feat: Added support for thought-signatures for Gemini 3+ models
This commit is contained in:
+22
-4
@@ -219,7 +219,14 @@ pub async fn gemini_chat_completions_streaming(
|
|||||||
part["functionCall"]["name"].as_str(),
|
part["functionCall"]["name"].as_str(),
|
||||||
part["functionCall"]["args"].as_object(),
|
part["functionCall"]["args"].as_object(),
|
||||||
) {
|
) {
|
||||||
handler.tool_call(ToolCall::new(name.to_string(), json!(args), None))?;
|
let thought_signature = part["thoughtSignature"]
|
||||||
|
.as_str()
|
||||||
|
.or_else(|| part["thought_signature"].as_str())
|
||||||
|
.map(|s| s.to_string());
|
||||||
|
handler.tool_call(
|
||||||
|
ToolCall::new(name.to_string(), json!(args), None)
|
||||||
|
.with_thought_signature(thought_signature),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Some("SAFETY") = data["promptFeedback"]["blockReason"]
|
} else if let Some("SAFETY") = data["promptFeedback"]["blockReason"]
|
||||||
@@ -280,7 +287,14 @@ fn gemini_extract_chat_completions_text(data: &Value) -> Result<ChatCompletionsO
|
|||||||
part["functionCall"]["name"].as_str(),
|
part["functionCall"]["name"].as_str(),
|
||||||
part["functionCall"]["args"].as_object(),
|
part["functionCall"]["args"].as_object(),
|
||||||
) {
|
) {
|
||||||
tool_calls.push(ToolCall::new(name.to_string(), json!(args), None));
|
let thought_signature = part["thoughtSignature"]
|
||||||
|
.as_str()
|
||||||
|
.or_else(|| part["thought_signature"].as_str())
|
||||||
|
.map(|s| s.to_string());
|
||||||
|
tool_calls.push(
|
||||||
|
ToolCall::new(name.to_string(), json!(args), None)
|
||||||
|
.with_thought_signature(thought_signature),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -347,12 +361,16 @@ pub fn gemini_build_chat_completions_body(
|
|||||||
},
|
},
|
||||||
MessageContent::ToolCalls(MessageContentToolCalls { tool_results, .. }) => {
|
MessageContent::ToolCalls(MessageContentToolCalls { tool_results, .. }) => {
|
||||||
let model_parts: Vec<Value> = tool_results.iter().map(|tool_result| {
|
let model_parts: Vec<Value> = tool_results.iter().map(|tool_result| {
|
||||||
json!({
|
let mut part = json!({
|
||||||
"functionCall": {
|
"functionCall": {
|
||||||
"name": tool_result.call.name,
|
"name": tool_result.call.name,
|
||||||
"args": tool_result.call.arguments,
|
"args": tool_result.call.arguments,
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
|
if let Some(sig) = &tool_result.call.thought_signature {
|
||||||
|
part["thoughtSignature"] = json!(sig);
|
||||||
|
}
|
||||||
|
part
|
||||||
}).collect();
|
}).collect();
|
||||||
let function_parts: Vec<Value> = tool_results.into_iter().map(|tool_result| {
|
let function_parts: Vec<Value> = tool_results.into_iter().map(|tool_result| {
|
||||||
json!({
|
json!({
|
||||||
|
|||||||
@@ -756,6 +756,10 @@ pub struct ToolCall {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub arguments: Value,
|
pub arguments: Value,
|
||||||
pub id: Option<String>,
|
pub id: Option<String>,
|
||||||
|
/// Gemini 3's thought signature for stateful reasoning in function calling.
|
||||||
|
/// Must be preserved and sent back when submitting function responses.
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
pub thought_signature: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
type CallConfig = (String, String, Vec<String>, HashMap<String, String>);
|
type CallConfig = (String, String, Vec<String>, HashMap<String, String>);
|
||||||
@@ -785,9 +789,15 @@ impl ToolCall {
|
|||||||
name,
|
name,
|
||||||
arguments,
|
arguments,
|
||||||
id,
|
id,
|
||||||
|
thought_signature: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn with_thought_signature(mut self, thought_signature: Option<String>) -> Self {
|
||||||
|
self.thought_signature = thought_signature;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn eval(&self, config: &GlobalConfig) -> Result<Value> {
|
pub async fn eval(&self, config: &GlobalConfig) -> Result<Value> {
|
||||||
let (call_name, cmd_name, mut cmd_args, envs) = match &config.read().agent {
|
let (call_name, cmd_name, mut cmd_args, envs) = match &config.read().agent {
|
||||||
Some(agent) => self.extract_call_config_from_agent(config, agent)?,
|
Some(agent) => self.extract_call_config_from_agent(config, agent)?,
|
||||||
|
|||||||
Reference in New Issue
Block a user