Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pydantic_ai_slim/pydantic_ai/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,13 @@ def has_token_limits(self) -> bool:
This is useful because if we have token limits, we need to check them after receiving each streamed message.
If there are no limits, we can skip that processing in the streaming response iterator.
"""
return any(
limit is not None
for limit in (self.request_tokens_limit, self.response_tokens_limit, self.total_tokens_limit)
)
if self.request_tokens_limit is not None:
return True
if self.response_tokens_limit is not None:
return True
if self.total_tokens_limit is not None:
return True
return False

def check_before_request(self, usage: Usage) -> None:
"""Raises a `UsageLimitExceeded` exception if the next request would exceed the request_limit."""
Expand Down
Loading