instead of having an openai => google translation layer, just add sister functions to the types that construct the google request just like openai's
This commit is contained in:
@@ -2,10 +2,10 @@ package schema
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/openai/openai-go"
|
||||
"reflect"
|
||||
|
||||
"github.com/sashabaranov/go-openai/jsonschema"
|
||||
"github.com/google/generative-ai-go/genai"
|
||||
"github.com/openai/openai-go"
|
||||
)
|
||||
|
||||
type object struct {
|
||||
@@ -16,14 +16,10 @@ type object struct {
|
||||
fields map[string]Type
|
||||
}
|
||||
|
||||
func (o object) SchemaType() jsonschema.DataType {
|
||||
return jsonschema.Object
|
||||
}
|
||||
|
||||
func (o object) FunctionParameters() openai.FunctionParameters {
|
||||
func (o object) OpenAIParameters() openai.FunctionParameters {
|
||||
var properties = map[string]openai.FunctionParameters{}
|
||||
for k, v := range o.fields {
|
||||
properties[k] = v.FunctionParameters()
|
||||
properties[k] = v.OpenAIParameters()
|
||||
}
|
||||
|
||||
return openai.FunctionParameters{
|
||||
@@ -33,16 +29,17 @@ func (o object) FunctionParameters() openai.FunctionParameters {
|
||||
}
|
||||
}
|
||||
|
||||
func (o object) Definition() jsonschema.Definition {
|
||||
def := o.basic.Definition()
|
||||
def.Type = jsonschema.Object
|
||||
def.Properties = make(map[string]jsonschema.Definition)
|
||||
func (o object) GoogleParameters() *genai.Schema {
|
||||
var properties = map[string]*genai.Schema{}
|
||||
for k, v := range o.fields {
|
||||
def.Properties[k] = v.Definition()
|
||||
properties[k] = v.GoogleParameters()
|
||||
}
|
||||
|
||||
def.AdditionalProperties = false
|
||||
return def
|
||||
return &genai.Schema{
|
||||
Type: genai.TypeObject,
|
||||
Description: o.Description(),
|
||||
Properties: properties,
|
||||
}
|
||||
}
|
||||
|
||||
func (o object) FromAny(val any) (reflect.Value, error) {
|
||||
|
Reference in New Issue
Block a user