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:
Steve Dudenhoeffer 2025-04-04 20:13:46 -04:00
parent 82feb7d8b4
commit ff5e4ca7b0

View File

@ -4,10 +4,10 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/sashabaranov/go-openai/jsonschema"
"log/slog"
"github.com/google/generative-ai-go/genai"
"github.com/sashabaranov/go-openai/jsonschema"
"google.golang.org/api/option"
)
@ -39,6 +39,9 @@ func (g google) requestToChatHistory(in Request, model *genai.GenerativeModel) (
case jsonschema.String:
res.Type = genai.TypeString
case jsonschema.Integer:
res.Type = genai.TypeInteger
case jsonschema.Number:
res.Type = genai.TypeNumber
@ -47,6 +50,11 @@ func (g google) requestToChatHistory(in Request, model *genai.GenerativeModel) (
default:
res.Type = genai.TypeUnspecified
slog.Error("unknown type in go_llm/google.go!requestToChatHistory", "type", in.Type)
}
if in.Items != nil {
res.Items = openAiSchemaToGenAISchema(*in.Items)
}
res.Description = in.Description
@ -77,6 +85,12 @@ func (g google) requestToChatHistory(in Request, model *genai.GenerativeModel) (
},
})
}
if !in.Toolbox.dontRequireTool {
res.ToolConfig = &genai.ToolConfig{FunctionCallingConfig: &genai.FunctionCallingConfig{
Mode: genai.FunctionCallingAny,
}}
}
}
cs := res.StartChat()