Skip to content

Commit 8d90254

Browse files
authored
Merge pull request #5 from roverflow/agent_service
Add agent service
2 parents 87a655e + 1330896 commit 8d90254

12 files changed

+232
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ __pycache__/
1212
.cache/
1313
.DS_Store
1414
output*
15+
storage/*.json

data/AccessSecurityOverview.pdf

507 KB
Binary file not shown.

data/Communications.pdf

45.1 KB
Binary file not shown.

data/ITSupport.pdf

174 KB
Binary file not shown.

data/MyLaptopOverview.pdf

1.07 MB
Binary file not shown.
1.23 MB
Binary file not shown.

data/indiaholiday.pdf

44.8 KB
Binary file not shown.

requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ hf_xet
2929
tf-keras
3030
selenium # can be removed after tesing with igloo API
3131
pdfminer.six
32+
fastapi
33+
uvicorn
34+
python-dotenv

sample.env

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ PGVECTOR_PASS=
1111
PGVECTOR_DATABASE_NAME=
1212
PGVECTOR_URI="localhost"
1313
PGVECTOR_PORT="5432"
14+
15+
16+
OPENAI_API_KEY="sk-..."
17+
AGENT_SERVICE_URL="http://localhost:8001"

scripts/bot_script.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
load_index_from_storage,
88
Settings,
99
)
10-
from llama_index.llms.ollama import Ollama
11-
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
10+
from llama_index.llms.openai import OpenAI
11+
from llama_index.embeddings.openai import OpenAIEmbedding
1212
from llama_index.readers.file import PDFReader
1313

14+
from dotenv import load_dotenv
15+
16+
load_dotenv()
17+
1418
# Config
1519
ROOT_DIR = Path(__file__).resolve().parent.parent
1620
DATA_DIR = ROOT_DIR / "data"
@@ -20,7 +24,13 @@ async def build_and_save_index():
2024
"""Builds the index from PDF files and saves it."""
2125
print("Loading PDF documents...")
2226
reader = PDFReader()
23-
documents = reader.load_data(folder_path=DATA_DIR)
27+
pdf_files = list(DATA_DIR.glob("**/*.pdf"))
28+
29+
documents = []
30+
for pdf_file in pdf_files:
31+
documents.extend(reader.load_data(file=pdf_file))
32+
33+
print(f"Loaded {len(documents)} document chunks from {len(pdf_files)} PDF files")
2434

2535
print("Building index...")
2636
index = VectorStoreIndex.from_documents(documents)
@@ -31,7 +41,7 @@ async def build_and_save_index():
3141

3242
async def load_or_build_index():
3343
"""Loads existing index or builds a new one if not found."""
34-
if os.path.exists(STORAGE_DIR):
44+
if os.path.exists(STORAGE_DIR) or False:
3545
print(f"Loading existing index from {STORAGE_DIR}/...")
3646
storage_context = StorageContext.from_defaults(persist_dir=STORAGE_DIR)
3747
index = load_index_from_storage(storage_context)
@@ -41,8 +51,11 @@ async def load_or_build_index():
4151

4252
async def main():
4353
# Step 1: Setup global Settings
44-
Settings.embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-base-en-v1.5")
45-
Settings.llm = Ollama(model="llama3.1", request_timeout=360.0)
54+
Settings.embed_model = OpenAIEmbedding(api_key=os.getenv("OPENAI_API_KEY"))
55+
Settings.llm = OpenAI(
56+
api_key=os.getenv("OPENAI_API_KEY"),
57+
model="gpt-4o-mini"
58+
)
4659

4760
# Step 2: Load or build the index
4861
index = await load_or_build_index()

0 commit comments

Comments
 (0)