wt002 commited on
Commit
70c4054
·
verified ·
1 Parent(s): 9443302

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -8,7 +8,7 @@ import requests
8
  from typing import List, Dict, Union
9
  import pandas as pd
10
  import wikipediaapi
11
-
12
 
13
  load_dotenv()
14
 
@@ -29,12 +29,14 @@ class BasicAgent:
29
  print(f"Agent returning answer: {fixed_answer}")
30
  return fixed_answer
31
 
32
- @staticmethod
33
- def basic_search(query):
34
- url = f"https://www.google.com/search?q={query}"
35
- response = requests.get(url)
36
- return response.text
37
 
 
 
 
 
 
 
 
38
 
39
 
40
 
 
8
  from typing import List, Dict, Union
9
  import pandas as pd
10
  import wikipediaapi
11
+ from googlesearch-python import search # pip install googlesearch-python
12
 
13
  load_dotenv()
14
 
 
29
  print(f"Agent returning answer: {fixed_answer}")
30
  return fixed_answer
31
 
 
 
 
 
 
32
 
33
+
34
+ def basic_search(self, query):
35
+ try:
36
+ results = list(search(query, num_results=1)) # Get top result
37
+ return results[0] if results else "No results found"
38
+ except Exception as e:
39
+ return f"Search error: {str(e)}"
40
 
41
 
42