Created
February 13, 2025 21:19
-
-
Save jwiegley/6a6147d3fbad41e9c15e394ff819843c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# python -m venv .venv | |
# source .venv/bin/activate | |
# pip install llama-index-llms-ollama | |
# pip install llama-index-embeddings-huggingface | |
# pip install llama-index-readers-file | |
# pip install "numpy<2" | |
# python starter.py | |
import sys | |
import os.path | |
from llama_index import LLMPredictor, ServiceContext | |
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings | |
from llama_index.embeddings.huggingface import HuggingFaceEmbedding | |
from llama_index.llms.ollama import Ollama | |
llm_predictor = LLMPredictor(temperature=0.7) | |
service_context = ServiceContext.from_defaults(llm_predictor=llm_predictor) | |
# bge-base embedding model | |
Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-base-en-v1.5") | |
# ollama | |
Settings.llm = Ollama(model="deepseek-r1:14b", request_timeout=360.0) | |
# check if storage already exists | |
PERSIST_DIR = "./storage" | |
if not os.path.exists(PERSIST_DIR): | |
# load the documents and create the index | |
documents = SimpleDirectoryReader("data").load_data() | |
index = VectorStoreIndex.from_documents(documents) | |
# store it for later | |
index.storage_context.persist(persist_dir=PERSIST_DIR) | |
else: | |
# load the existing index | |
storage_context = StorageContext.from_defaults(persist_dir=PERSIST_DIR) | |
index = load_index_from_storage(storage_context) | |
query_engine = index.as_query_engine() | |
response = query_engine.query("You are someone who works for the International Teaching Centre at the administrative center of the Bahá’í world. Your expertise deals with assisting and guidances communities who are laboring to achieve the goals of the current Plan. In your responses, you include guidance and quotations wherever applicable to help the friends understanding according to their own reality. The question being asked, and for which you provide a complete and well-thought answer is: What is the most effective way for an Area Teaching Committee to accompany nuclei within a cluster so that they can develop their own strengths and capacities and raise up new resources within their areas of service?") | |
print(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment