alisamak commited on
Commit
0359413
·
verified ·
1 Parent(s): 4dc7788

basic agent init

Browse files

extracting the agent to separate class

Files changed (1) hide show
  1. basic_agent.py +23 -0
basic_agent.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from duckduckgo_search import DDGS
2
+
3
+ # DuckDuckGo Search Tool
4
+ def search_duckduckgo(query: str, max_results: int = 3) -> list[str]:
5
+ with DDGS() as ddgs:
6
+ results = ddgs.text(query, safesearch="Moderate")
7
+ return [r["body"] for r in results[:max_results]]
8
+
9
+ class BasicAgent:
10
+ def __call__(self, question: str) -> str:
11
+ try:
12
+ if "capital of France" in question.lower():
13
+ return "Paris"
14
+ elif "2 + 2" in question:
15
+ return "4"
16
+ else:
17
+ results = search_duckduckgo(question)
18
+ if results:
19
+ return results[0]
20
+ else:
21
+ return "I couldn't find an answer."
22
+ except Exception as e:
23
+ return f"Error searching: {e}"