diff --git a/backend/modules/observability/lib/otel/open_inference/openinference.go b/backend/modules/observability/lib/otel/open_inference/openinference.go index 83a08bb9f..cd4158852 100644 --- a/backend/modules/observability/lib/otel/open_inference/openinference.go +++ b/backend/modules/observability/lib/otel/open_inference/openinference.go @@ -11,9 +11,12 @@ import ( type Literal string const ( - TextLiteral Literal = "text" - ImageLiteral Literal = "image" - ImageUrlLiteral Literal = "image_url" + TextLiteral Literal = "text" + ImageLiteral Literal = "image" + ImageUrlLiteral Literal = "image_url" + ReasoningLiteral Literal = "reasoning" + ToolCallLiteral Literal = "tool_call" + ToolCallResponseLiteral Literal = "tool_call_response" ) type ModelMessagePartType string @@ -78,6 +81,7 @@ func convertModelMsg(msg map[string]interface{}) map[string]interface{} { } if len(contents) > 0 { parts := make([]interface{}, 0, len(contents)) + toolCalls := make([]interface{}, 0) for _, content := range contents { if mc, ok := content.(map[string]interface{}); ok { mcContent, ok := mc["message_content"].(map[string]interface{}) @@ -102,11 +106,42 @@ func convertModelMsg(msg map[string]interface{}) map[string]interface{} { url, _ := imageMap["url"] part["image_url"] = map[string]interface{}{"url": url} } + case string(ReasoningLiteral): + modelMsg["reasoning_content"] = text + part = nil + case string(ToolCallLiteral): + toolCallId, _ := mcContent["id"] + toolCallName, _ := mcContent["name"] + toolCallArguments, _ := mcContent["arguments"] + modelCall := map[string]interface{}{ + "type": "function", + "id": toolCallId, + "function": map[string]interface{}{ + "name": toolCallName, + "arguments": toolCallArguments, + }, + } + toolCalls = append(toolCalls, modelCall) + part = nil + case string(ToolCallResponseLiteral): + toolCallId, _ := mcContent["id"] + toolCallResult, _ := mcContent["response"] + if toolCallResult == nil { + toolCallResult, _ = mcContent["result"] + } + modelMsg["content"] = toolCallResult + modelMsg["tool_call_id"] = toolCallId + part = nil default: } - parts = append(parts, part) + if part != nil { + parts = append(parts, part) + } } } + if len(toolCalls) > 0 { + modelMsg["tool_calls"] = toolCalls + } if len(parts) > 0 { modelMsg["parts"] = parts }