mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-12 03:48:56 +00:00
refactor(anthropic): restructure count_tokens placement casts for the type-discipline gate
This commit is contained in:
parent
96201a2ec3
commit
4556a2a654
1 changed files with 8 additions and 7 deletions
|
|
@ -126,14 +126,12 @@ class AnthropicCountTokensConfig:
|
|||
# path places it, so count_tokens never sends a role the API rejects (the
|
||||
# chat path's placement exists because the API answers 400 there). A
|
||||
# malformed ``system`` is the provider's to judge: nothing is rearranged.
|
||||
if system is None or isinstance(system, (str, list)):
|
||||
counted_messages = cast( # cast-ok: placement returns the same provider message dicts it was given
|
||||
placed_messages: Final = (
|
||||
cast( # cast-ok: placement returns the same provider message dicts it was given
|
||||
tuple[Mapping[str, JsonValue], ...],
|
||||
place_mid_conversation_system(
|
||||
cast(
|
||||
tuple[
|
||||
AllMessageValues, ...
|
||||
], # cast-ok: provider messages arrive as the typed chat message dicts
|
||||
cast( # cast-ok: provider messages arrive as the typed chat message dicts
|
||||
tuple[AllMessageValues, ...],
|
||||
counted_messages,
|
||||
),
|
||||
supports_mid_conversation_system=supports_mid_conversation_system(
|
||||
|
|
@ -141,12 +139,15 @@ class AnthropicCountTokensConfig:
|
|||
),
|
||||
),
|
||||
)
|
||||
if system is None or isinstance(system, (str, list))
|
||||
else counted_messages
|
||||
)
|
||||
return _COUNT_REQUEST.validate_python(
|
||||
MappingProxyType(
|
||||
{
|
||||
"model": model,
|
||||
"messages": [
|
||||
{**message, "content": _count_content(message["content"])} for message in counted_messages
|
||||
{**message, "content": _count_content(message["content"])} for message in placed_messages
|
||||
],
|
||||
**MappingProxyType(
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue