Skip to content
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

feat: collect token usage #94

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mdjastrzebski
Copy link
Collaborator

Summary

Collect token usage during all types of LLMs requests.

image

Details

  1. Added usage field to BaseWorkflowState type, of the CompletionUsage type imported from OpenAI SDK.
  2. Modified all LLMs calls to also return usage stats

Alternatively

Alternatively instead of having a separate accumulator variable on state, it could be calculated from messeges if there were to hold it as well. There would also be a need to capture the orchestration usage (e.g. selectAgent) as these are not directly reflected in the messages.

Test plan

Tested manually on surprise_trip.ts example

Resolves #8

@grabbou
Copy link
Collaborator

grabbou commented Dec 11, 2024

Thanks for the PR! I've been looking into this and potentially thinking about the second approach

Alternatively instead of having a separate accumulator variable on state, it could be calculated from messeges if there were to hold it as well. There would also be a need to capture the orchestration usage (e.g. selectAgent) as these are not directly reflected in the messages.

There's pending rewrite of the internals to enable more customization, partially inspired by this PR. Once that is complete and the PR is up, we will revisit this one (likely tomorrow, given our ambitious plans)

@mdjastrzebski
Copy link
Collaborator Author

In order to handle non-message workflow steps, you could collect the results of processing steps in some thing like audit-log of all workflow actions and then calculate total tokens from there

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: usage info - related to #4
2 participants