only emit final response once
This commit is contained in:
@@ -1027,7 +1027,9 @@ The tool will execute immediately and you'll receive the result (success or erro
|
|||||||
io::stdout().flush()?;
|
io::stdout().flush()?;
|
||||||
|
|
||||||
// Add the tool call and result to the context window
|
// Add the tool call and result to the context window
|
||||||
let tool_message = Message {
|
// Only include the text content if it's not already in full_response
|
||||||
|
let tool_message = if !full_response.contains(final_display_content) {
|
||||||
|
Message {
|
||||||
role: MessageRole::Assistant,
|
role: MessageRole::Assistant,
|
||||||
content: format!(
|
content: format!(
|
||||||
"{}\n\n{{\"tool\": \"{}\", \"args\": {}}}",
|
"{}\n\n{{\"tool\": \"{}\", \"args\": {}}}",
|
||||||
@@ -1035,6 +1037,17 @@ The tool will execute immediately and you'll receive the result (success or erro
|
|||||||
tool_call.tool,
|
tool_call.tool,
|
||||||
tool_call.args
|
tool_call.args
|
||||||
),
|
),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// If we've already added the text, just include the tool call
|
||||||
|
Message {
|
||||||
|
role: MessageRole::Assistant,
|
||||||
|
content: format!(
|
||||||
|
"{{\"tool\": \"{}\", \"args\": {}}}",
|
||||||
|
tool_call.tool,
|
||||||
|
tool_call.args
|
||||||
|
),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let result_message = Message {
|
let result_message = Message {
|
||||||
role: MessageRole::User,
|
role: MessageRole::User,
|
||||||
@@ -1052,7 +1065,10 @@ The tool will execute immediately and you'll receive the result (success or erro
|
|||||||
request.tools = Some(Self::create_tool_definitions());
|
request.tools = Some(Self::create_tool_definitions());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only add to full_response if we haven't already added it
|
||||||
|
if !full_response.contains(final_display_content) {
|
||||||
full_response.push_str(final_display_content);
|
full_response.push_str(final_display_content);
|
||||||
|
}
|
||||||
tool_executed = true;
|
tool_executed = true;
|
||||||
|
|
||||||
// Reset parser for next iteration
|
// Reset parser for next iteration
|
||||||
|
|||||||
Reference in New Issue
Block a user