Added the exact token count for the OpenAI Responses API

This commit is contained in:
Thorsten Sommer committed 2026-09-24 13:07:04 +02:00
1 parent 4becb98ee2
commit 4990bc116c
10 files changed
+363 -12

No files matched your search

@@ -59,14 +59,16 @@ public sealed class ResponsesToolCallingAdapter(Model chatModel, IList<object> b
//
// The text goes out while it is being written, the round only once the stream closed it.
// Sources travel with the text because the API announces them as it cites them.
// Sources travel with the text because the API announces them as it cites them. The usage
// goes out with every round: which of them describes the conversation is the loop's
// decision, which knows which round this is.
//
var accumulator = new ResponsesStreamAccumulator();
await foreach (var serverSentEvent in streamRequestAsync(request, token))
{
var part = accumulator.Process(serverSentEvent);
if (part.HasContent)
yield return ToolCallingStreamEvent.TextDelta(new ContentStreamChunk(part.TextDelta, part.Sources));
if (part.HasContent || part.Usage.IsKnown)
yield return ToolCallingStreamEvent.TextDelta(new ContentStreamChunk(part.TextDelta, part.Sources, Usage: part.Usage));
}
var response = accumulator.Build();