Skip to content

Handle exception for token cost calculation #4474

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

Merged
merged 1 commit into from
Apr 8, 2025

Conversation

emerzon
Copy link
Contributor

@emerzon emerzon commented Apr 8, 2025

Description

The code for token cost calculation fails in some cases when using a LiteLLM proxy due to mismatch with the provider+model naming. For now, just handle this exception and assume cost 0 when that happens instead of breaking the flow - A more precise, LiteLLM proxy based cost calculation (relying in the /model/info) LiteLLM Proxy implementation will be needed for accurate cost tracking.

How Has This Been Tested?

Test enabling Contextual RAG LLM when a non-standard model name is used in the LLM connector (Ie. claude-3.5-haiku@20241022)

The code for token cost calculation fails when using a LiteLLM proxy due to mismatch with the provider naming. For now, just handle this exception and assume cost 0 when that happens instead of breaking the flow - A more precise, LiteLLM proxy based cost calculation (relying in the `/model/info`) LiteLLM Proxy method will be needed
@emerzon emerzon requested a review from a team as a code owner April 8, 2025 02:28
Copy link

vercel bot commented Apr 8, 2025

@emerzon is attempting to deploy a commit to the Danswer Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

The PR updates token cost calculation to handle exceptions due to LiteLLM proxy naming mismatches without breaking the flow.

  • Modified backend/onyx/llm/utils.py to catch exceptions in get_llm_contextual_cost and log detailed context.
  • Returns a fallback cost of 0 when an exception occurs, ensuring uninterrupted processing.
  • This temporary measure will later be replaced by a more precise cost calculation implementation.

💡 (5/5) You can turn off certain types of comments like style here!

1 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings | Greptile

@Weves Weves merged commit ba80191 into onyx-dot-app:main Apr 8, 2025
1 of 9 checks passed
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.

2 participants