mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 10:44:24 +00:00
(feat) add async embeddings
This commit is contained in:
parent
34c75b8c0c
commit
6373f6bddd
2 changed files with 31 additions and 0 deletions
|
@ -1447,6 +1447,21 @@ def batch_completion_models_all_responses(*args, **kwargs):
|
|||
return responses
|
||||
|
||||
### EMBEDDING ENDPOINTS ####################
|
||||
|
||||
async def aembedding(*args, **kwargs):
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
# Use a partial function to pass your keyword arguments
|
||||
func = partial(embedding, *args, **kwargs)
|
||||
|
||||
# Add the context to the function
|
||||
ctx = contextvars.copy_context()
|
||||
func_with_context = partial(ctx.run, func)
|
||||
|
||||
# Call the synchronous function using run_in_executor
|
||||
response = await loop.run_in_executor(None, func_with_context)
|
||||
return response
|
||||
|
||||
@client
|
||||
@timeout( # type: ignore
|
||||
60
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue