Skip to content

Introduce .value_tokens() provider method#194

Merged
cpsievert merged 7 commits into
mainfrom
feat/value-tokens
Oct 29, 2025
Merged

Introduce .value_tokens() provider method#194
cpsievert merged 7 commits into
mainfrom
feat/value-tokens

Conversation

@cpsievert

Copy link
Copy Markdown
Collaborator

In anticipation of #192.

TODO: Also add a cost property to Turn, similar to tidyverse/ellmer#812?

@cpsievert cpsievert force-pushed the feat/value-tokens branch 3 times, most recently from 7189238 to a8b97ef Compare October 29, 2025 15:47
@cpsievert cpsievert requested a review from Copilot October 29, 2025 16:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 the Provider base class
  • Implemented .value_tokens() in all provider classes (OpenAI, Anthropic, Google, Snowflake)
  • Centralized token logging and Turn attachment in Chat._submit_turns() and Chat._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.

Comment thread chatlas/_provider_openai.py Outdated
Comment thread chatlas/_provider_google.py
Comment thread chatlas/_provider_google.py
@cpsievert cpsievert marked this pull request as ready for review October 29, 2025 16:42
@cpsievert cpsievert merged commit 2939edd into main Oct 29, 2025
5 of 14 checks passed
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()
@cpsievert cpsievert deleted the feat/value-tokens branch November 6, 2025 15:33
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