-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
.Net: [Feature Request] Expose token usage and executed prompt as part of function result. #4691
Comments
@gmantri Token usage is already part of semantic-kernel/dotnet/samples/KernelSyntaxExamples/Example43_GetModelResult.cs Lines 30 to 34 in 3fadf9a
This is not supported at the moment, but if it would be useful, we will add it as part of I would also recommend checking new approach of getting token usage and prompt - filters. PR with filters is here and will be released soon: #4437 |
@dmytrostruk - Thanks. I am not sure how I missed that. I will go ahead and close this. Do you want me to open up a new issue for the prompt so that it can be tracked properly? @dmm-l-mediehus - It may be worthwhile to open a new issue for your question. |
@dmm-l-mediehus I just checked, it doesn't look like Azure SDK or OpenAI API provide usage information as part of chat completion chunk object in streaming scenario. It makes sense, because information like token usage can be calculated only when you receive a full response and not chunk. Most probably in streaming scenario you have to calculate tokens manually on your side. |
I managed to get it working using a third party nuget to calculate ChatHistory and the final output of the stream.👍
|
How did you manage to get the token count thru the nuget package and which package is it? |
when should we expect token usage for GetStreamingChatMessageContentsAsync? Which version of SK would it go into? Thanks |
Tiktoken nuget:
|
@dmm-l-mediehus - Thanks for the tip on using Tiktoken! it was indeed helpful.
And as I am getting streaming response, I am saving that to a string. Once all responses have been received, I am making use of Tiktoken to calculate prompt and completion tokens using something like the following:
|
Currently there's a convoluted way to get the token usage and executed prompt when executing a function. For example, here's how you can get the token usage:
It would be really useful if this information is surfaced in
FunctionResult
. Even if it is part ofMetadata
property, I think it is fine.Same thing for the prompt that was sent to the LLM as well.
The text was updated successfully, but these errors were encountered: