Spaces:
Sleeping
Sleeping
Eurico149
commited on
Commit
·
54e6e24
1
Parent(s):
6fa006d
feat: CurrencyConverterTool
Browse files- app.py +5 -2
- tools/CurrencyConverterTool.py +40 -0
- tools/{weather.py → WeatherTool.py} +0 -0
- tools/__init__.py +2 -1
app.py
CHANGED
|
@@ -3,7 +3,7 @@ import gradio as gr
|
|
| 3 |
from dataclasses import asdict
|
| 4 |
from smolagents import CodeAgent, TransformersModel, InferenceClientModel, stream_to_gradio
|
| 5 |
from transformers import BitsAndBytesConfig
|
| 6 |
-
from tools import get_weather
|
| 7 |
|
| 8 |
|
| 9 |
model_path = "Qwen/Qwen3-4B-Instruct-2507"
|
|
@@ -25,7 +25,10 @@ else:
|
|
| 25 |
)
|
| 26 |
|
| 27 |
agent = CodeAgent(
|
| 28 |
-
tools=[
|
|
|
|
|
|
|
|
|
|
| 29 |
model=model,
|
| 30 |
max_steps=8,
|
| 31 |
verbosity_level=2,
|
|
|
|
| 3 |
from dataclasses import asdict
|
| 4 |
from smolagents import CodeAgent, TransformersModel, InferenceClientModel, stream_to_gradio
|
| 5 |
from transformers import BitsAndBytesConfig
|
| 6 |
+
from tools import get_weather, CurrencyConverterTool
|
| 7 |
|
| 8 |
|
| 9 |
model_path = "Qwen/Qwen3-4B-Instruct-2507"
|
|
|
|
| 25 |
)
|
| 26 |
|
| 27 |
agent = CodeAgent(
|
| 28 |
+
tools=[
|
| 29 |
+
get_weather,
|
| 30 |
+
CurrencyConverterTool()
|
| 31 |
+
],
|
| 32 |
model=model,
|
| 33 |
max_steps=8,
|
| 34 |
verbosity_level=2,
|
tools/CurrencyConverterTool.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from smolagents import Tool
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class CurrencyConverterTool(Tool):
|
| 6 |
+
name: str = "CurrencyConverterTool"
|
| 7 |
+
|
| 8 |
+
description: str = """
|
| 9 |
+
This tool are used to convert currencies in real time."""
|
| 10 |
+
|
| 11 |
+
inputs = {
|
| 12 |
+
"value": {
|
| 13 |
+
"type": "number",
|
| 14 |
+
"description": "The Amount to convert.",
|
| 15 |
+
},
|
| 16 |
+
"currency1": {
|
| 17 |
+
"type": "string",
|
| 18 |
+
"description": "The base currency.",
|
| 19 |
+
},
|
| 20 |
+
"currency2": {
|
| 21 |
+
"type": "string",
|
| 22 |
+
"description": "The target currency.",
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
output_type = "string"
|
| 27 |
+
|
| 28 |
+
def forward(self, value: float, currency1: str, currency2: str) -> str:
|
| 29 |
+
result = self._real_time_convert(currency1, currency2)
|
| 30 |
+
return f"{value * result:.2f}"
|
| 31 |
+
|
| 32 |
+
def _real_time_convert(self, curency1: str, curency2: str) -> float:
|
| 33 |
+
url = f"https://economia.awesomeapi.com.br/json/last/{curency1}-{curency2}"
|
| 34 |
+
|
| 35 |
+
response = requests.get(url, timeout=5)
|
| 36 |
+
response.raise_for_status()
|
| 37 |
+
data = response.json()
|
| 38 |
+
key = f"{curency1}{curency2}"
|
| 39 |
+
|
| 40 |
+
return float(data[key]['bid'])
|
tools/{weather.py → WeatherTool.py}
RENAMED
|
File without changes
|
tools/__init__.py
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
from .
|
|
|
|
|
|
| 1 |
+
from .WeatherTool import get_weather
|
| 2 |
+
from .CurrencyConverterTool import CurrencyConverterTool
|