-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Hacky workaround to get token usage from chat completions api response #1565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
.NET
Issue or Pull requests regarding .NET code
Comments
@RogerBarreto any thoughts here? |
4 tasks
@singhk97, Addressing the well spotted problem. |
github-merge-queue bot
pushed a commit
that referenced
this issue
Aug 30, 2023
…2657) ### Motivation and Context `IChatResult` interface misses the ModelResult abstraction Resolves #1565 Closes #1565 ### Description Added missing abstraction. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
SOE-YoungS
pushed a commit
to SOE-YoungS/semantic-kernel
that referenced
this issue
Nov 1, 2023
…icrosoft#2657) ### Motivation and Context `IChatResult` interface misses the ModelResult abstraction Resolves microsoft#1565 Closes microsoft#1565 ### Description Added missing abstraction. ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying to get the token usage data from the response of a call to the OpenAI's chat completion api but it doesn't seem possible. Here are the details:
IChatCompletion.GetChatCompletionsAsync
returns a list ofIChatResult
objects. It represents the response from OpenAI's chat completion API. The issue is that this interface does not have theModelResult
property which contains token usage data. Hence, there's no way to get the token usage data when using the chat completion api. In contrast, theITextCompletion.GetCompletionsAsync
returns a list ofITextResult
objects which do contain theModelResult
property.Looking deeper into the code, it looks like the concrete object type of
IChatResult
which is the internal classChatResult
has theModelResult
property. So then I was able to cast theIChatResult
to aITextResult
and access that property:There should be a simple fix for this.
The text was updated successfully, but these errors were encountered: