Hi, I am trying to build tool function with the following example. It is found that the tool choice paramter cannot be set to required or there will incur error. Can you help explain the right way to set required mode
#error message:
BadRequestError: Error code: 400 - {‘error’: {‘message’: “‘$.tool_choice’ is invalid. Please check the API reference: https://platform.openai.com/docs/api-reference.”, ‘type’: ‘invalid_request_error’, ‘param’: None, ‘code’: None}}
#code
def get_assets(asset):
"""Get asset names required by the """
# if "tokyo" in location.lower():
# return json.dumps({"location": "Tokyo", "temperature": "10", "unit": unit})
# elif "san francisco" in location.lower():
# return json.dumps({"location": "San Francisco", "temperature": "72", "unit": unit})
# elif "paris" in location.lower():
# return json.dumps({"location": "Paris", "temperature": "22", "unit": unit})
# else:
# return json.dumps({"location": location, "temperature": "unknown"})
return 0
# Step 1: send the conversation and available functions to the model
messages = [{"role": "user", "content": "what is Nvidia performance"}]
tools = [
{
"type": "function",
"function": {
"name": "get_asset_name",
"description": "find documents for the assigned assets",
"parameters": {
"type": "object",
"properties": {
"asset": {
"type": "string",
"description": "Asset name. The asset class can be any type, like companies, and currencies"
},
},
"required": ['aset'],
},
},
}
]
response = client.chat.completions.create(
model='...',
messages=messages,
tools=tools,
tool_choice='required'
)