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 {