Quazim0t0 commited on
Commit
51835ea
·
verified ·
1 Parent(s): 4839c34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -11,6 +11,17 @@ from urllib.parse import quote_plus
11
  from scripts.text_web_browser import SimpleTextBrowser, SearchInformationTool
12
  from scripts.cookies import COOKIES
13
 
 
 
 
 
 
 
 
 
 
 
 
14
  @tool
15
  def analyze_content(text: str, analysis_type: str = "general") -> str:
16
  """Analyzes content for various aspects like key points, themes, or citations
@@ -48,7 +59,7 @@ def analyze_content(text: str, analysis_type: str = "general") -> str:
48
 
49
  class ResearchSystem:
50
  def __init__(self):
51
- # Create browser with proper request_kwargs initialization
52
  self.browser = SimpleTextBrowser(
53
  viewport_size=4096,
54
  downloads_folder="./downloads",
@@ -69,10 +80,10 @@ class ResearchSystem:
69
  }
70
  )
71
 
72
- # Initialize agent with web search tool
73
  self.researcher = CodeAgent(
74
  tools=[
75
- SearchInformationTool(self.browser),
76
  analyze_content
77
  ],
78
  model=self.model
@@ -121,8 +132,8 @@ class ResearchSystem:
121
  try:
122
  print(f"\nDEBUG: Processing query: {query}")
123
 
124
- # Use the web search tool
125
- search_results = self.researcher.run(f"web_search: {query}")
126
  print(f"\nDEBUG: Search completed. Results:\n{search_results}")
127
 
128
  # Analyze the results
 
11
  from scripts.text_web_browser import SimpleTextBrowser, SearchInformationTool
12
  from scripts.cookies import COOKIES
13
 
14
+ class DuckDuckGoSearchTool(SearchInformationTool):
15
+ """Search tool that uses DuckDuckGo's HTML interface"""
16
+
17
+ def forward(self, query: str, filter_year: Optional[int] = None) -> str:
18
+ """Performs search using DuckDuckGo"""
19
+ encoded_query = quote_plus(query)
20
+ url = f"https://duckduckgo.com/?t=h_&q={encoded_query}"
21
+ self.browser.visit_page(url)
22
+ header, content = self.browser._state()
23
+ return header.strip() + "\n=======================\n" + content
24
+
25
  @tool
26
  def analyze_content(text: str, analysis_type: str = "general") -> str:
27
  """Analyzes content for various aspects like key points, themes, or citations
 
59
 
60
  class ResearchSystem:
61
  def __init__(self):
62
+ # Initialize browser with request settings
63
  self.browser = SimpleTextBrowser(
64
  viewport_size=4096,
65
  downloads_folder="./downloads",
 
80
  }
81
  )
82
 
83
+ # Initialize agent with custom DuckDuckGo search tool
84
  self.researcher = CodeAgent(
85
  tools=[
86
+ DuckDuckGoSearchTool(self.browser),
87
  analyze_content
88
  ],
89
  model=self.model
 
132
  try:
133
  print(f"\nDEBUG: Processing query: {query}")
134
 
135
+ # Get search results using the browser
136
+ search_results = self.researcher.run(f"Search query: {query}")
137
  print(f"\nDEBUG: Search completed. Results:\n{search_results}")
138
 
139
  # Analyze the results