1
This commit is contained in:
@@ -21,6 +21,7 @@ pub(crate) async fn stream_creation_agent_json_turn<F, E>(
|
||||
llm_client: Option<&LlmClient>,
|
||||
system_prompt: String,
|
||||
user_prompt: impl Into<String>,
|
||||
enable_web_search: bool,
|
||||
messages: CreationAgentLlmTurnErrorMessages<'_>,
|
||||
mut on_reply_update: F,
|
||||
build_error: impl Fn(String) -> E,
|
||||
@@ -33,10 +34,7 @@ where
|
||||
let mut latest_reply_text = String::new();
|
||||
let response = llm_client
|
||||
.stream_text(
|
||||
LlmTextRequest::new(vec![
|
||||
LlmMessage::system(system_prompt),
|
||||
LlmMessage::user(user_prompt.into()),
|
||||
]),
|
||||
build_creation_agent_llm_request(system_prompt, user_prompt.into(), enable_web_search),
|
||||
|delta: &LlmStreamDelta| {
|
||||
if let Some(reply_progress) =
|
||||
extract_reply_text_from_partial_json(delta.accumulated_text.as_str())
|
||||
@@ -61,6 +59,19 @@ where
|
||||
Ok(CreationAgentJsonTurnOutput { parsed })
|
||||
}
|
||||
|
||||
fn build_creation_agent_llm_request(
|
||||
system_prompt: String,
|
||||
user_prompt: String,
|
||||
enable_web_search: bool,
|
||||
) -> LlmTextRequest {
|
||||
// 创作 Agent 是否联网由 api-server 配置集中传入,避免各玩法各自散落默认值。
|
||||
LlmTextRequest::new(vec![
|
||||
LlmMessage::system(system_prompt),
|
||||
LlmMessage::user(user_prompt),
|
||||
])
|
||||
.with_web_search(enable_web_search)
|
||||
}
|
||||
|
||||
pub(crate) async fn request_creation_agent_json_turn<E>(
|
||||
llm_client: &LlmClient,
|
||||
system_prompt: String,
|
||||
@@ -149,7 +160,10 @@ fn read_reply_text(parsed: &JsonValue) -> Option<String> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{extract_reply_text_from_partial_json, parse_json_response_text};
|
||||
use super::{
|
||||
build_creation_agent_llm_request, extract_reply_text_from_partial_json,
|
||||
parse_json_response_text,
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn extracts_reply_text_from_partial_json_with_chinese_text() {
|
||||
@@ -167,4 +181,13 @@ mod tests {
|
||||
|
||||
assert_eq!(parsed["replyText"].as_str(), Some("好"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn builds_stream_request_with_web_search_when_enabled() {
|
||||
let request =
|
||||
build_creation_agent_llm_request("系统提示".to_string(), "用户提示".to_string(), true);
|
||||
|
||||
assert!(request.enable_web_search);
|
||||
assert_eq!(request.messages.len(), 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user