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

save token counts #1762

Merged

Conversation

emrgnt-cmplxty
Copy link
Contributor

@emrgnt-cmplxty emrgnt-cmplxty commented Jan 7, 2025

Important

Add token counting for messages and save token metadata to the database, with tiktoken dependency for encoding.

  • Token Counting:
    • Add tokens_count_for_message() and num_tokens_from_messages() in retrieval_service.py to calculate token counts for messages.
  • Database Updates:
    • Modify agent() in retrieval_service.py to save input_tokens and output_tokens metadata when adding messages to the database.
  • Dependencies:
    • Add tiktoken dependency in pyproject.toml for token encoding.

This description was created by Ellipsis for 02ac34e. It will automatically update as commits are pushed.

@emrgnt-cmplxty emrgnt-cmplxty marked this pull request as ready for review January 7, 2025 00:55
@emrgnt-cmplxty emrgnt-cmplxty merged commit 1689f20 into feature/configurable-api-base Jan 7, 2025
1 check passed
Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to 02ac34e in 1 minute and 32 seconds

More details
  • Looked at 140 lines of code in 2 files
  • Skipped 1 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. py/core/main/services/retrieval_service.py:36
  • Draft comment:
    Consider making tokens_per_message configurable or document why 3 tokens are added for each message and reply. This hardcoded value might not be accurate for all models or message types.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The function tokens_count_for_message and num_tokens_from_messages are calculating token counts, but there is a hardcoded value of 3 tokens added for each message and reply. This might not be accurate for all models or message types.
2. py/core/main/services/retrieval_service.py:56
  • Draft comment:
    Replace print with logger.warning for better logging practices.
logger.warning("Warning: model not found. Using cl100k_base encoding.")
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The print statement in num_tokens_from_messages function is not ideal for logging warnings. It should use the logger for consistency and better control over log levels.

Workflow ID: wflow_XVoFD3adowaM6ew2


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

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.

1 participant