davemasino commited on
Commit
fef0947
·
1 Parent(s): 88ad464

Move agent class ot its own file

Browse files
Files changed (3) hide show
  1. agent.py +40 -0
  2. app.py +1 -37
  3. tools.py +2 -0
agent.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ # --- Basic Agent Definition ---
4
+ # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
5
+ class BasicAgent:
6
+ def __init__(self):
7
+ print("BasicAgent initialized.")
8
+
9
+ def __call__(self, question: str) -> str:
10
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
11
+
12
+ ## new agent code
13
+ gemini_model = os.getenv(key="GEMINI_MODEL")
14
+
15
+ model = LiteLLMModel(model_id=f"gemini/{gemini_model}", api_key=os.getenv(key="GEMINI_API_KEY"))
16
+ agent = CodeAgent(
17
+ model=model,
18
+ tools=[DuckDuckGoSearchTool()]
19
+ )
20
+ prompt = f"""\
21
+ You are a general AI assistant. I will ask you a question. Report your thoughts,
22
+ and finish your answer with the following template:
23
+ FINAL ANSWER: YOUR FINAL ANSWER
24
+ YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma-
25
+ separated list of numbers and/or strings.
26
+
27
+ If you are asked for a number, do NOT use commas or units (%, $, etc.) unless
28
+ explicitly requested. If you are asked for a string, do NOT use articles or
29
+ abbreviations (e.g. for cities) and write digits in plain text unless
30
+ specified otherwise. If you are asked for a comma-separated list, apply the
31
+ above rules to each element.
32
+
33
+ {question}
34
+ """
35
+ answer = agent.run(prompt)
36
+
37
+ print(f"Agent returning answer: {answer}")
38
+ return answer
39
+
40
+
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
6
  from smolagents import ToolCallingAgent, CodeAgent, LiteLLMModel
7
 
8
  from tools import DuckDuckGoSearchTool, WeatherInfoTool, HubStatsTool
@@ -21,43 +22,6 @@ hub_stats_tool = HubStatsTool()
21
  # --- Constants ---
22
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
23
 
24
- # --- Basic Agent Definition ---
25
- # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
26
- class BasicAgent:
27
- def __init__(self):
28
- print("BasicAgent initialized.")
29
-
30
- def __call__(self, question: str) -> str:
31
- print(f"Agent received question (first 50 chars): {question[:50]}...")
32
-
33
- ## new agent code
34
- gemini_model = os.getenv(key="GEMINI_MODEL")
35
-
36
- model = LiteLLMModel(model_id=f"gemini/{gemini_model}", api_key=os.getenv(key="GEMINI_API_KEY"))
37
- agent = CodeAgent(
38
- model=model,
39
- tools=[DuckDuckGoSearchTool()]
40
- )
41
- prompt = f"""\
42
- You are a general AI assistant. I will ask you a question. Report your thoughts,
43
- and finish your answer with the following template:
44
- FINAL ANSWER: YOUR FINAL ANSWER
45
- YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma-
46
- separated list of numbers and/or strings.
47
-
48
- If you are asked for a number, do NOT use commas or units (%, $, etc.) unless
49
- explicitly requested. If you are asked for a string, do NOT use articles or
50
- abbreviations (e.g. for cities) and write digits in plain text unless
51
- specified otherwise. If you are asked for a comma-separated list, apply the
52
- above rules to each element.
53
-
54
- {question}
55
- """
56
- answer = agent.run(prompt)
57
-
58
- print(f"Agent returning answer: {answer}")
59
- return answer
60
-
61
 
62
  def run_and_submit_all( profile: gr.OAuthProfile | None):
63
  """
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from agent import BasicAgent
7
  from smolagents import ToolCallingAgent, CodeAgent, LiteLLMModel
8
 
9
  from tools import DuckDuckGoSearchTool, WeatherInfoTool, HubStatsTool
 
22
  # --- Constants ---
23
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  def run_and_submit_all( profile: gr.OAuthProfile | None):
27
  """
tools.py CHANGED
@@ -3,6 +3,8 @@ from smolagents import Tool
3
  import random
4
  from huggingface_hub import list_models
5
 
 
 
6
 
7
  class WeatherInfoTool(Tool):
8
  name = "weather_info"
 
3
  import random
4
  from huggingface_hub import list_models
5
 
6
+ ## CURRENTLY NOT USED - KEEP AS TEMPLATE
7
+
8
 
9
  class WeatherInfoTool(Tool):
10
  name = "weather_info"