From e70bf2b6c044467ee8b80731ba4f017a89a595e4 Mon Sep 17 00:00:00 2001 From: imeepos Date: Tue, 22 Jul 2025 18:25:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96markdown=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/infrastructure/gemini_service.rs | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs b/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs index 47796ef..3931d20 100644 --- a/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs +++ b/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs @@ -1117,19 +1117,7 @@ impl GeminiService { conversation_context.total_messages = history_messages.len() as u32; conversation_context.history_included = true; - // 添加系统提示(如果有) - let system_prompt = if let Some(system_prompt) = &request.system_prompt { - system_prompt.clone() - } else if let Some(default_prompt) = &rag_config.system_prompt { - default_prompt.clone() - } else { - return Err(anyhow::anyhow!("系统提示词不能为空,请在请求中提供 system_prompt 或在配置中设置默认 system_prompt")); - }; - - contents.push(ContentPart { - role: "system".to_string(), - parts: vec![Part::Text { text: system_prompt }], - }); + // 系统提示将在请求数据中通过 systemInstruction 字段处理 // 添加历史消息 for msg in &history_messages { @@ -1296,6 +1284,13 @@ impl GeminiService { max_output_tokens: rag_config.max_output_tokens, }; + // 获取系统提示 + let system_prompt = if let Some(system_prompt) = &request.system_prompt { + Some(system_prompt.clone()) + } else { + rag_config.system_prompt.clone() + }; + // 准备请求数据 let request_data = serde_json::json!({ "contents": contents, @@ -1306,7 +1301,13 @@ impl GeminiService { "mode": "ANY", "allowedFunctionNames": ["retrieval"] } - } + }, + "systemInstruction": system_prompt.map(|prompt| { + serde_json::json!({ + "role": "system", + "parts": [{"text": prompt}] + }) + }) }); // 发送请求到Cloudflare Gateway (使用beta API)