Add support for integers and tool configuration in schema handling
This update introduces support for `jsonschema.Integer` types and updates the logic to handle nested items in schemas. Added a new default error log for unknown types using `slog.Error`. Also, integrated tool configuration with a `FunctionCallingConfig` when `dontRequireTool` is false.
This commit is contained in:
34
response.go
34
response.go
@@ -1,6 +1,8 @@
|
||||
package go_llm
|
||||
|
||||
import "github.com/sashabaranov/go-openai"
|
||||
import (
|
||||
"github.com/openai/openai-go"
|
||||
)
|
||||
|
||||
type ResponseChoice struct {
|
||||
Index int
|
||||
@@ -30,24 +32,34 @@ func (r ResponseChoice) toRaw() map[string]any {
|
||||
return res
|
||||
}
|
||||
|
||||
func (r ResponseChoice) toChatCompletionMessages() []openai.ChatCompletionMessage {
|
||||
var res = openai.ChatCompletionMessage{
|
||||
Role: openai.ChatMessageRoleAssistant,
|
||||
Content: r.Content,
|
||||
Refusal: r.Refusal,
|
||||
func (r ResponseChoice) toChatCompletionMessages(_ string) []openai.ChatCompletionMessageParamUnion {
|
||||
var as openai.ChatCompletionAssistantMessageParam
|
||||
|
||||
if r.Name != "" {
|
||||
as.Name = openai.String(r.Name)
|
||||
}
|
||||
if r.Refusal != "" {
|
||||
as.Refusal = openai.String(r.Refusal)
|
||||
}
|
||||
|
||||
if r.Content != "" {
|
||||
as.Content.OfString = openai.String(r.Content)
|
||||
}
|
||||
|
||||
for _, call := range r.Calls {
|
||||
res.ToolCalls = append(res.ToolCalls, openai.ToolCall{
|
||||
ID: call.ID,
|
||||
Type: openai.ToolTypeFunction,
|
||||
Function: openai.FunctionCall{
|
||||
as.ToolCalls = append(as.ToolCalls, openai.ChatCompletionMessageToolCallParam{
|
||||
ID: call.ID,
|
||||
Function: openai.ChatCompletionMessageToolCallFunctionParam{
|
||||
Name: call.FunctionCall.Name,
|
||||
Arguments: call.FunctionCall.Arguments,
|
||||
},
|
||||
})
|
||||
}
|
||||
return []openai.ChatCompletionMessage{res}
|
||||
return []openai.ChatCompletionMessageParamUnion{
|
||||
{
|
||||
OfAssistant: &as,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (r ResponseChoice) toInput() []Input {
|
||||
|
Reference in New Issue
Block a user