Skip to content

Commit

Permalink
chore: return toolMapping in chat progress message
Browse files Browse the repository at this point in the history
  • Loading branch information
ibuildthecloud committed Oct 10, 2024
1 parent 8a0f8c6 commit df259f9
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/openai/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ func (c *Client) Call(ctx context.Context, messageRequest types.CompletionReques
}
}

toolMapping := map[string]string{}
for _, tool := range messageRequest.Tools {
var params any = tool.Function.Parameters
if tool.Function.Parameters == nil || len(tool.Function.Parameters.Properties) == 0 {
Expand All @@ -365,6 +366,10 @@ func (c *Client) Call(ctx context.Context, messageRequest types.CompletionReques
}
}

if tool.Function.ToolID != "" {
toolMapping[tool.Function.Name] = tool.Function.ToolID
}

request.Tools = append(request.Tools, openai.Tool{
Type: openai.ToolTypeFunction,
Function: &openai.FunctionDefinition{
Expand All @@ -378,7 +383,10 @@ func (c *Client) Call(ctx context.Context, messageRequest types.CompletionReques
id := counter.Next()
status <- types.CompletionStatus{
CompletionID: id,
Request: request,
Request: map[string]any{
"chatCompletion": request,
"toolMapping": toolMapping,
},
}

var cacheResponse bool
Expand Down

0 comments on commit df259f9

Please sign in to comment.