Skip to content

TypeError using Ollama embedding models #7451

@tsmdt

Description

@tsmdt

After upgrading from 1.54.1 to 1.56.3 I am getting a TypeError: object dict can't be used in 'await' expression whenever I try to embed strings using Ollama. I tested OpenAI (text-embedding-3-small) which works fine, but the following example code errors out with Ollama:

import litellm

text = 'Research Data Charta'

response = litellm.embedding(input=text, model='ollama/nomic-embed-text:latest')

print(response)

Error:

Traceback (most recent call last):
  File "/Users/thomas/Code/projects/dygest/venv_dygest/lib/python3.12/site-packages/litellm/main.py", line 3670, in embedding
    response = ollama_embeddings_fn(  # type: ignore
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thomas/Code/projects/dygest/venv_dygest/lib/python3.12/site-packages/litellm/llms/ollama/completion/handler.py", line 92, in ollama_embeddings
    return asyncio.run(
           ^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 686, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/thomas/Code/projects/dygest/venv_dygest/lib/python3.12/site-packages/litellm/llms/ollama/completion/handler.py", line 55, in ollama_aembeddings
    response_json = await response.json()
                    ^^^^^^^^^^^^^^^^^^^^^
TypeError: object dict can't be used in 'await' expression

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/thomas/Code/projects/dygest/embedtest.py", line 5, in <module>
    response = litellm.embedding(input=text, model='ollama/nomic-embed-text:latest')
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thomas/Code/projects/dygest/venv_dygest/lib/python3.12/site-packages/litellm/utils.py", line 993, in wrapper
    raise e
  File "/Users/thomas/Code/projects/dygest/venv_dygest/lib/python3.12/site-packages/litellm/utils.py", line 874, in wrapper
    result = original_function(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thomas/Code/projects/dygest/venv_dygest/lib/python3.12/site-packages/litellm/main.py", line 3829, in embedding
    raise exception_type(
          ^^^^^^^^^^^^^^^
  File "/Users/thomas/Code/projects/dygest/venv_dygest/lib/python3.12/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2190, in exception_type
    raise e
  File "/Users/thomas/Code/projects/dygest/venv_dygest/lib/python3.12/site-packages/litellm/litellm_core_utils/exception_mapping_utils.py", line 2166, in exception_type
    raise APIConnectionError(
litellm.exceptions.APIConnectionError: litellm.APIConnectionError: object dict can't be used in 'await' expression
Traceback (most recent call last):
  File "/Users/thomas/Code/projects/dygest/venv_dygest/lib/python3.12/site-packages/litellm/main.py", line 3670, in embedding
    response = ollama_embeddings_fn(  # type: ignore
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/thomas/Code/projects/dygest/venv_dygest/lib/python3.12/site-packages/litellm/llms/ollama/completion/handler.py", line 92, in ollama_embeddings
    return asyncio.run(
           ^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.8/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/base_events.py", line 686, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/thomas/Code/projects/dygest/venv_dygest/lib/python3.12/site-packages/litellm/llms/ollama/completion/handler.py", line 55, in ollama_aembeddings
    response_json = await response.json()
                    ^^^^^^^^^^^^^^^^^^^^^
TypeError: object dict can't be used in 'await' expression

Any help would be appreciated, thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions