Function Calling Not Working With Latest OpenAI API Version

bharath 0 Reputation points
2023-12-12T07:26:57.18+00:00

While using the new OpenAI library version 1.3.7 function calling is not working.I am seeing the below error using the code below.

Error:

openai.NotFoundError: Error code: 404 - {'error': {'message': 'Unrecognized request argument supplied: functions', 'type': 'invalid_request_error', 'param': None, 'code': None}}

import osimport jsonfrom openai import AzureOpenAIclient = AzureOpenAI(    azure_endpoint="https://neyahopenai.openai.azure.com/",    api_version="2023-07-01-preview",    api_key=os.environ["OPENAI_API_KEY"])def get_stock_price(symbol):    """Get the current stock price for given symbol"""    stock_info = {        "symbol": symbol,        "price": "1000"    }    return json.dumps(stock_info)functions = [    {        "name": "get_stock_price",        "description": "Get the current stock price for the given symbol",        "parameters": {            "type": "object",            "properties": {                "symbol": {                    "type": "string",                    "description": "The symbol, e.g. AAPL",                }            },            "required": ["symbol"],        },    }]messages = [{'role': 'user', 'content': 'Get stock symbol and price for Apple'}]response = client.chat.completions.create(    model="text_demo",    messages=messages,    functions=functions,    function_call="auto")response_message = response.choices[0].messageprint(response_message)
Azure OpenAI Service
Azure OpenAI Service
An Azure service that provides access to OpenAI’s GPT-3 models with enterprise capabilities.
4,080 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Saurabh Sharma 23,846 Reputation points Microsoft Employee Moderator
    2023-12-12T18:53:48.5833333+00:00

    Hi @bharath ,

    Welcome to Microsoft Q&A! Thanks for posting the question.

    I have checked your code, and it works fine with OpenAI library version 1.3.7 with GPT 3.5 Turbo and GPT 4 model.

    User's image

    I believe, it is an issue with the model you are using. As mentioned in the documentation please try with latest version of gpt-35-turbo and gpt-4 model.

    User's image

    Please let me know if you still see any issues.

    Thanks

    Saurabh

    1 person found this answer helpful.

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.