fix: 优化markdown解析器
This commit is contained in:
parent
26518569f4
commit
e70bf2b6c0
|
|
@ -1117,19 +1117,7 @@ impl GeminiService {
|
||||||
conversation_context.total_messages = history_messages.len() as u32;
|
conversation_context.total_messages = history_messages.len() as u32;
|
||||||
conversation_context.history_included = true;
|
conversation_context.history_included = true;
|
||||||
|
|
||||||
// 添加系统提示(如果有)
|
// 系统提示将在请求数据中通过 systemInstruction 字段处理
|
||||||
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 }],
|
|
||||||
});
|
|
||||||
|
|
||||||
// 添加历史消息
|
// 添加历史消息
|
||||||
for msg in &history_messages {
|
for msg in &history_messages {
|
||||||
|
|
@ -1296,6 +1284,13 @@ impl GeminiService {
|
||||||
max_output_tokens: rag_config.max_output_tokens,
|
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!({
|
let request_data = serde_json::json!({
|
||||||
"contents": contents,
|
"contents": contents,
|
||||||
|
|
@ -1306,7 +1301,13 @@ impl GeminiService {
|
||||||
"mode": "ANY",
|
"mode": "ANY",
|
||||||
"allowedFunctionNames": ["retrieval"]
|
"allowedFunctionNames": ["retrieval"]
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"systemInstruction": system_prompt.map(|prompt| {
|
||||||
|
serde_json::json!({
|
||||||
|
"role": "system",
|
||||||
|
"parts": [{"text": prompt}]
|
||||||
|
})
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
// 发送请求到Cloudflare Gateway (使用beta API)
|
// 发送请求到Cloudflare Gateway (使用beta API)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue