-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (45 loc) · 1.66 KB
/
main.py
File metadata and controls
59 lines (45 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# main.py
import dspy
import logging
from graph_vector_rag.config import settings
from graph_vector_rag.multihop_agent import MultiHopQASystem
def setup_dspy_and_logging():
"""Configures DSPy and Python's logging system."""
logging.basicConfig(
level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s"
)
if not settings.OPENAI_API_KEY:
raise ValueError("Please set OPENAI_API_KEY")
lm = dspy.LM(
model="openai/gpt-4o", # Use a more powerful model for reasoning
api_key=settings.OPENAI_API_KEY,
temperature=0.1,
max_tokens=8192, # Increased for more complex reasoning
)
dspy.configure(lm=lm)
logging.info("✅ DSPy and logging configured.")
def main():
"""Runs an interactive chat loop for the multi-hop QA system."""
setup_dspy_and_logging()
# Initialize our multi-hop agent
agent = MultiHopQASystem(num_hops=3)
print("\n✅ Multi-Hop Graph RAG Chat Prototype Initialized")
print(" This agent can answer complex, multi-step questions.")
print(" Type 'exit' to end the session.")
try:
while True:
question = input("\nAsk a complex question: ")
if question.lower() == "exit":
break
result = agent(question=question)
print("\n--- Final Answer ---")
print(result.answer)
print("\n--- Full Reasoning Scratchpad ---")
print(result.full_scratchpad)
except KeyboardInterrupt:
print("\nSession ended by user.")
finally:
agent.close() # Close the retriever connections
print("\nGoodbye!")
if __name__ == "__main__":
main()