forked from phoenix/litellm-mirror
add linting
This commit is contained in:
parent
8ef47524bf
commit
15b1da9dc8
40 changed files with 3110 additions and 1709 deletions
|
@ -11,9 +11,7 @@ from threading import Thread
|
|||
from openai.error import Timeout
|
||||
|
||||
|
||||
def timeout(
|
||||
timeout_duration: float = None, exception_to_raise = Timeout
|
||||
):
|
||||
def timeout(timeout_duration: float = None, exception_to_raise=Timeout):
|
||||
"""
|
||||
Wraps a function to raise the specified exception if execution time
|
||||
is greater than the specified timeout.
|
||||
|
@ -44,7 +42,9 @@ def timeout(
|
|||
result = future.result(timeout=local_timeout_duration)
|
||||
except futures.TimeoutError:
|
||||
thread.stop_loop()
|
||||
raise exception_to_raise(f"A timeout error occurred. The function call took longer than {local_timeout_duration} second(s).")
|
||||
raise exception_to_raise(
|
||||
f"A timeout error occurred. The function call took longer than {local_timeout_duration} second(s)."
|
||||
)
|
||||
thread.stop_loop()
|
||||
return result
|
||||
|
||||
|
@ -59,7 +59,9 @@ def timeout(
|
|||
)
|
||||
return value
|
||||
except asyncio.TimeoutError:
|
||||
raise exception_to_raise(f"A timeout error occurred. The function call took longer than {local_timeout_duration} second(s).")
|
||||
raise exception_to_raise(
|
||||
f"A timeout error occurred. The function call took longer than {local_timeout_duration} second(s)."
|
||||
)
|
||||
|
||||
if iscoroutinefunction(func):
|
||||
return async_wrapper
|
||||
|
@ -80,4 +82,4 @@ class _LoopWrapper(Thread):
|
|||
def stop_loop(self):
|
||||
for task in asyncio.all_tasks(self.loop):
|
||||
task.cancel()
|
||||
self.loop.call_soon_threadsafe(self.loop.stop)
|
||||
self.loop.call_soon_threadsafe(self.loop.stop)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue