Don't understand how to add enum validation to function call

Welcome @pine.cadet

You can simply look at the function call object within the response. Here’s how it looks before json parsing it:

"function_call": {
          "arguments": "{\n  \"location\": \"Boston, MA\"\n}",
          "name": "get_current_weather"
        },

Corresponding to the function definition:

"functions": [
    {
      "name": "get_current_weather",
      "description": "Get the current weather in a given location",
      "parameters": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "The city and state, e.g. San Francisco, CA"
          },
          "unit": {
            "type": "string",
            "enum": ["celsius", "fahrenheit"]
          }
        },
        "required": ["location"]
      }
    }
  ]

One you parse the function_call object, simply validate the value of complaints argument.

const complaint = functionArguments["complaint"];
const validComplaints = ["Value 1", "Value 2", "Value 3"];
  if (!validComplaints.includes(complaint)) {
    // Handle the invalid complaint here
    return { error: "Invalid complaint received" };
  }
1 Like