mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-11 12:18:59 +00:00
fix(providers): prevent Gemini thought_signature from leaking to other providers and breaking validation (#230)
* fix: prevent gemini thought_signature from leaking to other providers * test: refine gemini model detection for robust provider multiplexing
This commit is contained in:
1 parent
037d18f711
commit
5c0612a07f
1 file changed
+13
-2
@@ -227,7 +227,14 @@ func (p *OpenAIProvider) buildRequestBody(model string, req ChatRequest, stream
|
||||
// don't return it (e.g. gemini-3-flash) will cause HTTP 400 if sent as-is.
|
||||
// Tool results are folded into plain user messages to preserve context.
|
||||
inputMessages := req.Messages
|
||||
if strings.Contains(strings.ToLower(p.name), "gemini") {
|
||||
|
||||
// Compute provider capability once: does this endpoint support Google's thought_signature?
|
||||
// We check name, apiBase, and the model string (which covers OpenRouter/LiteLLM routing to Gemini).
|
||||
supportsThoughtSignature := strings.Contains(strings.ToLower(p.name), "gemini") ||
|
||||
strings.Contains(strings.ToLower(p.apiBase), "generativelanguage") ||
|
||||
strings.Contains(strings.ToLower(model), "gemini")
|
||||
|
||||
if supportsThoughtSignature {
|
||||
inputMessages = collapseToolCallsWithoutSig(inputMessages)
|
||||
}
|
||||
|
||||
@@ -280,7 +287,11 @@ func (p *OpenAIProvider) buildRequestBody(model string, req ChatRequest, stream
|
||||
"arguments": string(argsJSON),
|
||||
}
|
||||
if sig := tc.Metadata["thought_signature"]; sig != "" {
|
||||
fn["thought_signature"] = sig
|
||||
// Only send thought_signature to providers that support it (Google/Gemini).
|
||||
// Non-Google providers will reject the unknown field with 422 Unprocessable Entity.
|
||||
if supportsThoughtSignature {
|
||||
fn["thought_signature"] = sig
|
||||
}
|
||||
}
|
||||
toolCalls[i] = map[string]any{
|
||||
"id": tc.ID,
|
||||
|
||||
Reference in new issue
Block a user