2025-12-21
This commit is contained in:
parent
17dbd562f3
commit
ca07f08e67
|
|
@ -152,7 +152,7 @@ rag:
|
||||||
# 使用模式: disabled(禁用Java端)、python(仅Python)
|
# 使用模式: disabled(禁用Java端)、python(仅Python)
|
||||||
mode: disabled
|
mode: disabled
|
||||||
|
|
||||||
# OpenAI兼容API配置(仅用于AI报告生成,不用于RAG)
|
# OpenAI兼容API配置(本地开发时使用Kimi API)
|
||||||
openai:
|
openai:
|
||||||
base-url: https://api.moonshot.cn/v1
|
base-url: https://api.moonshot.cn/v1
|
||||||
api-key: sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m
|
api-key: sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m
|
||||||
|
|
@ -160,15 +160,16 @@ rag:
|
||||||
generate-model: moonshot-v1-32k
|
generate-model: moonshot-v1-32k
|
||||||
connect-timeout: 10
|
connect-timeout: 10
|
||||||
read-timeout: 60
|
read-timeout: 60
|
||||||
|
enabled: false
|
||||||
|
|
||||||
# Ollama配置(禁用)
|
# Ollama配置(服务器部署时使用本地Ollama)
|
||||||
ollama:
|
ollama:
|
||||||
url: http://localhost:11434
|
url: http://localhost:11434
|
||||||
embed-model: none
|
embed-model: nomic-embed-text
|
||||||
generate-model: none
|
generate-model: deepseek-r1:32b
|
||||||
connect-timeout: 5
|
connect-timeout: 30
|
||||||
read-timeout: 30
|
read-timeout: 300
|
||||||
enabled: false
|
enabled: true
|
||||||
|
|
||||||
# ChromaDB配置(禁用)
|
# ChromaDB配置(禁用)
|
||||||
chromadb:
|
chromadb:
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,10 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
private static final String TAG = "MainActivity";
|
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 WebView webView;
|
||||||
private TtsHelper ttsHelper;
|
private TtsHelper ttsHelper;
|
||||||
|
|
|
||||||
|
|
@ -152,15 +152,17 @@ export default {
|
||||||
reportDialogVisible: false,
|
reportDialogVisible: false,
|
||||||
comprehensiveReport: '',
|
comprehensiveReport: '',
|
||||||
ragSourcesForReport: [], // RAG知识库来源
|
ragSourcesForReport: [], // RAG知识库来源
|
||||||
// ========== Kimi API配置 ==========
|
// ========== Ollama本地大模型配置(服务器部署)==========
|
||||||
API_URL: 'https://api.moonshot.cn/v1/chat/completions',
|
API_URL: window.location.protocol === 'https:'
|
||||||
API_KEY: 'sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m',
|
? '/ollama/api/chat'
|
||||||
MODEL: 'moonshot-v1-32k'
|
: `http://${window.location.hostname}:11434/api/chat`,
|
||||||
|
API_KEY: '', // 本地模型不需要API Key
|
||||||
|
MODEL: 'deepseek-r1:32b'
|
||||||
|
|
||||||
// ========== 备用配置(Ollama本地大模型)==========
|
// ========== 备用配置(Kimi API - 本地开发)==========
|
||||||
// API_URL: 'http://192.168.0.106:11434/api/chat',
|
// API_URL: 'https://api.moonshot.cn/v1/chat/completions',
|
||||||
// API_KEY: '', // 本地模型不需要API Key
|
// API_KEY: 'sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m',
|
||||||
// MODEL: 'deepseek-r1:32b'
|
// MODEL: 'moonshot-v1-32k'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
|
@ -719,13 +721,15 @@ export default {
|
||||||
|
|
||||||
return `${SYSTEM_PROMPT}\n\n${userInfoText}\n\n【各量表/问卷详细报告及因子分析】\n${scaleReportsText}`
|
return `${SYSTEM_PROMPT}\n\n${userInfoText}\n\n【各量表/问卷详细报告及因子分析】\n${scaleReportsText}`
|
||||||
},
|
},
|
||||||
// Kimi API 调用方法
|
// Ollama 本地大模型调用方法
|
||||||
async callOLLAMA(prompt) {
|
async callOLLAMA(prompt) {
|
||||||
try {
|
try {
|
||||||
// 1. 先调用RAG服务获取知识库上下文
|
// 1. 先调用RAG服务获取知识库上下文
|
||||||
let knowledgeContext = '';
|
let knowledgeContext = '';
|
||||||
let ragSources = [];
|
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 {
|
try {
|
||||||
// 从prompt中提取关键信息用于RAG检索
|
// 从prompt中提取关键信息用于RAG检索
|
||||||
|
|
@ -766,28 +770,51 @@ export default {
|
||||||
enhancedPrompt = prompt + '\n\n【专业知识库参考资料】\n' + knowledgeContext + '\n\n请结合以上专业心理学资料进行分析,使报告更加专业和有深度。';
|
enhancedPrompt = prompt + '\n\n【专业知识库参考资料】\n' + knowledgeContext + '\n\n请结合以上专业心理学资料进行分析,使报告更加专业和有深度。';
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3. 调用AI API
|
// 3. 调用AI API(根据API类型选择不同的请求格式)
|
||||||
|
let response = '';
|
||||||
|
|
||||||
|
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分钟
|
||||||
|
});
|
||||||
|
|
||||||
|
response = data?.message?.content ?? '';
|
||||||
|
console.log('Ollama响应:', response);
|
||||||
|
} else {
|
||||||
|
// OpenAI兼容格式(Kimi等)
|
||||||
const { data } = await axios.post(this.API_URL, {
|
const { data } = await axios.post(this.API_URL, {
|
||||||
model: this.MODEL,
|
model: this.MODEL,
|
||||||
messages: [
|
messages: [
|
||||||
{ role: 'user', content: enhancedPrompt }
|
{ role: 'user', content: enhancedPrompt }
|
||||||
],
|
],
|
||||||
temperature: 0.3,
|
temperature: 0.3,
|
||||||
max_tokens: 8000, // 增加token数量以支持3000字以上的报告
|
max_tokens: 8000,
|
||||||
stream: false
|
stream: false
|
||||||
}, {
|
}, {
|
||||||
headers: {
|
headers: {
|
||||||
'Authorization': `Bearer ${this.API_KEY}`,
|
'Authorization': `Bearer ${this.API_KEY}`,
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
timeout: 180000 // 增加超时时间到3分钟
|
timeout: 180000
|
||||||
})
|
});
|
||||||
|
|
||||||
// 兼容 Kimi API (OpenAI 格式) 和 Ollama 格式
|
response = data?.choices?.[0]?.message?.content ?? '';
|
||||||
let response = data?.choices?.[0]?.message?.content ?? data?.message?.content ?? ''
|
console.log('OpenAI格式响应:', response);
|
||||||
|
}
|
||||||
console.log('原始响应:', response)
|
|
||||||
console.log('完整data:', data)
|
|
||||||
|
|
||||||
// 4. 如果有知识库来源,添加参考资料说明
|
// 4. 如果有知识库来源,添加参考资料说明
|
||||||
if (ragSources && ragSources.length > 0) {
|
if (ragSources && ragSources.length > 0) {
|
||||||
|
|
|
||||||
|
|
@ -415,13 +415,20 @@ export default {
|
||||||
this.aiError = '';
|
this.aiError = '';
|
||||||
this.aiResult = '';
|
this.aiResult = '';
|
||||||
|
|
||||||
// Kimi API配置
|
// ========== Kimi API配置(本地开发)==========
|
||||||
const API_URL = 'https://api.moonshot.cn/v1/chat/completions';
|
const API_URL = 'https://api.moonshot.cn/v1/chat/completions';
|
||||||
const API_KEY = 'sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m';
|
const API_KEY = 'sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m';
|
||||||
const MODEL = 'moonshot-v1-32k';
|
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知识库服务地址
|
// 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 || '';
|
const reportContent = this.reportForm.reportContent || '';
|
||||||
|
|
@ -469,7 +476,33 @@ export default {
|
||||||
|
|
||||||
const userPrompt = `重要:请直接输出结果,不要包含任何思考过程、<think>标签或<think>标签。\n\n报告标题:${reportTitle}\n报告类型:${reportType}\n报告内容:${textContent}`;
|
const userPrompt = `重要:请直接输出结果,不要包含任何思考过程、<think>标签或<think>标签。\n\n报告标题:${reportTitle}\n报告类型:${reportType}\n报告内容:${textContent}`;
|
||||||
|
|
||||||
// 3. 调用AI API
|
// 3. 调用AI API(根据API类型选择不同的请求格式)
|
||||||
|
let rawResponse = '';
|
||||||
|
|
||||||
|
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, {
|
const { data } = await axios.post(API_URL, {
|
||||||
model: MODEL,
|
model: MODEL,
|
||||||
messages: [
|
messages: [
|
||||||
|
|
@ -484,11 +517,12 @@ export default {
|
||||||
'Authorization': `Bearer ${API_KEY}`,
|
'Authorization': `Bearer ${API_KEY}`,
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
timeout: 60000 // 60秒超时
|
timeout: 60000
|
||||||
});
|
});
|
||||||
|
|
||||||
// 兼容 Kimi API (OpenAI 格式) 和 Ollama 格式
|
rawResponse = data?.choices?.[0]?.message?.content ?? '无法解析模型输出';
|
||||||
let rawResponse = data?.choices?.[0]?.message?.content ?? data?.message?.content ?? '无法解析模型输出';
|
console.log('OpenAI格式响应:', rawResponse);
|
||||||
|
}
|
||||||
|
|
||||||
// 过滤掉思考过程标签
|
// 过滤掉思考过程标签
|
||||||
rawResponse = rawResponse
|
rawResponse = rawResponse
|
||||||
|
|
|
||||||
|
|
@ -804,14 +804,17 @@ export default {
|
||||||
},
|
},
|
||||||
/** AI分析报告内容 */
|
/** AI分析报告内容 */
|
||||||
async generateAIAnalysis(reportContent, reportTitle, reportType) {
|
async generateAIAnalysis(reportContent, reportTitle, reportType) {
|
||||||
// Kimi API配置
|
// ========== Ollama本地大模型配置(服务器部署)==========
|
||||||
const API_URL = 'https://api.moonshot.cn/v1/chat/completions';
|
const API_URL = window.location.protocol === 'https:'
|
||||||
const API_KEY = 'sk-U9fdriPxwBcrpWW0Ite3N0eVtX7VxnqqqYUIBAdWd1hgEA9m';
|
? '/ollama/api/chat'
|
||||||
const MODEL = 'moonshot-v1-32k';
|
: `http://${window.location.hostname}:11434/api/chat`;
|
||||||
// 备用:Ollama本地大模型
|
const API_KEY = ''; // 本地模型不需要API Key
|
||||||
// const API_URL = 'http://192.168.0.106:11434/api/chat';
|
const MODEL = 'deepseek-r1:32b';
|
||||||
// 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 = [
|
const SYSTEM_PROMPT = [
|
||||||
|
|
@ -830,6 +833,32 @@ export default {
|
||||||
const userPrompt = `重要:请直接输出结果,不要包含任何思考过程、<think>标签或</think>标签。\n\n报告标题:${reportTitle}\n报告类型:${reportType}\n报告内容:${textContent}`;
|
const userPrompt = `重要:请直接输出结果,不要包含任何思考过程、<think>标签或</think>标签。\n\n报告标题:${reportTitle}\n报告类型:${reportType}\n报告内容:${textContent}`;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
let rawResponse = '';
|
||||||
|
|
||||||
|
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, {
|
const { data } = await axios.post(API_URL, {
|
||||||
model: MODEL,
|
model: MODEL,
|
||||||
messages: [
|
messages: [
|
||||||
|
|
@ -844,13 +873,12 @@ export default {
|
||||||
'Authorization': `Bearer ${API_KEY}`,
|
'Authorization': `Bearer ${API_KEY}`,
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
timeout: 60000 // 60秒超时
|
timeout: 60000
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('AI响应数据:', data);
|
rawResponse = data?.choices?.[0]?.message?.content ?? '';
|
||||||
|
console.log('OpenAI格式响应:', rawResponse);
|
||||||
// 兼容 Kimi API (OpenAI 格式) 和 Ollama 格式
|
}
|
||||||
let rawResponse = data?.choices?.[0]?.message?.content ?? data?.message?.content ?? '';
|
|
||||||
|
|
||||||
// 过滤掉思考过程标签
|
// 过滤掉思考过程标签
|
||||||
rawResponse = rawResponse
|
rawResponse = rawResponse
|
||||||
|
|
@ -1174,9 +1202,9 @@ export default {
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// 清理文件名中的非法字符
|
// 清理文件名中的非法字符
|
||||||
const safeFileName = (report.reportTitle || '报告_' + report.reportId)
|
const safeFileName = `${report.reportTitle || '报告'}_${report.reportId}`
|
||||||
.replace(/[\\/:*?"<>|]/g, '_')
|
.replace(/[\\/:*?"<>|]/g, '_')
|
||||||
.substring(0, 50);
|
.substring(0, 80);
|
||||||
|
|
||||||
if (this.batchExportForm.format === 'docx') {
|
if (this.batchExportForm.format === 'docx') {
|
||||||
// Word格式 - 使用完整的Word HTML格式
|
// Word格式 - 使用完整的Word HTML格式
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user