-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
61 lines (47 loc) · 1.62 KB
/
Copy pathagent.py
File metadata and controls
61 lines (47 loc) · 1.62 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
print("Script started")
import argparse
from validator import validate_query
from scraper import scrape_query
from summarizer import summarize_text
from vectorstore import get_vector_store
import os
os.environ["CHROMA_TELEMETRY_ENABLED"] = "False"
# Initialize vector store (default: Chroma)
vector_store = get_vector_store("chroma")
def main():
print("Main function entered")
try:
parser = argparse.ArgumentParser(description="Web-query agent CLI")
parser.add_argument('query', help='Search query to run')
args = parser.parse_args()
print(f"Query received: {args.query}")
# 1. Check cache
# cached = find_cached(args.query, vector_store)
cached=vector_store.search(args.query)
if cached:
print("Cached result:")
print("\n===== CACHED RESULT =====\n")
print(cached)
print("\n===== CACHED RESULT =====\n")
return
# else:
# print('idk')
# print(cached)
# 2. Validate
if not validate_query(args.query):
print("❌This is not a valid query.")
return
# # 3. Scrape & Summarize
print("Scraping and summarizing...")
pages = scrape_query(args.query)
summary = summarize_text(pages)
print("\n===== SUMMARY START =====\n")
print(summary)
print("\n===== SUMMARY END =====\n")
# # 4. Store
print("Storing result...")
vector_store.store(args.query, summary)
except Exception as e:
print("Error occurred:", e)
if __name__ == '__main__':
main()