最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

c# - How to count # of tokens consumed by OpenAI Assistant while streaming the message - Stack Overflow

matteradmin8PV0评论

I am using openAI Assistant, I get the streamingUpdate using

streamingUpdate = assistantClient.CreateRunStreaming(thread, assistant);

I could iterate through streamingUpdate and send the response to the client using SignalR api. however I would like to know how to count the #of tokens consumed in the streaming mode.

I am using openAI Assistant, I get the streamingUpdate using

streamingUpdate = assistantClient.CreateRunStreaming(thread, assistant);

I could iterate through streamingUpdate and send the response to the client using SignalR api. however I would like to know how to count the #of tokens consumed in the streaming mode.

Share Improve this question edited Jan 8 at 19:39 General Grievance 5,04338 gold badges37 silver badges56 bronze badges asked Nov 18, 2024 at 10:14 Sankaranarayanan RajkumarSankaranarayanan Rajkumar 511 silver badge7 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

I found the way to get the token count

CompletionTokens = assistantClient.GetRuns(threadID).Select(f => f.Usage.CompletionTokens).SingleOrDefault();
PromptTokens = assistantClient.GetRuns(threadID).Select(f => f.Usage.PromptTokens).SingleOrDefault();
TotalTokens = assistantClient.GetRuns(threadID).Select(f => f.Usage.TotalTokens).SingleOrDefault();
Post a comment

comment list (0)

  1. No comments so far