mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 19:24:27 +00:00
fix(router.py): check if async response is coroutine
This commit is contained in:
parent
d9123ea2e8
commit
a753487d79
1 changed files with 3 additions and 2 deletions
|
@ -3,6 +3,7 @@ from typing import Dict, List, Optional, Union, Literal
|
||||||
import random, threading, time
|
import random, threading, time
|
||||||
import litellm, openai
|
import litellm, openai
|
||||||
import logging, asyncio
|
import logging, asyncio
|
||||||
|
import inspect
|
||||||
|
|
||||||
class Router:
|
class Router:
|
||||||
"""
|
"""
|
||||||
|
@ -154,7 +155,7 @@ class Router:
|
||||||
try:
|
try:
|
||||||
# if the function call is successful, no exception will be raised and we'll break out of the loop
|
# if the function call is successful, no exception will be raised and we'll break out of the loop
|
||||||
response = await original_function(*args, **kwargs)
|
response = await original_function(*args, **kwargs)
|
||||||
if isinstance(response, asyncio.coroutines.Coroutine): # async errors are often returned as coroutines
|
if inspect.iscoroutinefunction(response): # async errors are often returned as coroutines
|
||||||
response = await response
|
response = await response
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@ -234,7 +235,7 @@ class Router:
|
||||||
deployment = self.get_available_deployment(model=model, messages=messages)
|
deployment = self.get_available_deployment(model=model, messages=messages)
|
||||||
data = deployment["litellm_params"]
|
data = deployment["litellm_params"]
|
||||||
response = await litellm.acompletion(**{**data, "messages": messages, "caching": self.cache_responses, **kwargs})
|
response = await litellm.acompletion(**{**data, "messages": messages, "caching": self.cache_responses, **kwargs})
|
||||||
if isinstance(response, asyncio.coroutines.Coroutine): # async errors are often returned as coroutines
|
if inspect.iscoroutinefunction(response): # async errors are often returned as coroutines
|
||||||
response = await response
|
response = await response
|
||||||
return response
|
return response
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue