Using Responses API with streaming and function call in .Net OpenAPI (C# SDK 2.2.0-beta.4)

Hi! I am trying to set up a ChatGPT solution in my .Net API, using streaming and function calls with the Responses API. I see this as fantastic AI-solution for my project. But code samples for this in .Net is not easy to find (yet). I hope Responses streaming+function call will be added to the github “How to”-demos…

The thing I now struggle with is the function part, more specifically how to return a function result back in the “streaming loop”. I got it to work without streaming, but with streaming I cannot figure out these things - really appreciate if someone has any tips :slight_smile:

My c# code basically looks like this:

//Main loop after getting a prompt from user
await foreach (StreamingResponseUpdate update in
_responseClient.CreateResponseStreamingAsync(userInputText: prompt.UserMessage,
              responseOptions))
{
    if (update is StreamingResponseCreatedUpdate created)
    {
       //Must remember this for later function calls (I guess):
       newResponseId = created.Response.Id;
     }
     if (update is ...)
     ...
     else if (update is StreamingResponseFunctionCallArgumentsDoneUpdate funcCall)
     {
         //I guess this is the right place to call the function
        string toolResult = CallMyFunction(funcCall.Arguments)

        //I create new Input Items with function results:
        var inputItems = new List<ResponseItem>();
        inputItems.Add(new FunctionCallOutputResponseItem(funcCall.ItemId, toolResult));

        //New loop for calling OpenAI with function results:
        await foreach (StreamingResponseUpdate updateFunc in _responseClient.CreateResponseStreamingAsync(inputItems, new ResponseCreationOptions
                            {                                
                                PreviousResponseId = newResponseId,
                                Tools = { getCurrentWeatherTool },
                            }))
        {
           //this code is never reached, the CreateResponseStreamingAsync call above creates an  exception
        }
    }    
}

I get exception “No tool output found for function call call…xxx”

I don’t know what I am missing here, I hope it is just some syntax problem, maybe my function result should not be returned in StreamingResponseFunctionCallArgumentsDoneUpdate at all, but I can’t find another logical place to execute the function and return the result. I guess I also should have a “CallId”, but there is no such thing in the StreamingResponseFunctionCallArgumentsDoneUpdate class.

Or maybe this is simply not working in this beta :grimacing: