spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

Azure OpenAI Client Streaming with Function (tools)

Open Grogdunn opened this issue 11 months ago • 3 comments

The AzureOpenAI client doesn't support function calling (now called tools in Azure SDK) in streaming response.

See: https://github.com/spring-projects/spring-ai/blob/1e98f82e03529506c9afaa650717b3819633d573/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatClient.java#L168

To reproduce, create a simple Client with a tool, and invoke, the choice contains the function call, but is ignored.

Grogdunn avatar Mar 20 '24 16:03 Grogdunn

working on a PR https://github.com/optionfactory/spring-ai/tree/azure-openai-tool-streaming-478

Grogdunn avatar Mar 21 '24 08:03 Grogdunn

@Grogdunn , this is true. I've implemented the streaming function calling for Gemini, OpenAI and Mistral AI (there is some common abstractions for last two) but haven't had time to do it for the Azure OpenAI client. Would appreciate your help!

tzolov avatar Mar 21 '24 12:03 tzolov

Hi @tzolov ,

I've found another issue, but I don't know how to fix at the moment. https://github.com/spring-projects/spring-ai/blob/1e98f82e03529506c9afaa650717b3819633d573/models/spring-ai-azure-openai/src/main/java/org/springframework/ai/azure/openai/AzureOpenAiChatClient.java#L474

In case of streaming in the line above (in all client Azure, OpenAI, Mistral, Gemini) "broke" the streaming ad do non streaming request. So, in streaming environment, with function call the LLM is invoked as not streaming.

Grogdunn avatar Mar 22 '24 14:03 Grogdunn

Resolved with a7eb28ac17debbaaaf227802eb0385f3daea4fd8

tzolov avatar May 15 '24 10:05 tzolov