aynot commited on
Commit
b8fd611
·
1 Parent(s): 255d634

initial agent implementation

Browse files
Files changed (3) hide show
  1. agent.py +26 -0
  2. app.py +6 -3
  3. tools.py +10 -0
agent.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import CodeAgent, LiteLLMModel
2
+ import os
3
+
4
+ from tools import initialize_all_available_tools
5
+
6
+
7
+ class MyAgent:
8
+ def __init__(self, verbosity_level=0):
9
+ model = LiteLLMModel(
10
+ model_id="gemini/gemini-2.0-flash-lite",
11
+ api_key=os.environ.get('GOOGLE_API_KEY')
12
+ )
13
+ tools = initialize_all_available_tools()
14
+
15
+ self.agent = CodeAgent(
16
+ tools=tools,
17
+ model=model,
18
+ max_steps=10,
19
+ verbosity_level=verbosity_level
20
+ )
21
+
22
+ def get_answer(self, question):
23
+ answer = self.agent.run(question)
24
+ return answer
25
+
26
+
app.py CHANGED
@@ -4,6 +4,8 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
 
 
7
  from dotenv import load_dotenv, find_dotenv
8
  load_dotenv(find_dotenv())
9
 
@@ -15,12 +17,13 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
15
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
16
  class BasicAgent:
17
  def __init__(self):
 
18
  print("BasicAgent initialized.")
19
  def __call__(self, question: str) -> str:
20
  print(f"Agent received question (first 50 chars): {question[:50]}...")
21
- fixed_answer = "This is a default answer."
22
- print(f"Agent returning fixed answer: {fixed_answer}")
23
- return fixed_answer
24
 
25
  def run_and_submit_all( profile: gr.OAuthProfile | None):
26
  """
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ from agent import MyAgent
8
+
9
  from dotenv import load_dotenv, find_dotenv
10
  load_dotenv(find_dotenv())
11
 
 
17
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
18
  class BasicAgent:
19
  def __init__(self):
20
+ self.agent = MyAgent()
21
  print("BasicAgent initialized.")
22
  def __call__(self, question: str) -> str:
23
  print(f"Agent received question (first 50 chars): {question[:50]}...")
24
+ answer = self.agent.get_answer(question)
25
+ print(f"Agent returning fixed answer: {answer}")
26
+ return answer
27
 
28
  def run_and_submit_all( profile: gr.OAuthProfile | None):
29
  """
tools.py ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ from smolagents import DuckDuckGoSearchTool, VisitWebpageTool
2
+
3
+
4
+
5
+ def initialize_all_available_tools():
6
+ return [
7
+ DuckDuckGoSearchTool(),
8
+ VisitWebpageTool()
9
+ ]
10
+