From bc2aed9510cfe396056ae05397b7779921beab5d Mon Sep 17 00:00:00 2001 From: Alexander Schaber Date: Sat, 29 Jun 2024 01:48:04 +0200 Subject: [PATCH 1/2] refactor(examples/llamaindex_ollama): add use of env vars for configuration --- .../rag/llamaindex_ollama_pipeline.py | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/examples/pipelines/rag/llamaindex_ollama_pipeline.py b/examples/pipelines/rag/llamaindex_ollama_pipeline.py index efafe67..ef588e1 100644 --- a/examples/pipelines/rag/llamaindex_ollama_pipeline.py +++ b/examples/pipelines/rag/llamaindex_ollama_pipeline.py @@ -10,23 +10,43 @@ from typing import List, Union, Generator, Iterator from schemas import OpenAIChatMessage +import os + +from pydantic import BaseModel class Pipeline: + + class Valves(BaseModel): + LLAMAINDEX_OLLAMA_BASE_URL: str + LLAMAINDEX_MODEL_NAME: str + LLAMAINDEX_EMBEDDING_MODEL_NAME: str + def __init__(self): self.documents = None self.index = None + self.valves = self.Valves( + **{ + "LLAMAINDEX_OLLAMA_BASE_URL": os.getenv("LLAMAINDEX_OLLAMA_BASE_URL", "http://localhost:11434"), + "LLAMAINDEX_MODEL_NAME": os.getenv("LLAMAINDEX_MODEL_NAME", "llama3"), + "LLAMAINDEX_EMBEDDING_MODEL_NAME": os.getenv("LLAMAINDEX_EMBEDDING_MODEL_NAME", "nomic-embed-text"), + } + ) + async def on_startup(self): from llama_index.embeddings.ollama import OllamaEmbedding from llama_index.llms.ollama import Ollama from llama_index.core import Settings, VectorStoreIndex, SimpleDirectoryReader Settings.embed_model = OllamaEmbedding( - model_name="nomic-embed-text", - base_url="http://localhost:11434", + model_name=self.valves.LLAMAINDEX_EMBEDDING_MODEL_NAME, + base_url=self.valves.LLAMAINDEX_OLLAMA_BASE_URL, + ) + Settings.llm = Ollama( + model=self.valves.LLAMAINDEX_MODEL_NAME, + base_url=self.valves.LLAMAINDEX_OLLAMA_BASE_URL, ) - Settings.llm = Ollama(model="llama3") # This function is called when the server is started. global documents, index From 307abf187a3ed77743699e61cd00aef3db9251b5 Mon Sep 17 00:00:00 2001 From: Alexander Schaber Date: Sat, 29 Jun 2024 01:54:39 +0200 Subject: [PATCH 2/2] fix(examples/llamaindex_ollama): move path to pvc --- examples/pipelines/rag/llamaindex_ollama_pipeline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pipelines/rag/llamaindex_ollama_pipeline.py b/examples/pipelines/rag/llamaindex_ollama_pipeline.py index ef588e1..0b7765c 100644 --- a/examples/pipelines/rag/llamaindex_ollama_pipeline.py +++ b/examples/pipelines/rag/llamaindex_ollama_pipeline.py @@ -51,7 +51,7 @@ async def on_startup(self): # This function is called when the server is started. global documents, index - self.documents = SimpleDirectoryReader("./data").load_data() + self.documents = SimpleDirectoryReader("/app/backend/data").load_data() self.index = VectorStoreIndex.from_documents(self.documents) pass