-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Print and store how many tokens were used in memory/logs #322
Comments
this was exactly what i was trying to decipher today. unfortunately the information online on OpenAI Usage retrieval is quite limited tried looking for some solutions that worked but on Langchain (i.e need some memory) def run_chain(k, max_tokens, model_name, docs, user_question): def extract_and_round_cost(cb):
this basically prints the token usage and calculates costs. output: Tokens Used: 560 not sure if this is what you are thinking about |
@yitron when and @AntonOsika I looked upon your suggestion, tiktoken a module by OpenAI is a fast BPE tokeniser for use with OpenAI's models and the below code will print the code and store the value in a file token_count_log.txt which we can further plot graphs for benchtesting the results. import tiktoken def run_chain(k, max_tokens, model_name, docs, user_question):
def extract_and_round_cost(cb):
def log_token_count(token_count): An example of the output in the log file and console : Callback Object: <Callback object at 0x7f8a12b65470> @AntonOsika would love to work on this issue, assign it to me |
@shubham-attri just fork the repo, make a change and submit a pr. that's the common way for open-source projects. :) If you're not working on it, I'd quickly do the pr. Let me know! |
Oops just saw this! Is this assigned ? If not I can work on it.. |
Hey, I now just went ahead an implemented it |
@yitron in open-source projects if an issue is not assigned, you can just do it. Don't wait for permission. ;) @shubham-attri @yitron Feel free to ping me if you have any questions on contributing to open source! |
Hey got it! Just thinking (and not verifying) if it's done haha sorry! |
* Implemented logging token usage Token usage is now tracked and logged into memory/logs/token_usage * Step names are now inferred from function name * Incorporated Anton's feedback - Made LogUsage a dataclass - For token logging, step name is now inferred via inspect module * Formatted (black/ruff) * Update gpt_engineer/ai.py Co-authored-by: Anton Osika <anton.osika@gmail.com> * formatting --------- Co-authored-by: Anton Osika <anton.osika@gmail.com>
Great job 🚀 |
…gineer-org#438) * Implemented logging token usage Token usage is now tracked and logged into memory/logs/token_usage * Step names are now inferred from function name * Incorporated Anton's feedback - Made LogUsage a dataclass - For token logging, step name is now inferred via inspect module * Formatted (black/ruff) * Update gpt_engineer/ai.py Co-authored-by: Anton Osika <anton.osika@gmail.com> * formatting --------- Co-authored-by: Anton Osika <anton.osika@gmail.com>
In this way, we can also store this to benchmark results.
A huge increase in tokens will not be worth a minor improvement in benchmark resultss.
The text was updated successfully, but these errors were encountered: