Here is my code
response = openai.ChatCompletion.create(
engine="XXX", # The deployment name you chose when you deployed the ChatGPT or GPT-4 model.
messages=[
{"role": "system", "content": "Assistant is a large language model trained by OpenAI."},
{"role": "user", "content": "Calculate the circumference of circle with radius 5?"}
],
functions=[{'name': 'circumference_calc', 'description': 'Calculate the circumference of circle given the radius', 'parameters': {'type': 'object', 'properties': {'radius': {'description': 'The radius of the circle', 'type': 'number'}}}, 'required': ['radius']}]
)
Results in :
InvalidRequestError: Unrecognized request argument supplied: functions
Wrote the above code
UPDATE (13. July 2023): Azure now supports function calling in API version 2023-07-01-preview on these models:
gpt-4-0613gpt-4-32k-0613gpt-35-turbo-0613 (thanks Joel)gpt-35-turbo-16k-0613Only version gpt-3.5-turbo-0613 and gpt-4-0613 has function calling (ref), and Azure OpenAI Services only supports these for now (ref):
gpt-3.5-turbo-0301gpt-4-0314gpt-4-32k-0314Hopefully, the Azure OpenAI Service team will support the 0613 version soon.
UPDATE (3. July 2023): Even though 0613 is out now, it seems like they still don't support functions as a parameter, as some others have pointed out here. I have tested using 2023-06-01-preview, which is supposed to be the newest API interface (according to these specs) with no luck.. I also found that version 2023-07-01-preview is working too, now, but no luck there either. (This has now changed. See update on the top^)
This has started working now. Make sure that your model version is 0613. I have tested with gpt-35-turbo.
import openai
openai.api_type = "azure"
openai.api_key = "XXX"
openai.api_base = "https://XXXX.openai.azure.com/"
openai.api_version = "2023-07-01-preview"
response = openai.ChatCompletion.create(
engine="XXX",
messages=[{"role": "user", "content": "what is current date?"}],
functions=[
{
"name": "get_current_date",
"description": "Get the current date in YYYY-MM-DD format",
"parameters": {"type": "object", "properties": {}, "required": []},
}
],
)
print(response["choices"][0])
Response:
<OpenAIObject at 0x10d2c1790> JSON: {
"index": 0,
"finish_reason": "function_call",
"message": {
"role": "assistant",
"function_call": {
"name": "get_current_date",
"arguments": "{}"
}
},
"content_filter_results": {}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With