Skip to content

How get StreamingResponseUpdate or ResponseItem StructData #818

@The-Mojoo

Description

@The-Mojoo

I am using Response and Stream, and I want to get data like:
event: response.output_text.delta data: {"type":"response.output_text.delta","item_id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","output_index":0,"content_index":0,"delta":"Hi"}
or
{"type":"response.output_text.delta","item_id":"msg_67c9fdcf37fc8190ba82116e33fb28c507b8b0ad4e5eb654","output_index":0,"content_index":0,"delta":"Hi"}
primitive data structure, save in my database for logging purposes.
I know I can output each property individually to assemble them, but I still prefer ToJson() or System.Text.Json.JsonSerializer.Serialize(update) .

await foreach (var update in client.CreateResponseStreamingAsync(question, options))
{
    switch (update)
    {
        case StreamingResponseCompletedUpdate chatCompletion:
            // System.Text.Json.JsonSerializer.Serialize(chatCompletion)
            foreach (var responseItme in chatCompletion.Response.OutputItems)
            {
                switch (responseItme)
                {
                    case FunctionCallResponseItem functionCall:
                    // System.Text.Json.JsonSerializer.Serialize(functionCall) 
                    break;
                }
            }
            break;
    }
}

Metadata

Metadata

Assignees

Labels

area: responsesThis item is related to Responsesissue-addressedWorkflow: The OpenAI maintainers believe the issue to be addressed and ready to close.questionCategory: The issue is seeking information about the library or its usage.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions