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: make use of litellm's response "usage" data #2947

Open
tobitege opened this issue Jul 15, 2024 · 6 comments · May be fixed by #5604
Open

Feat: make use of litellm's response "usage" data #2947

tobitege opened this issue Jul 15, 2024 · 6 comments · May be fixed by #5604
Assignees
Labels
enhancement New feature or request fix-me Attempt to fix this issue with OpenHands

Comments

@tobitege
Copy link
Collaborator

tobitege commented Jul 15, 2024

What problem or use case are you trying to solve?

TASK

We want to enhance our get_token_count() implementation in llm.py, to take advantage of the token counts we are provided from our dependencies, if available, and only fallback to count them if they are not already available.

Read the llm.py file. It uses the litellm library, and you can find some code that uses the Usage object from litellm, too.

This usage data, when available, provides live token counts. It will be available for some LLMs, and it will not be available for others.

If these values could be stored and/or attached to the corresponding messages, these values could be calculated and returned in get_token_count() in llm.py and used to live-compute the token counts.

Read also codeact_agent.py file, to see how the LLM is used, and message.py to understand the messages. Read event.py, there will be multiple files with this name, that's okay, read them all, to see Events.

IMPORTANT:

  • the Message objects are computed on the fly at each step
  • Messages get their content from Event objects
  • it is acceptable to add an event_id attribute to a Message, to link it to the underlying Event.
  • it's NOT acceptable to store the event_id_to_tokens or message_to_tokens in the agent. Use message.py class. Or use llm.py, if it's not too crowded. Your choice.

First, read and review the files you need to understand how we can do this.

Then, decide on a solution, and do it.

Unit tests are required.

/TASK

ORIGINAL MESSAGE

The usage data, if filled, provides live token counts. It will work for some LLMs, and it will not be available for others.

If these values could be stored and/or attached to the messages in the codeact_agent.py accordingly, these values could be calculated and returned in get_token_count() in llm.py.

Then this could help a running memory condenser in calculations?

ModelResponse(
    id='chatcmpl-47df6b79-cb8d-4f07-920a-8c5551ea7ee4',
    choices=[
        Choices(
            finish_reason='stop',
            index=0,
            message=Message(
                content='{\n  "action": "run",\n  "args": {\n    "command": "ls"\n  }\n}\n',
                role='assistant',
                tool_calls=None,
                function_call=None
            )
        )
    ],
    created=1721067905,
    model='anthropic/claude-3.5-sonnet:beta',
    object='chat.completion',
    system_fingerprint=None,
    usage=Usage(
        prompt_tokens=10,
        completion_tokens=20,
        total_tokens=30
    )
)
@tobitege tobitege added the enhancement New feature or request label Jul 15, 2024
Copy link
Contributor

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale Inactive for 30 days label Aug 17, 2024
@enyst enyst removed the Stale Inactive for 30 days label Aug 17, 2024
@enyst enyst self-assigned this Aug 17, 2024
Copy link
Contributor

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale Inactive for 30 days label Sep 19, 2024
@enyst enyst removed the Stale Inactive for 30 days label Sep 19, 2024
Copy link
Contributor

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale Inactive for 30 days label Oct 20, 2024
@enyst enyst removed the Stale Inactive for 30 days label Oct 20, 2024
Copy link
Contributor

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale Inactive for 30 days label Nov 25, 2024
@enyst enyst added fix-me Attempt to fix this issue with OpenHands and removed Stale Inactive for 30 days labels Nov 25, 2024
Copy link
Contributor

OpenHands started fixing the issue! You can monitor the progress here.

Copy link
Contributor

An attempt was made to automatically fix this issue, but it was unsuccessful. A branch named 'openhands-fix-issue-2947' has been created with the attempted changes. You can view the branch here. Manual intervention may be required.

@enyst enyst linked a pull request Dec 14, 2024 that will close this issue
1 task
enyst pushed a commit to enyst/playground that referenced this issue Dec 15, 2024
enyst pushed a commit to enyst/playground that referenced this issue Dec 15, 2024
enyst pushed a commit to enyst/playground that referenced this issue Dec 15, 2024
enyst pushed a commit to enyst/playground that referenced this issue Dec 15, 2024
enyst pushed a commit to enyst/playground that referenced this issue Dec 15, 2024
enyst pushed a commit to enyst/playground that referenced this issue Dec 15, 2024
enyst pushed a commit to enyst/playground that referenced this issue Dec 15, 2024
enyst pushed a commit to enyst/playground that referenced this issue Dec 15, 2024
…make use of litellm's response "usage" data"

This reverts commit d317a3e.
enyst pushed a commit to enyst/playground that referenced this issue Dec 15, 2024
enyst pushed a commit to enyst/playground that referenced this issue Dec 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fix-me Attempt to fix this issue with OpenHands
Projects
None yet
2 participants