google / generative-ai-go

Go SDK for Google Generative AI
Apache License 2.0
577 stars 56 forks source link

Validate that all `Required` function calling parameters exist in the Schema #93

Open fredsa opened 6 months ago

fredsa commented 6 months ago

Using github.com/google/generative-ai-go v0.11.0, this code does not complain about the "this_param_does_not_exist" entry in the Required field.

    currencyExchange := &genai.Tool{
        FunctionDeclarations: []*genai.FunctionDeclaration{{
            Name:        "get_exchange_rate",
            Description: "Lookup currency exchange rates by date",
            Parameters: &genai.Schema{
                Type: genai.TypeObject,
                Properties: map[string]*genai.Schema{
                    "currency_date": {
                        Type: genai.TypeString,
                        Description: "A date that must always be in YYYY-MM-DD format" +
                            " or the value 'latest' if a time period is not specified",
                    },
                    "currency_from": {
                        Type:        genai.TypeString,
                        Description: "Currency to convert from",
                    },
                    "currency_to": {
                        Type:        genai.TypeString,
                        Description: "Currency to convert to",
                    },
                },
                                 // Note, "this_param_does_not_exist".
                Required: []string{"currency_date", "currency_from", "this_param_does_not_exist"},
            },
        }},
    }

To help developers, it would be immensely valuable to validate the Required field values.

jba commented 6 months ago

Isn't that something the service should do, not the client? The client generally tries to do minimal validation or manipulation of requests to the service.

fredsa commented 6 months ago

That would be fine as well. Though, I suspect it will be easier for the client library / SDK to provide a much more useful message to the developer, though admittedly at the cost of duplicate complexity across all language client libraries / SDKs.

In short, happy to have the validation happen in either place.