generative-ai-go
generative-ai-go copied to clipboard
Validate that all `Required` function calling parameters exist in the Schema
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.
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.
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.