-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample_usage.py
More file actions
125 lines (102 loc) · 3.96 KB
/
example_usage.py
File metadata and controls
125 lines (102 loc) · 3.96 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python3
"""
Example usage for IPCC Chapter RAG System
Shows how different users can load different chapters and ask questions.
"""
from chapter_manager import ChapterManager
def example_user_workflow():
"""Example of how a user would work with a specific chapter."""
# Initialize the chapter manager
manager = ChapterManager()
# List available chapters
print("📚 Available IPCC Chapters:")
chapters = manager.list_available_chapters()
for chapter in chapters:
print(f" - {chapter}")
# Example: User Alice loads Chapter 4
print("\n" + "="*50)
print("👤 Alice's Workflow")
print("="*50)
user_id = "alice"
chapter_path = "wg1/chapter04"
# Load the chapter (this creates a separate collection for Alice)
try:
pipeline = manager.load_chapter(chapter_path, user_id)
print(f"✅ Alice loaded {chapter_path}")
except Exception as e:
print(f"❌ Failed to load chapter: {e}")
return
# Alice asks questions about her chapter
alice_queries = [
"What are the main climate scenarios used in projections?",
"How do CMIP6 models differ from CMIP5?",
"What is the projected temperature increase by 2100?"
]
for query in alice_queries:
print(f"\n❓ Alice asks: {query}")
try:
result = manager.query_chapter(chapter_path, query, user_id)
print(f"📝 Answer: {result['answer']}")
print(f"🏷️ Source paragraphs: {result['paragraph_ids'][:3]}...")
except Exception as e:
print(f"❌ Error: {e}")
# Example: User Bob loads the same chapter (gets his own collection)
print("\n" + "="*50)
print("👤 Bob's Workflow")
print("="*50)
user_id = "bob"
# Bob loads the same chapter but gets his own isolated context
try:
pipeline = manager.load_chapter(chapter_path, user_id)
print(f"✅ Bob loaded {chapter_path} (separate from Alice)")
except Exception as e:
print(f"❌ Failed to load chapter: {e}")
return
# Bob asks different questions
bob_queries = [
"How do climate models handle uncertainty?",
"What are the Shared Socioeconomic Pathways?",
"How does Arctic sea ice change in projections?"
]
for query in bob_queries:
print(f"\n❓ Bob asks: {query}")
try:
result = manager.query_chapter(chapter_path, query, user_id)
print(f"📝 Answer: {result['answer']}")
print(f"🏷️ Source paragraphs: {result['paragraph_ids'][:3]}...")
except Exception as e:
print(f"❌ Error: {e}")
# Show what's loaded
print("\n" + "="*50)
print("📊 System Status")
print("="*50)
print(f"Loaded chapters: {manager.list_loaded_chapters()}")
for chapter in manager.list_loaded_chapters():
info = manager.get_chapter_info(chapter)
print(f" - {chapter}: {info['collection_name']} (User: {info['user_id']})")
def simple_query_example():
"""Simple example for quick testing."""
manager = ChapterManager()
# Quick query to a specific chapter
chapter = "wg1/chapter04"
query = "What are the main climate scenarios?"
user_id = "test_user"
print(f"🔍 Querying {chapter}: {query}")
try:
result = manager.query_chapter(chapter, query, user_id)
print(f"📝 Answer: {result['answer']}")
print(f"🏷️ Paragraph IDs: {result['paragraph_ids']}")
except Exception as e:
print(f"❌ Error: {e}")
if __name__ == "__main__":
print("Choose an example:")
print("1. Full user workflow demo")
print("2. Simple query example")
choice = input("Enter choice (1 or 2): ").strip()
if choice == "1":
example_user_workflow()
elif choice == "2":
simple_query_example()
else:
print("Running simple example...")
simple_query_example()