OkGoDoIt / OpenAI-API-dotnet

An unofficial C#/.NET SDK for accessing the OpenAI GPT-3 API

Home Page:https://www.nuget.org/packages/OpenAI/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MostResentAPIResult.Usage is null

771185858 opened this issue · comments

After using Chat.StreamResponseEnumerableFromChatbotAsync() in Streaming, the Usage of Chat.MostResetAPIResult is always null. How can I obtain 'Usage' related information

var chat = _openAI.Client().Chat.CreateConversation();
chat.AppendUserInput("How to make bread ?");
await foreach (var res in chat.StreamResponseEnumerableFromChatbotAsync()).
{
await Clients.Client(connectionId).SendAsync("ChatGPTMessage", res);
}
var result = chat.MostResentAPIResult;

result.Usage is null

Can someone explain? Thank you very much

Look forward to your help @OkGoDoIt

commented

Hoping this can get looked at as well.

I saw the 1.8 update changed some stuff, this is unfortunately still coming out null for me too.

When streaming results, OpenAI does not provide usage details. Unfortunately this is a limitation of the OpenAI API and there's nothing I can do about it 😢
See this support thread: https://community.openai.com/t/openai-api-get-usage-tokens-in-response-when-set-stream-true/141866/18

commented

Thank you for the swift response and clarification