mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 02:34:29 +00:00
Merge 7a4d25c45a
into b82af5b826
This commit is contained in:
commit
eafcfad35b
1 changed files with 11 additions and 6 deletions
|
@ -24,6 +24,7 @@ from copy import deepcopy
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
|
Awaitable,
|
||||||
Callable,
|
Callable,
|
||||||
Coroutine,
|
Coroutine,
|
||||||
Dict,
|
Dict,
|
||||||
|
@ -461,19 +462,23 @@ async def acompletion(
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Use a partial function to pass your keyword arguments
|
# Use a partial function to pass your keyword arguments
|
||||||
func = partial(completion, **completion_kwargs, **kwargs)
|
# func = partial(completion, **completion_kwargs, **kwargs)
|
||||||
|
|
||||||
# Add the context to the function
|
# # Add the context to the function
|
||||||
ctx = contextvars.copy_context()
|
# ctx = contextvars.copy_context()
|
||||||
func_with_context = partial(ctx.run, func)
|
# func_with_context = partial(ctx.run, func)
|
||||||
|
|
||||||
init_response = await loop.run_in_executor(None, func_with_context)
|
init_response = await cast(
|
||||||
|
Awaitable[Union[dict, ModelResponse, CustomStreamWrapper]],
|
||||||
|
completion(**completion_kwargs, **kwargs),
|
||||||
|
)
|
||||||
if isinstance(init_response, dict) or isinstance(
|
if isinstance(init_response, dict) or isinstance(
|
||||||
init_response, ModelResponse
|
init_response, ModelResponse
|
||||||
): ## CACHING SCENARIO
|
): ## CACHING SCENARIO
|
||||||
if isinstance(init_response, dict):
|
if isinstance(init_response, dict):
|
||||||
response = ModelResponse(**init_response)
|
response = ModelResponse(**init_response)
|
||||||
response = init_response
|
else:
|
||||||
|
response = init_response
|
||||||
elif asyncio.iscoroutine(init_response):
|
elif asyncio.iscoroutine(init_response):
|
||||||
response = await init_response
|
response = await init_response
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue