Skip to content

Commit

Permalink
Merge pull request #691 from mc-marcocheng/router/aembedding
Browse files Browse the repository at this point in the history
Router aembedding
  • Loading branch information
ishaan-jaff authored Oct 25, 2023
2 parents 046e138 + bf98d48 commit bbec654
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
15 changes: 14 additions & 1 deletion litellm/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,20 @@ def embedding(self,
data["caching"] = self.cache_responses
# call via litellm.embedding()
return litellm.embedding(**{**data, **kwargs})


async def aembedding(self,
model: str,
input: Union[str, List],
is_async: Optional[bool] = True,
**kwargs) -> Union[List[float], None]:
# pick the one that is available (lowest TPM/RPM)
deployment = self.get_available_deployment(model=model, input=input)

data = deployment["litellm_params"]
data["input"] = input
data["caching"] = self.cache_responses
return await litellm.aembedding(**{**data, **kwargs})

def set_model_list(self, model_list: list):
self.model_list = model_list

Expand Down
26 changes: 26 additions & 0 deletions litellm/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,29 @@ async def get_response():
except Exception as e:
traceback.print_exc()
pytest.fail(f"Error occurred: {e}")


def test_aembedding_on_router():
try:
model_list = [
{
"model_name": "text-embedding-ada-002",
"litellm_params": {
"model": "text-embedding-ada-002",
},
"tpm": 100000,
"rpm": 10000,
},
]

async def embedding_call():
router = Router(model_list=model_list)
response = await router.aembedding(
model="text-embedding-ada-002",
input=["good morning from litellm", "this is another item"],
)
print(response)
asyncio.run(embedding_call())
except Exception as e:
traceback.print_exc()
pytest.fail(f"Error occurred: {e}")

0 comments on commit bbec654

Please sign in to comment.