-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuery.py
More file actions
83 lines (70 loc) · 2.5 KB
/
Copy pathQuery.py
File metadata and controls
83 lines (70 loc) · 2.5 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
import os
import asyncio
from ylightRag.yllm.openai import gpt_4o_mini_complete, openai_embed
from ylightRag.ykg.shared_storage import initialize_pipeline_status
from dotenv import load_dotenv
from ylightRag.ylightrag import LightRAG
from ylightRag.ybase import QueryParam
from ylightRag.yutils import EmbeddingFunc
load_dotenv()
WORKING_DIR = "Cache"
async def main():
# Initialize RAG system
rag = LightRAG(
llm_model_func=gpt_4o_mini_complete,
embedding_func=EmbeddingFunc(
embedding_dim=1536,
max_token_size=8192,
func=openai_embed
),
working_dir=WORKING_DIR
)
await rag.initialize_storages()
await initialize_pipeline_status()
print("=" * 60)
print("🤖 Interactive RAG Query System")
print("=" * 60)
print("Welcome! You can now ask questions about your documents.")
print("Type 'exit' to quit the application.")
print("Type 'help' for available commands.")
print("-" * 60)
while True:
try:
# Get user input
user_query = input("\n💬 Enter your query: ").strip()
# Check for exit condition
if user_query.lower() in ['exit', 'quit', 'q']:
print("\n👋 Goodbye! Thank you for using the RAG system.")
break
# Check for empty input
if not user_query:
print("⚠️ Please enter a valid query.")
continue
# Process the query
print(f"\n🔍 Processing query: '{user_query}'")
print("⏳ Please wait...")
# Execute the query
response = await rag.aquery(
user_query,
param=QueryParam(mode="local")
)
# Display the response
print("\n" + "=" * 60)
print("📝 Response:")
print("=" * 60)
print(response)
print("=" * 60)
except KeyboardInterrupt:
print("\n\n⚠️ Interrupted by user. Exiting...")
break
except Exception as e:
print(f"\n❌ An error occurred: {str(e)}")
print("Please try again with a different query.")
continue
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nApplication terminated by user.")
except Exception as e:
print(f"Failed to start application: {str(e)}")