2025-12-21
This commit is contained in:
parent
17dbd562f3
commit
ca07f08e67
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
// 从prompt中提取关键信息用于RAG检索
|
||||
|
|
@ -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, // 增加token数量以支持3000字以上的报告
|
||||
stream: false
|
||||
}, {
|
||||
headers: {
|
||||
'Authorization': `Bearer ${this.API_KEY}`,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
timeout: 180000 // 增加超时时间到3分钟
|
||||
})
|
||||
// 3. 调用AI API(根据API类型选择不同的请求格式)
|
||||
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 // Ollama本地模型需要更长时间,设置10分钟
|
||||
});
|
||||
|
||||
console.log('原始响应:', response)
|
||||
console.log('完整data:', data)
|
||||
response = data?.message?.content ?? '';
|
||||
console.log('Ollama响应:', response);
|
||||
} else {
|
||||
// OpenAI兼容格式(Kimi等)
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -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 API(根据API类型选择不同的请求格式)
|
||||
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 // Ollama本地模型需要更长时间,设置5分钟
|
||||
});
|
||||
|
||||
rawResponse = data?.message?.content ?? '无法解析模型输出';
|
||||
console.log('Ollama响应:', rawResponse);
|
||||
} else {
|
||||
// OpenAI兼容格式(Kimi等)
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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 // Ollama本地模型需要更长时间,设置5分钟
|
||||
});
|
||||
|
||||
// 兼容 Kimi API (OpenAI 格式) 和 Ollama 格式
|
||||
let rawResponse = data?.choices?.[0]?.message?.content ?? data?.message?.content ?? '';
|
||||
rawResponse = data?.message?.content ?? '';
|
||||
console.log('Ollama响应:', rawResponse);
|
||||
} else {
|
||||
// OpenAI兼容格式(Kimi等)
|
||||
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格式
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user