Refactor toolbox and function handling to support synthetic fields and improve type definitions
This commit is contained in:
30
openai.go
30
openai.go
@@ -31,23 +31,21 @@ func (o openaiImpl) newRequestToOpenAIRequest(request Request) openai.ChatComple
|
||||
res.Messages = append(res.Messages, msg.toChatCompletionMessages(o.model)...)
|
||||
}
|
||||
|
||||
if request.Toolbox != nil {
|
||||
for _, tool := range request.Toolbox.funcs {
|
||||
res.Tools = append(res.Tools, openai.ChatCompletionToolParam{
|
||||
Type: "function",
|
||||
Function: shared.FunctionDefinitionParam{
|
||||
Name: tool.Name,
|
||||
Description: openai.String(tool.Description),
|
||||
Strict: openai.Bool(tool.Strict),
|
||||
Parameters: tool.Parameters.OpenAIParameters(),
|
||||
},
|
||||
})
|
||||
}
|
||||
for _, tool := range request.Toolbox.functions {
|
||||
res.Tools = append(res.Tools, openai.ChatCompletionToolParam{
|
||||
Type: "function",
|
||||
Function: shared.FunctionDefinitionParam{
|
||||
Name: tool.Name,
|
||||
Description: openai.String(tool.Description),
|
||||
Strict: openai.Bool(tool.Strict),
|
||||
Parameters: tool.Parameters.OpenAIParameters(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if !request.Toolbox.dontRequireTool {
|
||||
res.ToolChoice = openai.ChatCompletionToolChoiceOptionUnionParam{
|
||||
OfAuto: openai.String("required"),
|
||||
}
|
||||
if request.Toolbox.RequiresTool() {
|
||||
res.ToolChoice = openai.ChatCompletionToolChoiceOptionUnionParam{
|
||||
OfAuto: openai.String("required"),
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user