Henady Zakalusky commited on
Commit
4d4b0b3
·
1 Parent(s): 81917a3
Files changed (4) hide show
  1. .gitignore +1 -0
  2. agent.py +46 -0
  3. app.py +3 -1
  4. requirements.txt +8 -1
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .env
agent.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import os
3
+ from dotenv import load_dotenv
4
+ from smolagents import CodeAgent, WikipediaSearchTool, VisitWebpageTool, DuckDuckGoSearchTool, InferenceClientModel
5
+
6
+ load_dotenv()
7
+
8
+ print(os.environ)
9
+
10
+ class TheAgent:
11
+ def __init__(self):
12
+ headers = {
13
+ "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
14
+ "Accept-Language": "en-US,en;q=0.9,en;q=0.8"
15
+ }
16
+
17
+ search_tool = DuckDuckGoSearchTool(rate_limit = 5, headers=headers)
18
+ wiki_tool = WikipediaSearchTool()
19
+ page_tool = VisitWebpageTool()
20
+
21
+ model_id = "Qwen/Qwen3-235B-A22B-Instruct-2507"
22
+ # model_id = "Qwen/Qwen3-1.7B"
23
+
24
+ self.agent = CodeAgent(
25
+ tools=[wiki_tool, page_tool, search_tool],
26
+ model=InferenceClientModel(
27
+ model_id=model_id,
28
+ api_key='sk_uKU_em9uXppHSEDjJa1BJETjRaqhi-9vpU_6ADJoH4M'
29
+ ),
30
+ )
31
+
32
+ print("BasicAgent initialized.")
33
+
34
+ def __call__(self, question: str):
35
+ try:
36
+ result = self.agent.run(question)
37
+ return str(result)
38
+ except requests.exceptions.HTTPError as e:
39
+ print(f"Error: {e.response.text}")
40
+
41
+ if __name__ == "__main__":
42
+ agent = TheAgent()
43
+ question = "Who nominated the only Featured Article on English Wikipedia about a dinosaur that was promoted in November 2016?"
44
+ question = "How many studio albums were published by Mercedes Sosa between 2000 and 2009 (included)? You can use the latest 2022 version of english wikipedia."
45
+ answer = agent(question)
46
+ print(f"Answer: {answer}")
app.py CHANGED
@@ -4,6 +4,8 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
 
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -40,7 +42,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
40
 
41
  # 1. Instantiate Agent ( modify this part to create your agent)
42
  try:
43
- agent = BasicAgent()
44
  except Exception as e:
45
  print(f"Error instantiating agent: {e}")
46
  return f"Error initializing agent: {e}", None
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ from agent import TheAgent
8
+
9
  # (Keep Constants as is)
10
  # --- Constants ---
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
42
 
43
  # 1. Instantiate Agent ( modify this part to create your agent)
44
  try:
45
+ agent = TheAgent()
46
  except Exception as e:
47
  print(f"Error instantiating agent: {e}")
48
  return f"Error initializing agent: {e}", None
requirements.txt CHANGED
@@ -1,2 +1,9 @@
1
  gradio
2
- requests
 
 
 
 
 
 
 
 
1
  gradio
2
+ dotenv
3
+ requests
4
+ ddgs
5
+ markdownify
6
+ Wikipedia-API
7
+ smolagents
8
+ duckduckgo_search
9
+ huggingface_hub