Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added filter for websearching only official drexel websites #3

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
added filter for websearching only official drexel websites
  • Loading branch information
azavalny committed Oct 22, 2024
commit 996498cc1f7fb3dea840442ec518c87c82940e07
6 changes: 4 additions & 2 deletions data_collection/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,14 @@ def is_valid_url(url: str) -> bool:
is_social_media = any(platform in url for platform in ["reddit", "tiktok", "linkedin", "instagram", "facebook", "twitter", "youtube"])
return is_http and not has_invalid_extension and not is_social_media

# too slow, deprecating
def fetch_content_from_urls(urls):
content = ""
if type(urls) == str:
urls = [urls]
for url in urls:
if is_valid_url(url):
if is_valid_url(url) and "drexel.edu" in url:
print(url)
try:
response = requests.get(url)
if response.status_code == 200:
Expand All @@ -446,4 +448,4 @@ def duckduckgo_search(query):
return DDGS().text(query, max_results=3, backend="lite")

if __name__ == "__main__":
upload_minors_to_index(r'C:\Users\alexa\Desktop\dragongpt-backend\data_collection\tools\drexel_catalog\data\minors_data.json')
pass
10 changes: 6 additions & 4 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ def improve_rag(RAG, query):

if check_answer.lower() != 'yes':
urls = parse_urls_from_rag(RAG)
RAG += data_manager.fetch_content_from_urls(urls)
# RAG += data_manager.fetch_content_from_urls(urls)
search_results = data_manager.duckduckgo_search(query + " at Drexel University 2024")
# print(search_results)
for result in search_results:
# print("fetching info")
RAG += result["body"]
moreinfo = data_manager.fetch_content_from_urls(result["href"])
if result["href"] not in urls:
RAG += moreinfo + result["href"]
#print(result["href"])
#print(moreinfo)
# print(result["href"])
# print(moreinfo)
if len(RAG) > 128000:
RAG = RAG[:128000]
return RAG
Expand Down Expand Up @@ -73,7 +76,6 @@ def query_llm():

if not query:
return jsonify({"detail": "Query is required"}), 400

RAG = data_manager.query_from_index(query)
RAG = improve_rag(RAG, query)
system_prompt = open(os.path.join("prompts", "system.txt"), 'r').read()
Expand Down