diff --git a/litellm/__pycache__/__init__.cpython-311.pyc b/litellm/__pycache__/__init__.cpython-311.pyc index 72f69328e..8a3e54fa1 100644 Binary files a/litellm/__pycache__/__init__.cpython-311.pyc and b/litellm/__pycache__/__init__.cpython-311.pyc differ diff --git a/litellm/__pycache__/main.cpython-311.pyc b/litellm/__pycache__/main.cpython-311.pyc index e6d09b6c9..81ac35601 100644 Binary files a/litellm/__pycache__/main.cpython-311.pyc and b/litellm/__pycache__/main.cpython-311.pyc differ diff --git a/litellm/main.py b/litellm/main.py index 08dd1ac09..ee68d00aa 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -2,6 +2,7 @@ import os, openai, cohere, replicate, sys from typing import Any from anthropic import Anthropic, HUMAN_PROMPT, AI_PROMPT import traceback +from functools import partial import dotenv import traceback import litellm @@ -261,8 +262,11 @@ def completion( 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) + # Use a partial function to pass your keyword arguments + func = partial(completion, *args, **kwargs) + + # Call the synchronous function using run_in_executor + return await loop.run_in_executor(None, func) ### EMBEDDING ENDPOINTS #################### @client diff --git a/litellm/tests/test_async_fn.py b/litellm/tests/test_async_fn.py new file mode 100644 index 000000000..b0925c4b5 --- /dev/null +++ b/litellm/tests/test_async_fn.py @@ -0,0 +1,21 @@ +#### What this tests #### +# This tests the the acompletion function + +import sys, os +import pytest +import traceback +import asyncio +sys.path.insert(0, os.path.abspath('../..')) # Adds the parent directory to the system path +from litellm import acompletion + +async def test_get_response(): + user_message = "Hello, how are you?" + messages = [{ "content": user_message,"role": "user"}] + try: + response = await acompletion(model="gpt-3.5-turbo", messages=messages) + except Exception as e: + pytest.fail(f"error occurred: {e}") + return response + +response = asyncio.run(test_get_response()) +print(response) \ No newline at end of file diff --git a/setup.py b/setup.py index f3b595ad8..47c8d82db 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name='litellm', - version='0.1.227', + version='0.1.228', description='Library to easily interface with LLM API providers', author='BerriAI', packages=[