From 25aed0836123fa1f4c80ef027877eabc9706471c Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 24 Nov 2025 00:31:20 +0000 Subject: [PATCH] feat: enable thoughtSignature for non-function-call messages Previously thoughtSignature was only attached to messages with function calls. This change extends the feature to also attach thoughtSignature to the first text part of assistant/model messages when no tool_calls are present, ensuring compatibility with Gemini thinking models in regular conversation scenarios. --- relay/channel/gemini/relay-gemini.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/relay/channel/gemini/relay-gemini.go b/relay/channel/gemini/relay-gemini.go index eae7a745..ab9e8e33 100644 --- a/relay/channel/gemini/relay-gemini.go +++ b/relay/channel/gemini/relay-gemini.go @@ -484,6 +484,17 @@ func CovertOpenAI2Gemini(c *gin.Context, textRequest dto.GeneralOpenAIRequest, i } } + // 如果需要附加签名但还没有附加(没有 tool_calls 或 tool_calls 为空), + // 则在第一个文本 part 上附加 thoughtSignature + if shouldAttachThoughtSignature && !signatureAttached && len(parts) > 0 { + for i := range parts { + if parts[i].Text != "" { + parts[i].ThoughtSignature = json.RawMessage(strconv.Quote(thoughtSignatureBypassValue)) + break + } + } + } + content.Parts = parts // there's no assistant role in gemini and API shall vomit if Role is not user or model