Skip to content

How to correctly obtain tokens usage from ChatMessageContent response #10322

Answered by RogerBarreto
AdriAJ1 asked this question in Q&A
Discussion options

You must be logged in to vote

@AdriAJ1 you are right, we don't have abstraction for Usage data in the C# library as the usage at the time and still a very specific OpenAI feature.

When using the OpenAI connector against OpenAI compatible API's you may have a better experience using the InnerContent instead of the Metadata:

See here:

var replyInnerContent = reply.InnerContent as OpenAI.Chat.ChatCompletion;

Retrieving the token count:

Console.WriteLine($"Input tokens usage: {innerContent.U…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RogerBarreto
Comment options

Answer selected by AdriAJ1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
.NET Issue or Pull requests regarding .NET code triage
3 participants