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

Use LLM APIs responses in token counting #5604

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from
Draft

Use LLM APIs responses in token counting #5604

wants to merge 27 commits into from

Conversation

enyst
Copy link
Collaborator

@enyst enyst commented Dec 14, 2024

End-user friendly description of the problem this fixes or functionality that this introduces

  • Include this change in the Release Notes. If checked, you must provide an end-user friendly description for your change below

Give a summary of what the PR does, explaining any non-trivial design decisions

Follow-up on #5550

Litellm has token data for certain LLMs. We can use it if it's available and more accurate/appropriate than its token counting with tiktoken.


Link of any specific issues this addresses
Fix #2947


To run this PR locally, use the following command:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:5ccb369-nikolaik   --name openhands-app-5ccb369   docker.all-hands.dev/all-hands-ai/openhands:5ccb369

@enyst enyst marked this pull request as draft December 14, 2024 20:25
openhands/llm/llm.py Outdated Show resolved Hide resolved
@enyst
Copy link
Collaborator Author

enyst commented Dec 15, 2024

@openhands-agent Read the diff of this PR, PR 5604. And add unit tests for the functionality we change or introduce.

Please make sure to explore the unit tests a bit to find if we already have test files appropriate for these tests, if not make a new one.

@All-Hands-AI All-Hands-AI deleted a comment from openhands-agent Dec 15, 2024
@enyst enyst added the lint-fix label Dec 15, 2024
* Replace prompt_tokens, completion_tokens, total_tokens fields with a single usage field
* Add properties to maintain backward compatibility
* Update tests to verify Usage object is stored and properties work
* Update LLM.get_token_count() to use usage.total_tokens
* Keep Usage-based token counting for Message objects
* Add support for dict messages from main
* Add custom tokenizer support from main
* Improve error logging from main
* Add new tests from main
@enyst enyst added lint-fix and removed lint-fix labels Dec 15, 2024
@enyst enyst self-assigned this Dec 15, 2024
* Add back the initialization of self.tokenizer that was lost in merge
* This is needed for custom tokenizer support in token counting
* Add back the import that was lost in merge
* This import is needed for custom tokenizer initialization
@enyst enyst added lint-fix and removed lint-fix labels Dec 15, 2024
* Add explicit type check for Message in token counting loop
* This fixes mypy errors about accessing .usage on dict
* Add back the logger mock that was lost in merge
* This is needed for token counting error handling tests
@enyst enyst changed the title Make use of litellm 'Usage' data for token counting Use LLM APIs responses in token counting Dec 17, 2024
@enyst

This comment was marked as outdated.

@openhands-agent

This comment was marked as outdated.

@openhands-agent
Copy link
Contributor

Status Summary:

UNRESOLVED ISSUES:

  • Main task of merging branches via GitHub API has not been addressed
  • Merge conflicts remain unresolved
  • Agent provided irrelevant response about code changes instead of handling requested merge operations

NEXT STEPS NEEDED:

  1. Use GitHub API to pull main branch into PR branch
  2. Resolve any resulting merge conflicts
  3. Confirm completion of merge operations

Overall Assessment: The original issue remains entirely unresolved as the agent did not perform any of the requested merge-related tasks and instead went off-topic with code analysis.

@enyst

This comment was marked as outdated.

@openhands-agent

This comment was marked as outdated.

@openhands-agent
Copy link
Contributor

OVERVIEW:
The changes successfully resolved all merge conflicts by:

  • Pulling latest main branch
  • Resolving conflicts in multiple files while preserving key functionality
  • Committing the resolved changes

STATUS: ✅ FULLY RESOLVED

  • All merge conflicts have been addressed
  • Changes are now in a mergeable state
  • No remaining issues identified

NEXT STEPS:

  • Maintainer review of specific conflict resolutions
  • PR can proceed with merge process once approved

@All-Hands-AI All-Hands-AI deleted a comment from openhands-agent Jan 21, 2025
@All-Hands-AI All-Hands-AI deleted a comment from openhands-agent Jan 21, 2025
@All-Hands-AI All-Hands-AI deleted a comment from openhands-agent Jan 21, 2025
@All-Hands-AI All-Hands-AI deleted a comment from openhands-agent Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feat: make use of litellm's response "usage" data
2 participants