mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
anthropic: Allow kwargs to pass through when counting tokens (#31082)
- **Description:** `ChatAnthropic.get_num_tokens_from_messages` does not currently receive `kwargs` and pass those on to `self._client.beta.messages.count_tokens`. This is a problem if you need to pass specific options to `count_tokens`, such as the `thinking` option. This PR fixes that. - **Issue:** N/A - **Dependencies:** None - **Twitter handle:** @bengladwell Co-authored-by: ccurme <chester.curme@gmail.com>
This commit is contained in:
@@ -1588,6 +1588,7 @@ class ChatAnthropic(BaseChatModel):
|
||||
tools: Optional[
|
||||
Sequence[Union[dict[str, Any], type, Callable, BaseTool]]
|
||||
] = None,
|
||||
**kwargs: Any,
|
||||
) -> int:
|
||||
"""Count tokens in a sequence of input messages.
|
||||
|
||||
@@ -1647,7 +1648,6 @@ class ChatAnthropic(BaseChatModel):
|
||||
https://docs.anthropic.com/en/docs/build-with-claude/token-counting
|
||||
"""
|
||||
formatted_system, formatted_messages = _format_messages(messages)
|
||||
kwargs: dict[str, Any] = {}
|
||||
if isinstance(formatted_system, str):
|
||||
kwargs["system"] = formatted_system
|
||||
if tools:
|
||||
|
||||
Reference in New Issue
Block a user