added anthropic tool support i think
This commit is contained in:
@@ -31,6 +31,14 @@ func (a array) GoogleParameters() *genai.Schema {
|
||||
}
|
||||
}
|
||||
|
||||
func (a array) AnthropicInputSchema() map[string]any {
|
||||
return map[string]any{
|
||||
"type": "array",
|
||||
"description": a.Description(),
|
||||
"items": a.items.AnthropicInputSchema(),
|
||||
}
|
||||
}
|
||||
|
||||
func (a array) FromAny(val any) (reflect.Value, error) {
|
||||
v := reflect.ValueOf(val)
|
||||
|
||||
|
@@ -70,6 +70,32 @@ func (b basic) GoogleParameters() *genai.Schema {
|
||||
}
|
||||
}
|
||||
|
||||
func (b basic) AnthropicInputSchema() map[string]any {
|
||||
var t = "string"
|
||||
|
||||
switch b.DataType {
|
||||
case TypeString:
|
||||
t = "string"
|
||||
case TypeInteger:
|
||||
t = "integer"
|
||||
case TypeNumber:
|
||||
t = "number"
|
||||
case TypeBoolean:
|
||||
t = "boolean"
|
||||
case TypeObject:
|
||||
t = "object"
|
||||
case TypeArray:
|
||||
t = "array"
|
||||
default:
|
||||
t = "unknown"
|
||||
}
|
||||
|
||||
return map[string]any{
|
||||
"type": t,
|
||||
"description": b.description,
|
||||
}
|
||||
}
|
||||
|
||||
func (b basic) Required() bool {
|
||||
return b.required
|
||||
}
|
||||
|
@@ -31,6 +31,14 @@ func (e enum) GoogleParameters() *genai.Schema {
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@@ -98,6 +98,29 @@ func (o Object) GoogleParameters() *genai.Schema {
|
||||
return res
|
||||
}
|
||||
|
||||
func (o Object) AnthropicInputSchema() map[string]any {
|
||||
var properties = map[string]any{}
|
||||
var required []string
|
||||
for k, v := range o.fields {
|
||||
properties[k] = v.AnthropicInputSchema()
|
||||
if v.Required() {
|
||||
required = append(required, k)
|
||||
}
|
||||
}
|
||||
|
||||
var res = map[string]any{
|
||||
"type": "object",
|
||||
"description": o.Description(),
|
||||
"properties": properties,
|
||||
}
|
||||
|
||||
if len(required) > 0 {
|
||||
res["required"] = required
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// FromAny converts the value from any to the correct type, returning the value, and an error if any
|
||||
func (o Object) FromAny(val any) (reflect.Value, error) {
|
||||
// if the value is nil, we can't do anything
|
||||
|
@@ -10,6 +10,7 @@ import (
|
||||
type Type interface {
|
||||
OpenAIParameters() openai.FunctionParameters
|
||||
GoogleParameters() *genai.Schema
|
||||
AnthropicInputSchema() map[string]any
|
||||
|
||||
//SchemaType() jsonschema.DataType
|
||||
//Definition() jsonschema.Definition
|
||||
|
Reference in New Issue
Block a user