Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,20 +4,31 @@ import requests
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
-
|
| 8 |
from Gradio_UI import GradioUI
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
-
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
-
def
|
| 13 |
-
|
| 14 |
-
"""A tool that does nothing yet
|
| 15 |
Args:
|
| 16 |
-
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 23 |
"""A tool that fetches the current local time in a specified timezone.
|
|
@@ -33,33 +44,21 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
temperature=0.5,
|
| 41 |
-
model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
|
| 42 |
-
custom_role_conversions=None,
|
| 43 |
)
|
| 44 |
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
-
# Import tool from Hub
|
| 47 |
-
image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
|
| 48 |
-
|
| 49 |
-
with open("prompts.yaml", 'r') as stream:
|
| 50 |
-
prompt_templates = yaml.safe_load(stream)
|
| 51 |
-
|
| 52 |
agent = CodeAgent(
|
| 53 |
model=model,
|
| 54 |
-
tools=[final_answer],
|
| 55 |
-
max_steps=
|
| 56 |
-
verbosity_level=1
|
| 57 |
-
grammar=None,
|
| 58 |
-
planning_interval=None,
|
| 59 |
-
name=None,
|
| 60 |
-
description=None,
|
| 61 |
-
prompt_templates=prompt_templates
|
| 62 |
)
|
| 63 |
|
| 64 |
-
|
| 65 |
GradioUI(agent).launch()
|
|
|
|
| 4 |
import pytz
|
| 5 |
import yaml
|
| 6 |
from tools.final_answer import FinalAnswerTool
|
| 7 |
+
import os
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
+
import requests
|
| 10 |
+
|
| 11 |
+
API_KEY = os.getenv("KEY")
|
| 12 |
+
|
| 13 |
|
|
|
|
| 14 |
@tool
|
| 15 |
+
def get_currency_rate(currency_pair: str) -> str:
|
| 16 |
+
"""Fetches the current exchange rate for a given currency pair (e.g., 'USD-EUR').
|
|
|
|
| 17 |
Args:
|
| 18 |
+
currency_pair: The currency pair to query, formatted as 'BASE-CURRENCY'.
|
|
|
|
| 19 |
"""
|
| 20 |
+
try:
|
| 21 |
+
# Use a free API like exchangerate-api.com
|
| 22 |
+
base, target = currency_pair.split("-")
|
| 23 |
+
response = requests.get(f"https://api.exchangerate-api.com/v4/latest/{base}")
|
| 24 |
+
data = response.json()
|
| 25 |
+
rate = data["rates"].get(target)
|
| 26 |
+
if rate:
|
| 27 |
+
return f"Current {currency_pair} rate: {rate}"
|
| 28 |
+
else:
|
| 29 |
+
return f"Invalid currency pair: {currency_pair}"
|
| 30 |
+
except Exception as e:
|
| 31 |
+
return f"Error fetching rate: {str(e)}"
|
| 32 |
@tool
|
| 33 |
def get_current_time_in_timezone(timezone: str) -> str:
|
| 34 |
"""A tool that fetches the current local time in a specified timezone.
|
|
|
|
| 44 |
except Exception as e:
|
| 45 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 46 |
|
| 47 |
+
model = OpenAIServerModel(
|
| 48 |
+
model_id="deepseek-chat",
|
| 49 |
+
api_base="https://api.deepseek.com",
|
| 50 |
+
api_key=API_KEY
|
|
|
|
|
|
|
|
|
|
| 51 |
)
|
| 52 |
|
| 53 |
+
# Load your custom tool and others
|
| 54 |
+
currency_tool = get_currency_rate
|
| 55 |
+
final_answer = FinalAnswerTool()
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
+
tools=[currency_tool, final_answer], # Include your tool here
|
| 60 |
+
max_steps=3,
|
| 61 |
+
verbosity_level=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
)
|
| 63 |
|
|
|
|
| 64 |
GradioUI(agent).launch()
|