microsoft / sample-app-aoai-chatGPT

Sample code for a simple web chat experience through Azure OpenAI, including Azure OpenAI On Your Data.
MIT License
1.42k stars 2.13k forks source link

Issue with Open AI Function Calling #936

Open codedash07 opened 1 week ago

codedash07 commented 1 week ago

Issue: For a use case, I have data in multiple sources PDFs, excel files, 3rd party APIs. I have uploaded PDF data to AI Search and configured it in the bot app, it works fine with PDF data. Now when I try to add more data sources like 3rd party APIs using function calling feature, application throws error - "400 - Functions are not supported for this API version or this model version." while enabling function calling feature. Functions are working fine with 4/4o GPT versions when tried separately.

In code, I am trying to add tools & tool_call parameters: tools = [ { "type": "function", "function": { "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"], }, }, } ] model_args['tools'] = tools model_args['tool_choice'] = 'auto'

Configuration: Tried with GPT 4 & 40 version: 2024-05-01-preview

Can anyone please suggest the right way to do it.

sarah-widder commented 1 week ago

Hi @codedash07, we recently (last 24 hours) updated the model support for data sources + functions. Can you give it another try? If it's still not working, can you share the exact model names & versions you're using, and which region your AOAI resource is in?

codedash07 commented 5 days ago

@sarah-widder The newer codebase does not throws error "400 - Functions are not supported for this API version or this model version", . Any specific change was made in latest codebase? For streamed responses with this bot, can you please share a sample usage with function calls. It would be really helpful. I am trying to connect this bot with multiple data sources (multiple AI search indexes/3rd party APIs). Thanks in advance.

sarah-widder commented 4 days ago

@codedash07 there was a change on the service side to update the supported model list for function calling with data. For more information on function calling, please reference the documentation here. Currently, only one data source can be used at a time through the data_sources parameter.

codedash07 commented 4 days ago

@sarah-widder Thanks for this information. Is function calling only supported with Assistants API currently? Unable to find any documentation around async chat completion calls with function calling. For non-stream chat completion calls its works fine.

image ![Uploading image.png…]()

sarah-widder commented 3 days ago

@codedash07 function calling is supported with chat completions, both streaming and non-streaming. For an SDK example, it may help to look at posts in the openai discussion forums - like this one or similar - https://community.openai.com/t/streaming-function-calls-does-not-return-an-id-with-tool-calls/608510/3

If the SDK is not working, calling the chat completions API directly is also always an option.