Files
go-llm/schema/enum.go
Steve Dudenhoeffer be99af3597 Update all dependencies and migrate to new Google genai SDK
- Update all Go dependencies to latest versions
- Migrate from github.com/google/generative-ai-go/genai to google.golang.org/genai
- Fix google.go to use the new SDK API (NewPartFromText, NewContentFromParts, etc.)
- Update schema package imports to use the new genai package
- Add CLAUDE.md with README maintenance guideline

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-24 15:22:34 -05:00

62 lines
1.2 KiB
Go

package schema
import (
"errors"
"reflect"
"slices"
"github.com/openai/openai-go"
"google.golang.org/genai"
)
type enum struct {
basic
values []string
}
func (e enum) FunctionParameters() openai.FunctionParameters {
return openai.FunctionParameters{
"type": "string",
"description": e.Description(),
"enum": e.values,
}
}
func (e enum) GoogleParameters() *genai.Schema {
return &genai.Schema{
Type: genai.TypeString,
Description: e.Description(),
Enum: e.values,
}
}
func (e enum) AnthropicInputSchema() map[string]any {
return map[string]any{
"type": "string",
"description": e.Description(),
"enum": e.values,
}
}
func (e enum) FromAny(val any) (reflect.Value, error) {
v := reflect.ValueOf(val)
if v.Kind() != reflect.String {
return reflect.Value{}, errors.New("expected string, got " + v.Kind().String())
}
s := v.String()
if !slices.Contains(e.values, s) {
return reflect.Value{}, errors.New("value " + s + " not in enum")
}
return v, nil
}
func (e enum) SetValueOnField(obj reflect.Value, val reflect.Value) {
if !e.required {
val = val.Addr()
}
obj.Field(e.index).Set(val)
}