@@ -727,21 +727,21 @@ func processGeminiPart(part *Part, state *GeminiResponsesStreamState, sequenceNu
727727 var responses []* schemas.BifrostResponsesStreamResponse
728728
729729 switch {
730+ case part .Thought && part .Text != "" :
731+ // Reasoning/thinking content
732+ responses = append (responses , processGeminiThoughtPart (part , state , sequenceNumber )... )
730733 case part .Text != "" && ! part .Thought :
731734 // Regular text content
732735 responses = append (responses , processGeminiTextPart (part , state , sequenceNumber )... )
733736
734- case part .Thought && part . Text != "" :
735- // Reasoning/thinking content
736- responses = append (responses , processGeminiThoughtPart (part , state , sequenceNumber )... )
737+ case part .FunctionCall != nil :
738+ // Function call
739+ responses = append (responses , processGeminiFunctionCallPart (part , state , sequenceNumber )... )
737740
738741 case part .ThoughtSignature != nil :
739742 // Encrypted reasoning content (thoughtSignature)
740743 responses = append (responses , processGeminiThoughtSignaturePart (part , state , sequenceNumber )... )
741744
742- case part .FunctionCall != nil :
743- // Function call
744- responses = append (responses , processGeminiFunctionCallPart (part , state , sequenceNumber )... )
745745 case part .FunctionResponse != nil :
746746 // Function response (tool result)
747747 responses = append (responses , processGeminiFunctionResponsePart (part , state , sequenceNumber )... )
@@ -1658,22 +1658,6 @@ func convertGeminiCandidatesToResponsesOutput(candidates []*Candidate) []schemas
16581658 for _ , part := range candidate .Content .Parts {
16591659 // Handle different types of parts
16601660 switch {
1661- case part .Text != "" :
1662- // Regular text message
1663- msg := schemas.ResponsesMessage {
1664- Role : schemas .Ptr (schemas .ResponsesInputMessageRoleAssistant ),
1665- Content : & schemas.ResponsesMessageContent {
1666- ContentBlocks : []schemas.ResponsesMessageContentBlock {
1667- {
1668- Type : schemas .ResponsesOutputMessageContentTypeText ,
1669- Text : & part .Text ,
1670- },
1671- },
1672- },
1673- Type : schemas .Ptr (schemas .ResponsesMessageTypeMessage ),
1674- }
1675- messages = append (messages , msg )
1676-
16771661 case part .Thought :
16781662 // Thinking/reasoning message
16791663 if part .Text != "" {
@@ -1692,6 +1676,22 @@ func convertGeminiCandidatesToResponsesOutput(candidates []*Candidate) []schemas
16921676 messages = append (messages , msg )
16931677 }
16941678
1679+ case part .Text != "" :
1680+ // Regular text message
1681+ msg := schemas.ResponsesMessage {
1682+ Role : schemas .Ptr (schemas .ResponsesInputMessageRoleAssistant ),
1683+ Content : & schemas.ResponsesMessageContent {
1684+ ContentBlocks : []schemas.ResponsesMessageContentBlock {
1685+ {
1686+ Type : schemas .ResponsesOutputMessageContentTypeText ,
1687+ Text : & part .Text ,
1688+ },
1689+ },
1690+ },
1691+ Type : schemas .Ptr (schemas .ResponsesMessageTypeMessage ),
1692+ }
1693+ messages = append (messages , msg )
1694+
16951695 case part .FunctionCall != nil :
16961696 // Function call message
16971697 // Convert Args to JSON string if it's not already a string
@@ -1723,7 +1723,7 @@ func convertGeminiCandidatesToResponsesOutput(candidates []*Candidate) []schemas
17231723 // Preserve thought signature if present (required for Gemini 3 Pro)
17241724 // Store it in a separate ResponsesReasoning message for better scalability
17251725 if len (part .ThoughtSignature ) > 0 {
1726- thoughtSig := string (part .ThoughtSignature )
1726+ thoughtSig := base64 . StdEncoding . EncodeToString (part .ThoughtSignature )
17271727 reasoningMsg := schemas.ResponsesMessage {
17281728 Role : schemas .Ptr (schemas .ResponsesInputMessageRoleAssistant ),
17291729 Type : schemas .Ptr (schemas .ResponsesMessageTypeReasoning ),
@@ -1899,7 +1899,8 @@ func (r *GeminiGenerationRequest) convertParamsToGenerationConfigResponses(param
18991899 config .ThinkingConfig = & GenerationConfigThinkingConfig {
19001900 IncludeThoughts : true ,
19011901 }
1902- if params .Reasoning .Effort != nil {
1902+ // only set thinking level if max tokens is not set
1903+ if params .Reasoning .Effort != nil && params .Reasoning .MaxTokens == nil {
19031904 switch * params .Reasoning .Effort {
19041905 case "minimal" , "low" :
19051906 config .ThinkingConfig .ThinkingLevel = ThinkingLevelLow
0 commit comments