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) # 使用模式: 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:

View File

@ -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;

View File

@ -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 {
// promptRAG // promptRAG
@ -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 APIAPI
const { data } = await axios.post(this.API_URL, { let response = '';
model: this.MODEL,
messages: [ if (this.API_URL.includes('11434')) {
{ role: 'user', content: enhancedPrompt } // Ollama
], const { data } = await axios.post(this.API_URL, {
temperature: 0.3, model: this.MODEL,
max_tokens: 8000, // token3000 messages: [
stream: false { role: 'user', content: enhancedPrompt }
}, { ],
headers: { stream: false,
'Authorization': `Bearer ${this.API_KEY}`, options: {
'Content-Type': 'application/json' temperature: 0.3,
}, num_predict: 8000
timeout: 180000 // 3 }
}) }, {
headers: {
// Kimi API (OpenAI ) Ollama 'Content-Type': 'application/json'
let response = data?.choices?.[0]?.message?.content ?? data?.message?.content ?? '' },
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. // 4.
if (ragSources && ragSources.length > 0) { if (ragSources && ragSources.length > 0) {

View File

@ -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,26 +476,53 @@ 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 APIAPI
const { data } = await axios.post(API_URL, { let rawResponse = '';
model: MODEL,
messages: [ if (API_URL.includes('11434')) {
{ role: 'system', content: SYSTEM_PROMPT }, // Ollama
{ role: 'user', content: userPrompt } const { data } = await axios.post(API_URL, {
], model: MODEL,
temperature: 0.2, messages: [
max_tokens: 1500, { role: 'system', content: SYSTEM_PROMPT },
stream: false { role: 'user', content: userPrompt }
}, { ],
headers: { stream: false,
'Authorization': `Bearer ${API_KEY}`, options: {
'Content-Type': 'application/json' temperature: 0.2,
}, num_predict: 2000
timeout: 60000 // 60 }
}); }, {
headers: {
// Kimi API (OpenAI ) Ollama 'Content-Type': 'application/json'
let rawResponse = data?.choices?.[0]?.message?.content ?? data?.message?.content ?? '无法解析模型输出'; },
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 rawResponse = rawResponse

View File

@ -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,27 +833,52 @@ 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 {
const { data } = await axios.post(API_URL, { let rawResponse = '';
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
});
console.log('AI响应数据:', data);
// Kimi API (OpenAI ) Ollama if (API_URL.includes('11434')) {
let rawResponse = data?.choices?.[0]?.message?.content ?? data?.message?.content ?? ''; // 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: 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 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