forked from phoenix/litellm-mirror
fix(proxy_server.py): fix spend log update
This commit is contained in:
parent
8fefe625d9
commit
f588bff69b
3 changed files with 31 additions and 5 deletions
|
@ -329,6 +329,16 @@ async def test_key_info_spend_values():
|
|||
- make completion call
|
||||
- assert cost is expected value
|
||||
"""
|
||||
|
||||
async def retry_request(func, *args, _max_attempts=5, **kwargs):
|
||||
for attempt in range(_max_attempts):
|
||||
try:
|
||||
return await func(*args, **kwargs)
|
||||
except aiohttp.client_exceptions.ClientOSError as e:
|
||||
if attempt + 1 == _max_attempts:
|
||||
raise # re-raise the last ClientOSError if all attempts failed
|
||||
print(f"Attempt {attempt+1} failed, retrying...")
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
## Test Spend Update ##
|
||||
# completion
|
||||
|
@ -336,7 +346,9 @@ async def test_key_info_spend_values():
|
|||
key = key_gen["key"]
|
||||
response = await chat_completion(session=session, key=key)
|
||||
await asyncio.sleep(5)
|
||||
spend_logs = await get_spend_logs(session=session, request_id=response["id"])
|
||||
spend_logs = await retry_request(
|
||||
get_spend_logs, session=session, request_id=response["id"]
|
||||
)
|
||||
print(f"spend_logs: {spend_logs}")
|
||||
completion_tokens = spend_logs[0]["completion_tokens"]
|
||||
prompt_tokens = spend_logs[0]["prompt_tokens"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue