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

fix: better anthropic cost logging #321

Merged
merged 1 commit into from
Dec 10, 2024

Conversation

ErikBjare
Copy link
Owner

@ErikBjare ErikBjare commented Dec 10, 2024

Also set a bunch of loglevels for libs higher, so now -v output is actually readable.

Important

Enhance logging in llm_anthropic.py to capture usage data and chunk types, and adjust logging levels in init.py.

  • Logging Enhancements in llm_anthropic.py:
    • Add logger.debug(response.usage) in chat() to log usage data.
    • Add logger.debug(chunk.message.usage) in stream() for message_start case.
    • Add logger.debug(chunk.usage) in stream() for message_delta case.
  • Logging Configuration in init.py:
    • Set anthropic logger level to INFO to reduce debug log spam.
    • Set httpcore logger level to WARNING.

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

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 d0c1c8b in 13 seconds

More details
  • Looked at 48 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. gptme/llm/llm_anthropic.py:97
  • Draft comment:
    Combine logging of chunk.type and chunk.usage into a single log entry for better readability and performance.
logger.info(f"Chunk type: {chunk.type}, Usage: {chunk.usage}")
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The logging of chunk.type and chunk.usage should be combined into a single log entry for better readability and performance.
2. gptme/llm/llm_anthropic.py:75
  • Draft comment:
    The import statement for anthropic.types.beta.prompt_caching is unnecessary here since it's already imported at the module level under TYPE_CHECKING.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The import statement for anthropic.types.beta.prompt_caching is unnecessary in the stream function since it is already imported at the module level under TYPE_CHECKING.

Workflow ID: wflow_Qev6fcPd4ztv9D4m


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

@codecov-commenter
Copy link

codecov-commenter commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.57%. Comparing base (65efc3e) to head (f074706).
Report is 1 commits behind head on master.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #321      +/-   ##
==========================================
+ Coverage   72.49%   72.57%   +0.07%     
==========================================
  Files          67       67              
  Lines        4912     4922      +10     
==========================================
+ Hits         3561     3572      +11     
+ Misses       1351     1350       -1     
Flag Coverage Δ
anthropic/claude-3-haiku-20240307 70.62% <100.00%> (+0.08%) ⬆️
openai/gpt-4o-mini 69.36% <25.00%> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

now -v output is actually readable
@ErikBjare ErikBjare force-pushed the dev/better-anthropic-cost-logging branch from d0c1c8b to f074706 Compare December 10, 2024 22:52
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! Incremental review on f074706 in 15 seconds

More details
  • Looked at 64 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. gptme/llm/llm_anthropic.py:68
  • Draft comment:
    The logging level for response.usage should be info instead of debug to match the PR description.
  • Reason this comment was not posted:
    Comment did not seem useful.
2. gptme/llm/llm_anthropic.py:127
  • Draft comment:
    The logging level for chunk.message.usage should be info instead of debug to match the PR description. This also applies to chunk.usage on line 130.
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_Cr8cOkrTD24ehuxo


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

@ErikBjare ErikBjare merged commit 283e8b0 into master Dec 10, 2024
7 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