pub struct FunctionSpecification {
pub name: String,
pub description: Option<String>,
pub parameters: Option<Parameters>,
}
Expand description
The documentation for a function
§Caveats
The documentation, in July 2023 is not accurate https://platform.openai.com/docs/api-reference/chat/create#chat/create-parameters
It states that the parameters are optional, but they are not:
curl https://api.openai.com/v1/chat/completions -H “Content-Type: application/json” -H “Authorization: Bearer $OPENAI_API_KEY” -d ‘{ “model”: “gpt-3.5-turbo-0613”, “messages”: [{“role”: “system”, “content”: “You are a helpful assistant.”}, {“role”: “user”, “content”: “What is the weather like in Madrid, Spain?”}], “functions”: [{ “name”: “get_current_weather”, “description”: “Get the current weather in a given location” }], “function_call”: “auto” }’ { “error”: { “message”: “‘parameters’ is a required property - ‘functions.0’”, “type”: “invalid_request_error”, “param”: null, “code”: null } }
The library works around it by actually having the parameters as optional in the struct, so the configuration can be parsed correctly, but then printing the object with the parameters and the minimum required fields so the API doesn’t complain. This would be by adding the parameteres, with type and empty properties. Like this:
curl https://api.openai.com/v1/chat/completions -H “Content-Type: application/json” -H “Authorization: Bearer $OPENAI_API_KEY” -d ‘{ “model”: “gpt-3.5-turbo-0613”, “messages”: [{“role”: “system”, “content”: “You are a helpful assistant.”}, {“role”: “user”, “content”: “What is the weather like in Madrid, Spain?”}], “functions”: [{ “name”: “get_current_weather”, “description”: “Get the current weather in a given location”, “parameters”: { “type”: “object”, “properties”: {} } }] }’
Fields§
§name: String
§description: Option<String>
§parameters: Option<Parameters>
Implementations§
Source§impl FunctionSpecification
impl FunctionSpecification
pub fn new( name: String, description: Option<String>, parameters: Option<Parameters>, ) -> FunctionSpecification
Trait Implementations§
Source§impl Clone for FunctionSpecification
impl Clone for FunctionSpecification
Source§fn clone(&self) -> FunctionSpecification
fn clone(&self) -> FunctionSpecification
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more