BerriAI / litellm

Python SDK, Proxy Server (LLM Gateway) to call 100+ LLM APIs in OpenAI format - [Bedrock, Azure, OpenAI, VertexAI, Cohere, Anthropic, Sagemaker, HuggingFace, Replicate, Groq]
https://docs.litellm.ai/docs/
Other
12.65k stars 1.47k forks source link

[Bug]: error when calling IBM watsonx embedding model #4538

Closed polubarev closed 3 months ago

polubarev commented 3 months ago

What happened?

When trying to use embedding model from IBM watsonx, next error occured:

Reference code:

from litellm import embedding
import os

os.environ["WATSONX_URL"] = "hidden"
os.environ["WATSONX_APIKEY"] = "hidden"
os.environ["WATSONX_PROJECT_ID"] = "hidden"

response = embedding('watsonx/ibm/slate-30m-english-rtrvr', input=["What is the capital of France?"])
print(response)

Error:

Traceback (most recent call last):
  File "C:\Users\025200756\Work\Projects\Coralogix\litellm\aembeddings.py", line 9, in <module>
    response = embedding('watsonx/ibm/slate-30m-english-rtrvr', input=["What is the capital of France?"])
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\11\.conda\envs\project\Lib\site-packages\litellm\utils.py", line 1001, in wrapper
    raise e
  File "C:\Users\11\.conda\envs\project\Lib\site-packages\litellm\utils.py", line 947, in wrapper
    result._response_ms = (
    ^^^^^^^^^^^^^^^^^^^
AttributeError: 'coroutine' object has no attribute '_response_ms'
sys:1: RuntimeWarning: coroutine 'IBMWatsonXAI.embedding.<locals>.handle_aembedding' was never awaited

After investigation it was found that in the litellm/llms/watsonx.py source code there is a bug. at lines 619-623.

       try:
            if aembedding is True:
                return handle_embedding(req_params)
            else:
                return handle_aembedding(req_params)

The function handle_aembedding should be used when aembedding is set to True, but instead, handle_embedding is called.

Correct code:

       try:
            if aembedding is True:
                return handle_aembedding(req_params)
            else:
                return handle_embedding(req_params)

Relevant log output

No response

Twitter / LinkedIn details

No response

igoratibm commented 3 months ago

@simonsanvil

simonsanvil commented 3 months ago

Thank you for adding me @polubarev. I'll submit a PR today to fix this