Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{})
Expand All @@ -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
}
Expand Down
Loading