Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions go/plugins/compat_oai/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,14 @@ func (g *ModelGenerator) WithMessages(messages []*ai.Message) *ModelGenerator {
if !p.IsToolResponse() {
continue
}
// Use the captured tool call ID (Ref) if available, otherwise fall back to tool name
toolCallID := p.ToolResponse.Ref
if toolCallID == "" {
toolCallID = p.ToolResponse.Name
}

tm := openai.ToolMessage(
// NOTE: Temporarily set its name instead of its ref (i.e. call_xxxxx) since it's not defined in the ai.ToolResponse struct.
p.ToolResponse.Name,
toolCallID,
anyToJSONString(p.ToolResponse.Output),
)
oaiMessages = append(oaiMessages, tm)
Expand Down Expand Up @@ -346,6 +351,7 @@ func (g *ModelGenerator) generateComplete(ctx context.Context) (*ai.ModelRespons
var toolRequestParts []*ai.Part
for _, toolCall := range choice.Message.ToolCalls {
toolRequestParts = append(toolRequestParts, ai.NewToolRequestPart(&ai.ToolRequest{
Ref: toolCall.ID,
Name: toolCall.Function.Name,
Input: jsonStringToMap(toolCall.Function.Arguments),
}))
Expand Down Expand Up @@ -374,9 +380,13 @@ func convertToolCalls(content []*ai.Part) []openai.ChatCompletionMessageToolCall
}

func convertToolCall(part *ai.Part) openai.ChatCompletionMessageToolCallParam {
toolCallID := part.ToolRequest.Ref
if toolCallID == "" {
toolCallID = part.ToolRequest.Name
}

param := openai.ChatCompletionMessageToolCallParam{
// NOTE: Temporarily set its name instead of its ref (i.e. call_xxxxx) since it's not defined in the ai.ToolRequest struct.
ID: (part.ToolRequest.Name),
ID: (toolCallID),
Function: (openai.ChatCompletionMessageToolCallFunctionParam{
Name: (part.ToolRequest.Name),
}),
Expand Down
Loading