mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
adding an async completion function
This commit is contained in:
parent
16966e61b9
commit
f222ea31f7
3 changed files with 8 additions and 1 deletions
Binary file not shown.
Binary file not shown.
|
@ -7,6 +7,7 @@ import traceback
|
||||||
import litellm
|
import litellm
|
||||||
from litellm import client, logging, exception_type, timeout, success_callback, failure_callback
|
from litellm import client, logging, exception_type, timeout, success_callback, failure_callback
|
||||||
import random
|
import random
|
||||||
|
import asyncio
|
||||||
from tenacity import (
|
from tenacity import (
|
||||||
retry,
|
retry,
|
||||||
stop_after_attempt,
|
stop_after_attempt,
|
||||||
|
@ -69,7 +70,7 @@ def completion(
|
||||||
temperature=1, top_p=1, n=1, stream=False, stop=None, max_tokens=float('inf'),
|
temperature=1, top_p=1, n=1, stream=False, stop=None, max_tokens=float('inf'),
|
||||||
presence_penalty=0, frequency_penalty=0, logit_bias={}, user="",
|
presence_penalty=0, frequency_penalty=0, logit_bias={}, user="",
|
||||||
# Optional liteLLM function params
|
# Optional liteLLM function params
|
||||||
*, api_key=None, force_timeout=60, azure=False, logger_fn=None, verbose=False
|
*, return_async=False, api_key=None, force_timeout=60, azure=False, logger_fn=None, verbose=False
|
||||||
):
|
):
|
||||||
try:
|
try:
|
||||||
# check if user passed in any of the OpenAI optional params
|
# check if user passed in any of the OpenAI optional params
|
||||||
|
@ -254,6 +255,12 @@ def completion(
|
||||||
raise exception_type(model=model, original_exception=e)
|
raise exception_type(model=model, original_exception=e)
|
||||||
|
|
||||||
|
|
||||||
|
async def acompletion(*args, **kwargs):
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
|
# Call the synchronous function using run_in_executor()
|
||||||
|
return loop.run_in_executor(None, completion, *args, **kwargs)
|
||||||
|
|
||||||
### EMBEDDING ENDPOINTS ####################
|
### EMBEDDING ENDPOINTS ####################
|
||||||
@client
|
@client
|
||||||
@timeout(60) ## set timeouts, in case calls hang (e.g. Azure) - default is 60s, override with `force_timeout`
|
@timeout(60) ## set timeouts, in case calls hang (e.g. Azure) - default is 60s, override with `force_timeout`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue