ImportError: cannot import name 'Ollama' from 'llama_index.llms' (unknown location)

2k Views Asked by At

Getting error while importing Ollama from 'llama_index.llms' in Linux OS.


from llama_index.llms import Ollama
response = llm.complete(f"What is code?")
print(response)

I installed Ollama from, curl -fsSL https://ollama.com/install.sh | sh Also Installed , pip3 install llama-index qdrant_client torch transformers Its installed successfully.

On running , I am getting -

ImportError: cannot import name 'Ollama' from 'llama_index.llms' (unknown location)

3

There are 3 best solutions below

0
On

I have the same issue but from https://docs.llamaindex.ai/en/stable/understanding/using_llms/using_llms.html, the import should be:

from llama_index.llms.ollama import Ollama
from llama_index.core import Settings

Settings.llm = Ollama(model="llama2", request_timeout=60.0)

Still, it doesn't work for me and I suspect there is specific module to install but I don't know which one...

EDIT: found!!! You have to install llama-index-llms-ollama

2
On

You are finding the ollama in the wrong place. Instead try using the ollama-python

pip install ollama

Follow the below link of the github and you will find the appropriate documentation for utilizing ollama :

https://github.com/ollama/ollama-python

0
On

Install the below in virtual environment pip install llama-index qdrant_client torch transformers pip install llama-index-llms-ollama

Sample code :

# Just runs .complete to make sure the LLM is listening
from llama_index.llms.ollama import Ollama
from llama_index.core import Settings


llm = Ollama(model="mistral")

response = llm.complete("Who is Laurie Voss? write in 10 words")
print(response)