Back to Llama Index

Ollama Llama Pack Example

docs/examples/llama_hub/llama_pack_ollama.ipynb

0.14.211.5 KB
Original Source

Ollama Llama Pack Example

Setup Data

python
!wget "https://www.dropbox.com/s/f6bmb19xdg0xedm/paul_graham_essay.txt?dl=1" -O paul_graham_essay.txt
python
from llama_index.core import SimpleDirectoryReader

# load in some sample data
reader = SimpleDirectoryReader(input_files=["paul_graham_essay.txt"])
documents = reader.load_data()

Start Ollama

Make sure you run ollama run llama2 in a terminal.

python
# !ollama run llama2

Download and Initialize Pack

We use download_llama_pack to download the pack class, and then we initialize it with documents.

Every pack will have different initialization parameters. You can find more about the initialization parameters for each pack through its README (also on LlamaHub).

NOTE: You must also specify an output directory. In this case the pack is downloaded to voyage_pack. This allows you to customize and make changes to the file, and import it later!

python
from llama_index.core.llama_pack import download_llama_pack

# download and install dependencies
OllamaQueryEnginePack = download_llama_pack(
    "OllamaQueryEnginePack", "./ollama_pack"
)
python
# You can use any llama-hub loader to get documents!
ollama_pack = OllamaQueryEnginePack(model="llama2", documents=documents)
python
response = ollama_pack.run("What did the author do growing up?")
python
print(str(response))