2025-12-21

This commit is contained in:
xiao12feng8 2025-12-21 18:57:14 +08:00
parent 17dbd562f3
commit ca07f08e67
5 changed files with 185 additions and 92 deletions

View File

@ -152,7 +152,7 @@ rag:
# 使用模式: disabled(禁用Java端)、python(仅Python)
mode: disabled
# OpenAI兼容API配置仅用于AI报告生成不用于RAG
# OpenAI兼容API配置本地开发时使用Kimi API
openai:
base-url: https://api.moonshot.cn/v1
api-key: sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m
@ -160,15 +160,16 @@ rag:
generate-model: moonshot-v1-32k
connect-timeout: 10
read-timeout: 60
enabled: false
# Ollama配置禁用
# Ollama配置服务器部署时使用本地Ollama
ollama:
url: http://localhost:11434
embed-model: none
generate-model: none
connect-timeout: 5
read-timeout: 30
enabled: false
embed-model: nomic-embed-text
generate-model: deepseek-r1:32b
connect-timeout: 30
read-timeout: 300
enabled: true
# ChromaDB配置禁用
chromadb:

View File

@ -13,7 +13,10 @@ import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private static final String FIXED_URL = "http://192.168.1.164:80?app=1";
// 内网部署地址192.168.0.106
private static final String FIXED_URL = "http://192.168.0.106:80?app=1";
// 备用地址192.168.1.164
// private static final String FIXED_URL = "http://192.168.1.164:80?app=1";
private WebView webView;
private TtsHelper ttsHelper;

View File

@ -152,15 +152,17 @@ export default {
reportDialogVisible: false,
comprehensiveReport: '',
ragSourcesForReport: [], // RAG
// ========== Kimi API ==========
API_URL: 'https://api.moonshot.cn/v1/chat/completions',
API_KEY: 'sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m',
MODEL: 'moonshot-v1-32k'
// ========== Ollama==========
API_URL: window.location.protocol === 'https:'
? '/ollama/api/chat'
: `http://${window.location.hostname}:11434/api/chat`,
API_KEY: '', // API Key
MODEL: 'deepseek-r1:32b'
// ========== Ollama==========
// API_URL: 'http://192.168.0.106:11434/api/chat',
// API_KEY: '', // API Key
// MODEL: 'deepseek-r1:32b'
// ========== Kimi API - ==========
// API_URL: 'https://api.moonshot.cn/v1/chat/completions',
// API_KEY: 'sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m',
// MODEL: 'moonshot-v1-32k'
}
},
created() {
@ -719,13 +721,15 @@ export default {
return `${SYSTEM_PROMPT}\n\n${userInfoText}\n\n【各量表/问卷详细报告及因子分析】\n${scaleReportsText}`
},
// Kimi API
// Ollama
async callOLLAMA(prompt) {
try {
// 1. RAG
let knowledgeContext = '';
let ragSources = [];
const RAG_API_URL = 'http://localhost:5000/api/rag-analyze';
const RAG_API_URL = window.location.protocol === 'https:'
? '/rag-api/api/rag-analyze'
: `http://${window.location.hostname}:5000/api/rag-analyze`;
try {
// promptRAG
@ -766,28 +770,51 @@ export default {
enhancedPrompt = prompt + '\n\n【专业知识库参考资料】\n' + knowledgeContext + '\n\n请结合以上专业心理学资料进行分析使报告更加专业和有深度。';
}
// 3. AI API
const { data } = await axios.post(this.API_URL, {
model: this.MODEL,
messages: [
{ role: 'user', content: enhancedPrompt }
],
temperature: 0.3,
max_tokens: 8000, // token3000
stream: false
}, {
headers: {
'Authorization': `Bearer ${this.API_KEY}`,
'Content-Type': 'application/json'
},
timeout: 180000 // 3
})
// 3. AI APIAPI
let response = '';
// Kimi API (OpenAI ) Ollama
let response = data?.choices?.[0]?.message?.content ?? data?.message?.content ?? ''
if (this.API_URL.includes('11434')) {
// Ollama
const { data } = await axios.post(this.API_URL, {
model: this.MODEL,
messages: [
{ role: 'user', content: enhancedPrompt }
],
stream: false,
options: {
temperature: 0.3,
num_predict: 8000
}
}, {
headers: {
'Content-Type': 'application/json'
},
timeout: 600000 // Ollama10
});
console.log('原始响应:', response)
console.log('完整data:', data)
response = data?.message?.content ?? '';
console.log('Ollama响应:', response);
} else {
// OpenAIKimi
const { data } = await axios.post(this.API_URL, {
model: this.MODEL,
messages: [
{ role: 'user', content: enhancedPrompt }
],
temperature: 0.3,
max_tokens: 8000,
stream: false
}, {
headers: {
'Authorization': `Bearer ${this.API_KEY}`,
'Content-Type': 'application/json'
},
timeout: 180000
});
response = data?.choices?.[0]?.message?.content ?? '';
console.log('OpenAI格式响应:', response);
}
// 4.
if (ragSources && ragSources.length > 0) {

View File

@ -415,13 +415,20 @@ export default {
this.aiError = '';
this.aiResult = '';
// Kimi API
// ========== Kimi API==========
const API_URL = 'https://api.moonshot.cn/v1/chat/completions';
const API_KEY = 'sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m';
const MODEL = 'moonshot-v1-32k';
// ========== Ollama - ==========
// const API_URL = 'http://localhost:11434/api/chat';
// const API_KEY = ''; // API Key
// const MODEL = 'deepseek-r1:32b';
// RAG
const RAG_API_URL = 'http://localhost:5000/api/rag-analyze';
const RAG_API_URL = window.location.protocol === 'https:'
? '/rag-api/api/rag-analyze'
: `http://${window.location.hostname}:5000/api/rag-analyze`;
//
const reportContent = this.reportForm.reportContent || '';
@ -469,26 +476,53 @@ export default {
const userPrompt = `重要:请直接输出结果,不要包含任何思考过程、<think>标签或<think>标签。\n\n报告标题${reportTitle}\n报告类型${reportType}\n报告内容${textContent}`;
// 3. AI API
const { data } = await axios.post(API_URL, {
model: MODEL,
messages: [
{ role: 'system', content: SYSTEM_PROMPT },
{ role: 'user', content: userPrompt }
],
temperature: 0.2,
max_tokens: 1500,
stream: false
}, {
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
timeout: 60000 // 60
});
// 3. AI APIAPI
let rawResponse = '';
// Kimi API (OpenAI ) Ollama
let rawResponse = data?.choices?.[0]?.message?.content ?? data?.message?.content ?? '无法解析模型输出';
if (API_URL.includes('11434')) {
// Ollama
const { data } = await axios.post(API_URL, {
model: MODEL,
messages: [
{ role: 'system', content: SYSTEM_PROMPT },
{ role: 'user', content: userPrompt }
],
stream: false,
options: {
temperature: 0.2,
num_predict: 2000
}
}, {
headers: {
'Content-Type': 'application/json'
},
timeout: 300000 // Ollama5
});
rawResponse = data?.message?.content ?? '无法解析模型输出';
console.log('Ollama响应:', rawResponse);
} else {
// OpenAIKimi
const { data } = await axios.post(API_URL, {
model: MODEL,
messages: [
{ role: 'system', content: SYSTEM_PROMPT },
{ role: 'user', content: userPrompt }
],
temperature: 0.2,
max_tokens: 1500,
stream: false
}, {
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
timeout: 60000
});
rawResponse = data?.choices?.[0]?.message?.content ?? '无法解析模型输出';
console.log('OpenAI格式响应:', rawResponse);
}
//
rawResponse = rawResponse

View File

@ -804,14 +804,17 @@ export default {
},
/** AI分析报告内容 */
async generateAIAnalysis(reportContent, reportTitle, reportType) {
// Kimi API
const API_URL = 'https://api.moonshot.cn/v1/chat/completions';
const API_KEY = 'sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m';
const MODEL = 'moonshot-v1-32k';
// Ollama
// const API_URL = 'http://192.168.0.106:11434/api/chat';
// const API_KEY = ''; // API Key
// const MODEL = 'deepseek-r1:32b';
// ========== Ollama==========
const API_URL = window.location.protocol === 'https:'
? '/ollama/api/chat'
: `http://${window.location.hostname}:11434/api/chat`;
const API_KEY = ''; // API Key
const MODEL = 'deepseek-r1:32b';
// ========== Kimi API - ==========
// const API_URL = 'https://api.moonshot.cn/v1/chat/completions';
// const API_KEY = 'sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m';
// const MODEL = 'moonshot-v1-32k';
//
const SYSTEM_PROMPT = [
@ -830,27 +833,52 @@ export default {
const userPrompt = `重要:请直接输出结果,不要包含任何思考过程、<think>标签或</think>标签。\n\n报告标题${reportTitle}\n报告类型${reportType}\n报告内容${textContent}`;
try {
const { data } = await axios.post(API_URL, {
model: MODEL,
messages: [
{ role: 'system', content: SYSTEM_PROMPT },
{ role: 'user', content: userPrompt }
],
temperature: 0.2,
max_tokens: 1000,
stream: false
}, {
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
timeout: 60000 // 60
});
let rawResponse = '';
console.log('AI响应数据:', data);
if (API_URL.includes('11434')) {
// Ollama
const { data } = await axios.post(API_URL, {
model: MODEL,
messages: [
{ role: 'system', content: SYSTEM_PROMPT },
{ role: 'user', content: userPrompt }
],
stream: false,
options: {
temperature: 0.2,
num_predict: 2000
}
}, {
headers: {
'Content-Type': 'application/json'
},
timeout: 300000 // Ollama5
});
// Kimi API (OpenAI ) Ollama
let rawResponse = data?.choices?.[0]?.message?.content ?? data?.message?.content ?? '';
rawResponse = data?.message?.content ?? '';
console.log('Ollama响应:', rawResponse);
} else {
// OpenAIKimi
const { data } = await axios.post(API_URL, {
model: MODEL,
messages: [
{ role: 'system', content: SYSTEM_PROMPT },
{ role: 'user', content: userPrompt }
],
temperature: 0.2,
max_tokens: 1000,
stream: false
}, {
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
timeout: 60000
});
rawResponse = data?.choices?.[0]?.message?.content ?? '';
console.log('OpenAI格式响应:', rawResponse);
}
//
rawResponse = rawResponse
@ -1174,9 +1202,9 @@ export default {
`;
//
const safeFileName = (report.reportTitle || '报告_' + report.reportId)
const safeFileName = `${report.reportTitle || '报告'}_${report.reportId}`
.replace(/[\\/:*?"<>|]/g, '_')
.substring(0, 50);
.substring(0, 80);
if (this.batchExportForm.format === 'docx') {
// Word - 使Word HTML