mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-10 03:28:53 +00:00
fix(interactions): stop the cost poll loop instead of spinning on a non-positive interval
This commit is contained in:
parent
94caab7302
commit
6befeb8a17
2 changed files with 14 additions and 1 deletions
|
|
@ -74,7 +74,7 @@ async def _fetch_interaction(context: BackgroundInteractionPollContext) -> Inter
|
|||
def _poll_intervals(initial: float, maximum: float, timeout: float) -> Iterator[float]:
|
||||
elapsed = 0.0
|
||||
interval = initial
|
||||
while elapsed + interval <= timeout:
|
||||
while interval > 0 and elapsed + interval <= timeout:
|
||||
yield interval
|
||||
elapsed += interval
|
||||
interval = min(interval * 2, maximum)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import asyncio
|
||||
import time
|
||||
from itertools import islice
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
|
||||
from litellm.interactions.background_cost_polling import (
|
||||
_SETTLED_KEY,
|
||||
_poll_intervals,
|
||||
BackgroundInteractionPollContext,
|
||||
maybe_schedule_background_interaction_cost_polling,
|
||||
maybe_settle_background_interaction_before_delete,
|
||||
|
|
@ -92,6 +94,17 @@ def _fetch_sequence(*responses):
|
|||
return fetch, calls
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"initial, maximum",
|
||||
[(0.0, 0.002), (0.001, 0.0), (-1.0, 0.002), (0.0, 0.0)],
|
||||
)
|
||||
def test_poll_intervals_stops_instead_of_looping_on_a_non_positive_interval(initial, maximum):
|
||||
intervals = list(islice(_poll_intervals(initial=initial, maximum=maximum, timeout=3600.0), 10))
|
||||
|
||||
assert len(intervals) < 10
|
||||
assert all(interval > 0 for interval in intervals)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_poller_bills_once_when_interaction_completes():
|
||||
logging_obj = _logging_obj()
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue