anasfik / openai

Dart/Flutter SDK for ChatGPT and all OpenAI APIs (GPT, Dall-e..)
https://pub.dev/packages/dart_openai
MIT License
593 stars 186 forks source link

Need to add the field 'usage' to OpenAIStreamChatCompletionModel #155

Closed hnvmeta closed 9 months ago

hnvmeta commented 9 months ago

I need to read the total_tokens field in JSON which is returned from OpenAI. Can you add this field to the OpenAIStreamChatCompletionModel class? Because this class is final, I can't extend it.

anasfik commented 9 months ago

The thing is the chat responses chunk object doesn't support having the usage like the asynchronous chat response object

dominic-deantonio commented 5 months ago

Hi @anasfik I am looking for this feature too. It seems that the chat responses chunk object does include usage according to the page you linked (maybe it didn't before?), just need to include stream_options: {"include_usage": true}. It says it will be null until the final chunk.

Screenshot 2024-06-07 at 3 54 57 PM

I will try to find where to put that in the library, but any help would be appreciated.

Update: I made a PR for this: https://github.com/anasfik/openai/pull/180