@@ -75,23 +75,27 @@ func hexToBytes(hexStr string, length int) []byte {
7575func getSpeechRequestParams (req * schemas.BifrostSpeechRequest ) []* KeyValue {
7676 params := []* KeyValue {}
7777 if req .Params != nil {
78- if req .Params .VoiceConfig .Voice != nil {
79- params = append (params , kvStr ("gen_ai.request.voice" , * req .Params .VoiceConfig .Voice ))
80- }
81- if len (req .Params .VoiceConfig .MultiVoiceConfig ) > 0 {
82- multiVoiceConfigParams := []* KeyValue {}
83- for _ , voiceConfig := range req .Params .VoiceConfig .MultiVoiceConfig {
84- multiVoiceConfigParams = append (multiVoiceConfigParams , kvStr ("gen_ai.request.voice" , voiceConfig .Voice ))
78+ if req .Params .VoiceConfig != nil {
79+ if req .Params .VoiceConfig .Voice != nil {
80+ params = append (params , kvStr ("gen_ai.request.voice" , * req .Params .VoiceConfig .Voice ))
81+ }
82+ if len (req .Params .VoiceConfig .MultiVoiceConfig ) > 0 {
83+ multiVoiceConfigParams := []* KeyValue {}
84+ for _ , voiceConfig := range req .Params .VoiceConfig .MultiVoiceConfig {
85+ multiVoiceConfigParams = append (multiVoiceConfigParams , kvStr ("gen_ai.request.voice" , voiceConfig .Voice ))
86+ }
87+ params = append (params , kvAny ("gen_ai.request.multi_voice_config" , arrValue (listValue (multiVoiceConfigParams ... ))))
8588 }
86- params = append (params , kvAny ("gen_ai.request.multi_voice_config" , arrValue (listValue (multiVoiceConfigParams ... ))))
8789 }
8890 params = append (params , kvStr ("gen_ai.request.instructions" , req .Params .Instructions ))
8991 params = append (params , kvStr ("gen_ai.request.response_format" , req .Params .ResponseFormat ))
9092 if req .Params .Speed != nil {
9193 params = append (params , kvDbl ("gen_ai.request.speed" , * req .Params .Speed ))
9294 }
9395 }
94- params = append (params , kvStr ("gen_ai.input.speech" , req .Input .Input ))
96+ if req .Input != nil {
97+ params = append (params , kvStr ("gen_ai.input.speech" , req .Input .Input ))
98+ }
9599 return params
96100}
97101
@@ -226,6 +230,9 @@ func getChatRequestParams(req *schemas.BifrostChatRequest) []*KeyValue {
226230 if req .Input != nil {
227231 messages := []* AnyValue {}
228232 for _ , message := range req .Input {
233+ if message .Content == nil {
234+ continue
235+ }
229236 switch message .Role {
230237 case schemas .ChatMessageRoleUser :
231238 kvs := []* KeyValue {kvStr ("role" , "user" )}
@@ -504,18 +511,20 @@ func completeResourceSpan(span *ResourceSpan, timestamp time.Time, resp *schemas
504511 continue
505512 }
506513 kvs := []* KeyValue {kvStr ("role" , string (* message .Role ))}
507- if message .Content .ContentStr != nil && * message .Content .ContentStr != "" {
508- kvs = append (kvs , kvStr ("content" , * message .Content .ContentStr ))
509- } else if message .Content .ContentBlocks != nil {
510- blockText := ""
511- for _ , block := range message .Content .ContentBlocks {
512- if block .Text != nil {
513- blockText += * block .Text
514+ if message .Content != nil {
515+ if message .Content .ContentStr != nil && * message .Content .ContentStr != "" {
516+ kvs = append (kvs , kvStr ("content" , * message .Content .ContentStr ))
517+ } else if message .Content .ContentBlocks != nil {
518+ blockText := ""
519+ for _ , block := range message .Content .ContentBlocks {
520+ if block .Text != nil {
521+ blockText += * block .Text
522+ }
514523 }
524+ kvs = append (kvs , kvStr ("content" , blockText ))
515525 }
516- kvs = append (kvs , kvStr ("content" , blockText ))
517526 }
518- if message .ResponsesReasoning != nil {
527+ if message .ResponsesReasoning != nil && message . ResponsesReasoning . Summary != nil {
519528 reasoningText := ""
520529 for _ , block := range message .ResponsesReasoning .Summary {
521530 if block .Text != "" {
@@ -620,18 +629,20 @@ func completeResourceSpan(span *ResourceSpan, timestamp time.Time, resp *schemas
620629 kvs := []* KeyValue {kvStr ("text" , resp .TranscriptionResponse .Text )}
621630 outputMessages = append (outputMessages , listValue (kvs ... ))
622631 params = append (params , kvAny ("gen_ai.transcribe.output_messages" , arrValue (outputMessages ... )))
623- if resp .TranscriptionResponse .Usage .InputTokens != nil {
624- params = append (params , kvInt ("gen_ai.usage.input_tokens" , int64 (* resp .TranscriptionResponse .Usage .InputTokens )))
625- }
626- if resp .TranscriptionResponse .Usage .OutputTokens != nil {
627- params = append (params , kvInt ("gen_ai.usage.completion_tokens" , int64 (* resp .TranscriptionResponse .Usage .OutputTokens )))
628- }
629- if resp .TranscriptionResponse .Usage .TotalTokens != nil {
630- params = append (params , kvInt ("gen_ai.usage.total_tokens" , int64 (* resp .TranscriptionResponse .Usage .TotalTokens )))
631- }
632- if resp .TranscriptionResponse .Usage .InputTokenDetails != nil {
633- params = append (params , kvInt ("gen_ai.usage.input_token_details.text_tokens" , int64 (resp .TranscriptionResponse .Usage .InputTokenDetails .TextTokens )))
634- params = append (params , kvInt ("gen_ai.usage.input_token_details.audio_tokens" , int64 (resp .TranscriptionResponse .Usage .InputTokenDetails .AudioTokens )))
632+ if resp .TranscriptionResponse .Usage != nil {
633+ if resp .TranscriptionResponse .Usage .InputTokens != nil {
634+ params = append (params , kvInt ("gen_ai.usage.input_tokens" , int64 (* resp .TranscriptionResponse .Usage .InputTokens )))
635+ }
636+ if resp .TranscriptionResponse .Usage .OutputTokens != nil {
637+ params = append (params , kvInt ("gen_ai.usage.completion_tokens" , int64 (* resp .TranscriptionResponse .Usage .OutputTokens )))
638+ }
639+ if resp .TranscriptionResponse .Usage .TotalTokens != nil {
640+ params = append (params , kvInt ("gen_ai.usage.total_tokens" , int64 (* resp .TranscriptionResponse .Usage .TotalTokens )))
641+ }
642+ if resp .TranscriptionResponse .Usage .InputTokenDetails != nil {
643+ params = append (params , kvInt ("gen_ai.usage.input_token_details.text_tokens" , int64 (resp .TranscriptionResponse .Usage .InputTokenDetails .TextTokens )))
644+ params = append (params , kvInt ("gen_ai.usage.input_token_details.audio_tokens" , int64 (resp .TranscriptionResponse .Usage .InputTokenDetails .AudioTokens )))
645+ }
635646 }
636647 }
637648 }
0 commit comments