From ff927d1a5189280b61bb89f08178be33d5c77e17 Mon Sep 17 00:00:00 2001
From: "Embruch, Gerd" <gerd.embruch@uni-hamburg.de>
Date: Sat, 27 Apr 2024 15:09:23 +0200
Subject: [PATCH] switched to ollama model

---
 .env.template                                  | 4 ++++
 evaluateRAG.py                                 | 9 +++++----
 using_llamaindex_with_huggingface_models.ipynb | 0
 3 files changed, 9 insertions(+), 4 deletions(-)
 create mode 100755 using_llamaindex_with_huggingface_models.ipynb

diff --git a/.env.template b/.env.template
index f91a75c..b42cfed 100644
--- a/.env.template
+++ b/.env.template
@@ -4,6 +4,10 @@ PHOENIX_PORT=6006
 # API KEY TO OPENAI / CHATGPT API
 OPENAI_API_KEY=sk-hj8dfs8f9dsfsdgibberish
 
+# PATH TO LOCALLY INSTALLED OLLAMA DAEMON
+# to use a LLM via OLLAMA it must be installed already
+OLLAMA_API_BASE=http://localhost:11434
+
 #CHUNK SIZE OF DOMAIN FILES
 DOCUMENTS_CHUNK_SIZE=512
 
diff --git a/evaluateRAG.py b/evaluateRAG.py
index a096e58..45886c9 100644
--- a/evaluateRAG.py
+++ b/evaluateRAG.py
@@ -21,7 +21,7 @@ nest_asyncio.apply()
 from colorist import Color, BrightColor, bright_yellow, magenta, red, green
 # phoenix is the framework & webservice from arize (https://docs.arize.com/phoenix)
 import phoenix as px
-from phoenix.evals import OpenAIModel, llm_generate, HallucinationEvaluator, QAEvaluator, run_evals
+from phoenix.evals import OpenAIModel, LiteLLMModel, llm_generate, HallucinationEvaluator, QAEvaluator, run_evals
 from phoenix.session.evaluation import get_retrieved_documents, get_qa_with_reference
 from phoenix.evals import RelevanceEvaluator, run_evals
 from phoenix.trace import DocumentEvaluations, SpanEvaluations
@@ -114,7 +114,7 @@ nodes = node_parser.get_nodes_from_documents(documents)
 vector_index = VectorStoreIndex(nodes)
 print(f'created {length_hint(nodes)} chunks')
 countQuestions = length_hint(nodes) * int(os.environ['QUESTIONS_PER_CHUNK'])
-# # Build a QueryEngine and start querying.
+# Build a QueryEngine and start querying.
 query_engine = vector_index.as_query_engine()
 
 ##########
@@ -153,11 +153,12 @@ def output_parser(response: str, index: int):
     return {"__error__": str(e)}
   
 # prompt template to LLM and store > questions_df 
+# You can choose among multiple models supported by LiteLLM (https://docs.litellm.ai/docs/providers)
 questions_df = llm_generate(
   dataframe=document_chunks_df,
   template=generate_questions_template,
-  model=OpenAIModel(
-    model="gpt-3.5-turbo",
+  model=LiteLLMModel(
+    model="ollama/llama2",
   ),
   output_parser=output_parser,
   concurrency=20,
diff --git a/using_llamaindex_with_huggingface_models.ipynb b/using_llamaindex_with_huggingface_models.ipynb
new file mode 100755
index 0000000..e69de29
-- 
GitLab