Skip to content

Commit 0a143cb

Browse files
committed
fix: integration test cases fixes
1 parent 97a94f4 commit 0a143cb

File tree

33 files changed

+181
-122
lines changed

33 files changed

+181
-122
lines changed

core/changelog.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
feat: send back raw request in extra fields
22
feat: added support for reasoning in chat completions
33
feat: enhanced reasoning support in responses api
4-
enhancement: improved internal inter provider conversions for integrations
4+
enhancement: improved internal inter provider conversions for integrations
5+
feat: switched to gemini native api
6+
feat: fallback to supported request type for custom models used in integration

core/providers/gemini/chat.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,6 @@ func (response *GenerateContentResponse) ToBifrostChatCompletionStream() (*schem
256256
},
257257
}
258258

259-
// Preserve thought signature if present (required for Gemini 3 Pro)
260-
if len(part.ThoughtSignature) > 0 {
261-
toolCall.ExtraContent = map[string]interface{}{
262-
"google": map[string]interface{}{
263-
"thought_signature": string(part.ThoughtSignature),
264-
},
265-
}
266-
}
267-
268259
toolCalls = append(toolCalls, toolCall)
269260

270261
case part.FunctionResponse != nil:

core/providers/gemini/responses.go

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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

core/providers/gemini/types.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import (
88
"reflect"
99
"strings"
1010
"time"
11+
12+
"github.com/bytedance/sonic"
1113
)
1214

1315
type Role string
@@ -68,6 +70,9 @@ type GeminiGenerationRequest struct {
6870
IsTranscription bool `json:"-"` // Internal field to track if this is a transcription request
6971
IsSpeech bool `json:"-"` // Internal field to track if this is a speech request
7072

73+
// Extra parameters for the request
74+
ExtraParams map[string]any `json:"extra_params,omitempty"`
75+
7176
// Bifrost specific field (only parsed when converting from Provider -> Bifrost request)
7277
Fallbacks []string `json:"fallbacks,omitempty"`
7378
}
@@ -912,6 +917,46 @@ type GenerationConfigThinkingConfig struct {
912917
ThinkingLevel ThinkingLevel `json:"thinkingLevel,omitempty"`
913918
}
914919

920+
// Gemini API supports Camel case but genai sdk sends thinking fields as snake_case
921+
// UnmarshalJSON implements custom JSON unmarshaling to support both camelCase and snake_case
922+
func (tc *GenerationConfigThinkingConfig) UnmarshalJSON(data []byte) error {
923+
// Define an auxiliary struct with both camelCase and snake_case tags
924+
type Alias struct {
925+
IncludeThoughts *bool `json:"includeThoughts"`
926+
IncludeThoughtsSnake *bool `json:"include_thoughts"`
927+
ThinkingBudget *int32 `json:"thinkingBudget"`
928+
ThinkingBudgetSnake *int32 `json:"thinking_budget"`
929+
ThinkingLevel *ThinkingLevel `json:"thinkingLevel"`
930+
ThinkingLevelSnake *ThinkingLevel `json:"thinking_level"`
931+
}
932+
933+
var aux Alias
934+
if err := sonic.Unmarshal(data, &aux); err != nil {
935+
return err
936+
}
937+
938+
// Prefer camelCase, fall back to snake_case
939+
if aux.IncludeThoughts != nil {
940+
tc.IncludeThoughts = *aux.IncludeThoughts
941+
} else if aux.IncludeThoughtsSnake != nil {
942+
tc.IncludeThoughts = *aux.IncludeThoughtsSnake
943+
}
944+
945+
if aux.ThinkingBudget != nil {
946+
tc.ThinkingBudget = aux.ThinkingBudget
947+
} else if aux.ThinkingBudgetSnake != nil {
948+
tc.ThinkingBudget = aux.ThinkingBudgetSnake
949+
}
950+
951+
if aux.ThinkingLevel != nil {
952+
tc.ThinkingLevel = *aux.ThinkingLevel
953+
} else if aux.ThinkingLevelSnake != nil {
954+
tc.ThinkingLevel = *aux.ThinkingLevelSnake
955+
}
956+
957+
return nil
958+
}
959+
915960
type ThinkingLevel string
916961

917962
const (

core/providers/gemini/utils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ func (r *GeminiGenerationRequest) convertGenerationConfigToResponsesParameters()
3232
}
3333
if config.ThinkingConfig != nil {
3434
params.Reasoning = &schemas.ResponsesParametersReasoning{}
35+
if strings.Contains(r.Model, "openai") {
36+
params.Reasoning.Summary = schemas.Ptr("auto")
37+
}
38+
if summaryValue, ok := schemas.SafeExtractStringPointer(r.ExtraParams["reasoning_summary"]); ok {
39+
params.Reasoning.Summary = summaryValue
40+
}
3541
if config.ThinkingConfig.ThinkingBudget != nil {
3642
params.Reasoning.MaxTokens = schemas.Ptr(int(*config.ThinkingConfig.ThinkingBudget))
3743
}
@@ -669,6 +675,11 @@ func convertBifrostMessagesToGemini(messages []schemas.ChatMessage) []Content {
669675
Parts: parts,
670676
Role: string(message.Role),
671677
}
678+
if message.Role == schemas.ChatMessageRoleUser {
679+
content.Role = "user"
680+
} else {
681+
content.Role = "model"
682+
}
672683
contents = append(contents, content)
673684
}
674685
}

core/providers/vertex/vertex.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,10 +1222,7 @@ func (provider *VertexProvider) ResponsesStream(ctx context.Context, postHookRun
12221222
jsonData,
12231223
headers,
12241224
provider.networkConfig.ExtraHeaders,
1225-
<<<<<<< HEAD
12261225
providerUtils.ShouldSendBackRawRequest(ctx, provider.sendBackRawRequest),
1227-
=======
1228-
>>>>>>> e38b5065 (feat: added support for gemini native converterswq)
12291226
providerUtils.ShouldSendBackRawResponse(ctx, provider.sendBackRawResponse),
12301227
provider.GetProviderKey(),
12311228
request.Model,

core/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.36
1+
1.2.37

framework/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.1.46
1+
1.1.47

plugins/governance/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- chore: updating core to 1.2.37 and framework to 1.1.47

plugins/governance/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.47
1+
1.3.48

0 commit comments

Comments
 (0)