From cd7e9b351dcc68447121b82c960745480901e30b Mon Sep 17 00:00:00 2001 From: imeepos Date: Tue, 22 Jul 2025 18:15:52 +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 | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs b/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs index b6f41e3..196d631 100644 --- a/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs +++ b/apps/desktop/src-tauri/src/infrastructure/gemini_service.rs @@ -1108,17 +1108,18 @@ impl GeminiService { conversation_context.history_included = true; // 添加系统提示(如果有) - if let Some(system_prompt) = &request.system_prompt { - contents.push(ContentPart { - role: "system".to_string(), - parts: vec![Part::Text { text: system_prompt.clone() }], - }); + let system_prompt = if let Some(system_prompt) = &request.system_prompt { + system_prompt.clone() } else if let Some(default_prompt) = &rag_config.system_prompt { - contents.push(ContentPart { - role: "system".to_string(), - parts: vec![Part::Text { text: default_prompt.clone() }], - }); - } + 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 }], + }); // 添加历史消息 for msg in &history_messages {