Skip to content

Commit 6110981

Browse files
fix: minor type fixes
1 parent 5f6b769 commit 6110981

File tree

25 files changed

+388
-1513
lines changed

25 files changed

+388
-1513
lines changed

core/schemas/chatcompletions.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type ChatParameters struct {
1414
LogProbs *bool `json:"logprobs,omitempty"` // Number of logprobs to return
1515
MaxCompletionTokens *int `json:"max_completion_tokens,omitempty"` // Maximum number of tokens to generate
1616
Metadata *map[string]any `json:"metadata,omitempty"` // Metadata to be returned with the response
17-
Modalities []string `json:"modalities,omitempty"` // Modalities to be returned with the response
17+
Modalities []string `json:"modalities,omitempty"` // Modalities to be returned with the response
1818
ParallelToolCalls *bool `json:"parallel_tool_calls,omitempty"`
1919
PresencePenalty *float64 `json:"presence_penalty,omitempty"` // Penalizes repeated tokens
2020
PromptCacheKey *string `json:"prompt_cache_key,omitempty"` // Prompt cache key
@@ -24,7 +24,7 @@ type ChatParameters struct {
2424
Seed *int `json:"seed,omitempty"`
2525
ServiceTier *string `json:"service_tier,omitempty"`
2626
StreamOptions *ChatStreamOptions `json:"stream_options,omitempty"`
27-
Stop []string `json:"stop,omitempty"`
27+
Stop []string `json:"stop,omitempty"`
2828
Store *bool `json:"store,omitempty"`
2929
Temperature *float64 `json:"temperature,omitempty"`
3030
TopLogProbs *int `json:"top_logprobs,omitempty"`
@@ -71,7 +71,7 @@ type ToolFunctionParameters struct {
7171
Description *string `json:"description,omitempty"` // Description of the parameters
7272
Required []string `json:"required,omitempty"` // Required parameter names
7373
Properties map[string]interface{} `json:"properties,omitempty"` // Parameter properties
74-
Enum []string `json:"enum,omitempty"` // Enum values for the parameters
74+
Enum []string `json:"enum,omitempty"` // Enum values for the parameters
7575
}
7676

7777
type ChatToolCustom struct {
@@ -89,7 +89,7 @@ type ChatToolCustomGrammarFormat struct {
8989
Syntax string `json:"syntax"` // "lark" | "regex"
9090
}
9191

92-
// Combined tool choices for all providers, make sure to check the provider's
92+
// ChatToolChoiceType for all providers, make sure to check the provider's
9393
// documentation to see which tool choices are supported.
9494
type ChatToolChoiceType string
9595

@@ -178,7 +178,7 @@ type ChatToolChoiceAllowedToolsTool struct {
178178

179179
// MESSAGES
180180

181-
// ModelChatMessageRole represents the role of a chat message
181+
// ChatMessageRole represents the role of a chat message
182182
type ChatMessageRole string
183183

184184
const (
@@ -296,7 +296,7 @@ type ChatToolMessage struct {
296296
type ChatAssistantMessage struct {
297297
Refusal *string `json:"refusal,omitempty"`
298298
Annotations []ChatAssistantMessageAnnotation `json:"annotations,omitempty"`
299-
ToolCalls []ChatAssistantMessageToolCall `json:"tool_calls,omitempty"`
299+
ToolCalls []ChatAssistantMessageToolCall `json:"tool_calls,omitempty"`
300300
}
301301

302302
// ChatAssistantMessageAnnotation represents an annotation in a response.

core/schemas/providers/anthropic/chat.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -780,16 +780,12 @@ func ToAnthropicChatCompletionError(bifrostErr *schemas.BifrostError) *Anthropic
780780

781781
// Handle nested error fields with nil checks
782782
errorStruct := AnthropicMessageErrorStruct{
783-
Type: "",
783+
Type: errorType,
784784
Message: bifrostErr.Error.Message,
785785
}
786786

787-
if bifrostErr.Error.Type != nil {
788-
errorStruct.Type = *bifrostErr.Error.Type
789-
}
790-
791787
return &AnthropicMessageError{
792-
Type: errorType,
788+
Type: "error", // always "error" for Anthropic
793789
Error: errorStruct,
794790
}
795791
}

core/schemas/providers/anthropic/responses.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func ToAnthropicResponsesRequest(bifrostReq *schemas.BifrostResponsesRequest) *A
129129
if ok {
130130
anthropicReq.TopK = topK
131131
}
132-
if stop, ok := schemas.SafeExtractStringSlicePointer(bifrostReq.Params.ExtraParams["stop"]); ok {
132+
if stop, ok := schemas.SafeExtractStringSlice(bifrostReq.Params.ExtraParams["stop"]); ok {
133133
anthropicReq.StopSequences = stop
134134
}
135135
}
@@ -891,7 +891,7 @@ func convertBifrostMessagesToAnthropicContent(messages []schemas.ResponsesMessag
891891
})
892892
} else if msg.Content.ContentBlocks != nil {
893893
// Convert content blocks
894-
for _, block := range msg.Content.ContentBlocks {
894+
for _, block := range msg.Content.ContentBlocks {
895895
anthropicBlock := convertContentBlockToAnthropic(block)
896896
if anthropicBlock != nil {
897897
contentBlocks = append(contentBlocks, *anthropicBlock)

core/schemas/providers/bedrock/responses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func ToBedrockResponsesRequest(bifrostReq *schemas.BifrostResponsesRequest) (*Be
4444
inferenceConfig.TopP = bifrostReq.Params.TopP
4545
}
4646
if bifrostReq.Params.ExtraParams != nil {
47-
if stop, ok := schemas.SafeExtractStringSlicePointer(bifrostReq.Params.ExtraParams["stop"]); ok {
47+
if stop, ok := schemas.SafeExtractStringSlice(bifrostReq.Params.ExtraParams["stop"]); ok {
4848
inferenceConfig.StopSequences = stop
4949
}
5050
}

core/schemas/providers/cohere/responses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func ToCohereResponsesRequest(bifrostReq *schemas.BifrostResponsesRequest) *Cohe
3232
if topK, ok := schemas.SafeExtractIntPointer(bifrostReq.Params.ExtraParams["top_k"]); ok {
3333
cohereReq.K = topK
3434
}
35-
if stop, ok := schemas.SafeExtractStringSlicePointer(bifrostReq.Params.ExtraParams["stop"]); ok {
35+
if stop, ok := schemas.SafeExtractStringSlice(bifrostReq.Params.ExtraParams["stop"]); ok {
3636
cohereReq.StopSequences = stop
3737
}
3838
if frequencyPenalty, ok := schemas.SafeExtractFloat64Pointer(bifrostReq.Params.ExtraParams["frequency_penalty"]); ok {

core/schemas/utils.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -510,17 +510,6 @@ func SafeExtractBoolPointer(value interface{}) (*bool, bool) {
510510
return nil, false
511511
}
512512

513-
// SafeExtractStringSlicePointer safely extracts a []string value from an interface{} with type checking
514-
func SafeExtractStringSlicePointer(value interface{}) ([]string, bool) {
515-
if value == nil {
516-
return nil, false
517-
}
518-
if sliceVal, ok := SafeExtractStringSlice(value); ok {
519-
return sliceVal, true
520-
}
521-
return nil, false
522-
}
523-
524513
// SafeExtractFromMap safely extracts a value from a map[string]interface{} with type checking
525514
func SafeExtractFromMap(m map[string]interface{}, key string) (interface{}, bool) {
526515
if m == nil {

framework/streaming/accumulator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ func (a *Accumulator) cleanupOldAccumulators() {
309309
a.streamAccumulators.Range(func(key, value interface{}) bool {
310310
accumulator := value.(*StreamAccumulator)
311311
if accumulator.Timestamp.Before(time.Now().Add(-a.ttl)) {
312-
a.streamAccumulators.Delete(key)
312+
a.cleanupStreamAccumulator(key.(string))
313313
}
314314
count++
315315
return true

framework/streaming/audio.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ func (a *Accumulator) processAccumulatedAudioStreamingChunks(requestID string, b
3333
accumulator := a.getOrCreateStreamAccumulator(requestID)
3434
// Lock the accumulator
3535
accumulator.mu.Lock()
36-
defer accumulator.mu.Unlock()
37-
if isFinalChunk {
38-
// Before unlocking, we cleanup
39-
defer a.cleanupStreamAccumulator(requestID)
40-
}
36+
defer func() {
37+
accumulator.mu.Unlock()
38+
if isFinalChunk {
39+
// Before unlocking, we cleanup
40+
defer a.cleanupStreamAccumulator(requestID)
41+
}
42+
}()
4143
data := &AccumulatedData{
4244
RequestID: requestID,
4345
Status: "success",
@@ -78,7 +80,7 @@ func (a *Accumulator) processAccumulatedAudioStreamingChunks(requestID string, b
7880
PromptTokens: lastChunk.TokenUsage.InputTokens,
7981
CompletionTokens: lastChunk.TokenUsage.OutputTokens,
8082
TotalTokens: lastChunk.TokenUsage.TotalTokens,
81-
}
83+
}
8284
}
8385
}
8486
// Update cost from final chunk if available

framework/streaming/chat.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ func (a *Accumulator) buildCompleteMessageFromChatStreamChunks(chunks []*ChatStr
5050
func (a *Accumulator) processAccumulatedChatStreamingChunks(requestID string, respErr *schemas.BifrostError, isFinalChunk bool) (*AccumulatedData, error) {
5151
accumulator := a.getOrCreateStreamAccumulator(requestID)
5252
// Lock the accumulator
53-
accumulator.mu.Lock()
54-
defer accumulator.mu.Unlock()
55-
if isFinalChunk {
56-
// Before unlocking, we cleanup
57-
defer a.cleanupStreamAccumulator(requestID)
58-
}
53+
accumulator.mu.Lock()
54+
defer func() {
55+
accumulator.mu.Unlock()
56+
if isFinalChunk {
57+
// Before unlocking, we cleanup
58+
defer a.cleanupStreamAccumulator(requestID)
59+
}
60+
}()
5961
// Initialize accumulated data
6062
data := &AccumulatedData{
6163
RequestID: requestID,
@@ -111,11 +113,12 @@ func (a *Accumulator) processAccumulatedChatStreamingChunks(requestID string, re
111113
if lastChunk.Cost != nil {
112114
data.Cost = lastChunk.Cost
113115
}
116+
data.FinishReason = lastChunk.FinishReason
114117
}
115118
// Update object field from accumulator (stored once for the entire stream)
116119
if accumulator.Object != "" {
117120
data.Object = accumulator.Object
118-
}
121+
}
119122
return data, nil
120123
}
121124

framework/streaming/transcription.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ func (a *Accumulator) processAccumulatedTranscriptionStreamingChunks(requestID s
3131
accumulator := a.getOrCreateStreamAccumulator(requestID)
3232
// Lock the accumulator
3333
accumulator.mu.Lock()
34-
defer accumulator.mu.Unlock()
35-
if isFinalChunk {
36-
// Before unlocking, we cleanup
37-
defer a.cleanupStreamAccumulator(requestID)
38-
}
34+
defer func() {
35+
accumulator.mu.Unlock()
36+
if isFinalChunk {
37+
// Before unlocking, we cleanup
38+
defer a.cleanupStreamAccumulator(requestID)
39+
}
40+
}()
3941
data := &AccumulatedData{
4042
RequestID: requestID,
4143
Status: "success",

0 commit comments

Comments
 (0)