first commit, smolagent basic tools
Browse files
README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
emoji: 🕵🏻♂️
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: indigo
|
|
|
|
| 1 |
---
|
| 2 |
+
title: Antonio Russo (Nioi) - Agents Course Final Assignment
|
| 3 |
emoji: 🕵🏻♂️
|
| 4 |
colorFrom: indigo
|
| 5 |
colorTo: indigo
|
agent.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'''
|
| 2 |
+
TODO tools
|
| 3 |
+
- web_search
|
| 4 |
+
|
| 5 |
+
Facultative
|
| 6 |
+
- wiki_search
|
| 7 |
+
- arxiv_search
|
| 8 |
+
'''
|
| 9 |
+
|
| 10 |
+
from smolagents import CodeAgent, HfApiModel, tool, DuckDuckGoSearchTool
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@tool
|
| 14 |
+
def add(a:int, b:int) -> int:
|
| 15 |
+
"""
|
| 16 |
+
This tool returns the sum of two numbers.
|
| 17 |
+
|
| 18 |
+
Args:
|
| 19 |
+
a: first number
|
| 20 |
+
b: second number
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
return a+b
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@tool
|
| 27 |
+
def subtract(a:int, b:int) -> int:
|
| 28 |
+
"""
|
| 29 |
+
This tool returns the difference between two numbers.
|
| 30 |
+
|
| 31 |
+
Args:
|
| 32 |
+
a: first number
|
| 33 |
+
b: second number
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
return a-b
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
@tool
|
| 40 |
+
def multiply(a:int, b:int) -> int:
|
| 41 |
+
"""
|
| 42 |
+
This tool multiplies two numbers.
|
| 43 |
+
|
| 44 |
+
Args:
|
| 45 |
+
a: first number
|
| 46 |
+
b: second number
|
| 47 |
+
"""
|
| 48 |
+
|
| 49 |
+
return a*b
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
@tool
|
| 53 |
+
def divide(a:int, b:int) -> float:
|
| 54 |
+
"""
|
| 55 |
+
This tool divides two numbers.
|
| 56 |
+
|
| 57 |
+
Args:
|
| 58 |
+
a: first number
|
| 59 |
+
b: second number
|
| 60 |
+
"""
|
| 61 |
+
|
| 62 |
+
if b==0: raise ValueError('Cannot divide by zero')
|
| 63 |
+
return a/b
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
@tool
|
| 67 |
+
def modulus(a:int, b:int) -> int:
|
| 68 |
+
"""
|
| 69 |
+
This tool returns the modulus of two numbers.
|
| 70 |
+
|
| 71 |
+
Args:
|
| 72 |
+
a: first number
|
| 73 |
+
b: second number
|
| 74 |
+
"""
|
| 75 |
+
|
| 76 |
+
return a%b
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
@tool
|
| 80 |
+
def rounder(a:float, n:int):
|
| 81 |
+
"""
|
| 82 |
+
This tool rounds a number to a certain number of decimals.
|
| 83 |
+
|
| 84 |
+
Args:
|
| 85 |
+
a: number to be rounded
|
| 86 |
+
n: number of decimals to use when rounding the number
|
| 87 |
+
"""
|
| 88 |
+
|
| 89 |
+
return round(a,n)
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def get_agent() -> CodeAgent:
|
| 93 |
+
search_tool = DuckDuckGoSearchTool()
|
| 94 |
+
|
| 95 |
+
return CodeAgent(tools=[add, subtract, multiply, divide, modulus, rounder, search_tool], model=HfApiModel())
|
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
| 4 |
-
import inspect
|
| 5 |
import pandas as pd
|
|
|
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
@@ -12,12 +12,13 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
|
|
|
| 15 |
print("BasicAgent initialized.")
|
| 16 |
def __call__(self, question: str) -> str:
|
| 17 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 18 |
-
|
| 19 |
-
print(f"Agent returning
|
| 20 |
-
return
|
| 21 |
|
| 22 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 23 |
"""
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import requests
|
|
|
|
| 4 |
import pandas as pd
|
| 5 |
+
import agent
|
| 6 |
|
| 7 |
# (Keep Constants as is)
|
| 8 |
# --- Constants ---
|
|
|
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
+
self.agent = agent.get_agent()
|
| 16 |
print("BasicAgent initialized.")
|
| 17 |
def __call__(self, question: str) -> str:
|
| 18 |
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 19 |
+
answer = self.agent.run(question)
|
| 20 |
+
print(f"Agent returning answer: {answer}")
|
| 21 |
+
return answer
|
| 22 |
|
| 23 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 24 |
"""
|
system_prompt.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
You are a helpful assistant tasked with answering questions using a set of tools.
|
| 2 |
+
Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
|
| 3 |
+
FINAL ANSWER: [YOUR FINAL ANSWER].
|
| 4 |
+
YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
|
| 5 |
+
Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
|