Introduce .value_tokens() provider method#194
Merged
Conversation
7189238 to
a8b97ef
Compare
a8b97ef to
d8e3ca9
Compare
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a new .value_tokens() method to the Provider interface that extracts token usage information from API completions. This refactoring moves token logging and attachment logic from individual provider implementations into the Chat class, standardizing token handling across all providers.
Key changes:
- Added abstract
.value_tokens()method to theProviderbase class - Implemented
.value_tokens()in all provider classes (OpenAI, Anthropic, Google, Snowflake) - Centralized token logging and Turn attachment in
Chat._submit_turns()andChat._submit_turns_async()
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| chatlas/_provider.py | Added abstract .value_tokens() method signature to Provider interface |
| chatlas/_provider_openai.py | Implemented .value_tokens() extracting token counts from OpenAI/Groq completions; removed token logic from ._as_turn() |
| chatlas/_provider_anthropic.py | Implemented .value_tokens() for Anthropic with cache read tracking; removed token logic from ._as_turn() |
| chatlas/_provider_google.py | Implemented .value_tokens() for Google with cached content handling; removed token logic from ._as_turn() |
| chatlas/_provider_snowflake.py | Implemented .value_tokens() for Snowflake; removed token logic from ._as_turn() |
| chatlas/_chat.py | Added centralized token extraction and logging after turn completion in both sync and async paths |
| CHANGELOG.md | Documented the new .value_tokens() requirement for Provider implementations |
| tests/test_inspect.py | Commented out integration tests (unrelated to main changes) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
cpsievert
added a commit
that referenced
this pull request
Oct 29, 2025
cpsievert
added a commit
that referenced
this pull request
Oct 29, 2025
* fix: workarounds for recent Anthropic type changes * Follow up to #194: fix google's value_turn()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In anticipation of #192.
TODO: Also add a
costproperty toTurn, similar to tidyverse/ellmer#812?