Model response format from custom chat completion service to ensure that functions are auto invoked by SK #6389
-
Hi Team, We have a custom chat completion service, which calls the model and getting the response. The custom service does some other tasks like load balancing, content checks as well. Currently the streaming response returned by this service is not interpreted by SK for calling the functions automatically. It seems the issue is with our service response format. Any idea, how we can get the format expected by SK to call the functions automatically? We are using SK 1.9 version. Below is the code snippet. If I use Azure Open AI model, it's working fine. But, if I use our custom service, it's not working. This must be due to response format returned by service itself. Any pointers in identifying the expected format so that auto function invocation happens? ` Kernel kernel = kernelBuilder.Build(); kernel.ImportPluginFromObject(new WeatherSearchPlugin(), nameof(WeatherSearchPlugin));
var stream = chatCompletion.GetStreamingChatMessageContentsAsync( var Content = ""; try public class WeatherSearchPlugin ` Response returned by model is in below format: ` ` |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hi @ddramireddy ! Non-streaming: Streaming: Looking at model response provided by you, it looks like a response for non-streaming scenario. You could try to get non-streaming chat message content and see if your function will be called. If you still want to use streaming capability, your custom model should return a response in the same format as provided above for streaming scenario. Please let me know if that helps! |
Beta Was this translation helpful? Give feedback.
-
Hi @dmytrostruk , Thank you for the quick response. It looks as I misunderstood that Semantic Kernel framework does call the functions automatically based on model response. But, it seems the connectors needs to parse the model response, if there are any tool calls, execute those functions. I can see OpenAI connector is invoking the functions based on response in tool_calls. Is there any reason, this is not abstracted to Semantic Kernel framework, instead of delegating to individual connectors/services? |
Beta Was this translation helpful? Give feedback.
-
@ddramireddy That's correct, but SK also has a mode to ask LLM to provide which functions to call, but SK won't call it automatically, instead, it will provide function information to you, so you will be able to call it manually. This file contains some examples with automatic and manual function calling:
Great question! This work is currently in progress: |
Beta Was this translation helpful? Give feedback.
-
Wow, Great to know this. :) If this change can come in next few weeks, we can wait, and it can reduce some of our development effort. Thank you very much @dmytrostruk |
Beta Was this translation helpful? Give feedback.
@ddramireddy That's correct, but SK also has a mode to ask LLM to provide which functions to call, but SK won't call it automatically, instead, it will provide function information to you, so you will be able to call it manually. This file contains some examples with automatic and manual function calling:
https://github.com/microsoft/semantic-kernel/blob/main/dotnet/samples/Concepts/AutoFunctionCalling/OpenAI_FunctionCalling.cs
Great qu…