Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
|
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
@@ -8,15 +9,80 @@ from tools.final_answer import FinalAnswerTool
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
Args:
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
18 |
"""
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
@tool
|
22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
@@ -55,7 +121,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
55 |
|
56 |
agent = CodeAgent(
|
57 |
model=model,
|
58 |
-
tools=[final_answer], ## add your tools here (don't remove final answer)
|
59 |
max_steps=6,
|
60 |
verbosity_level=1,
|
61 |
grammar=None,
|
|
|
1 |
from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
|
2 |
+
from typing import Optional
|
3 |
import datetime
|
4 |
import requests
|
5 |
import pytz
|
|
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
11 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
12 |
+
# @tool
|
13 |
+
# def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
14 |
+
# #Keep this format for the description / args / args description but feel free to modify the tool
|
15 |
+
# """A tool that does nothing yet
|
16 |
+
# Args:
|
17 |
+
# arg1: the first argument
|
18 |
+
# arg2: the second argument
|
19 |
+
# """
|
20 |
+
# return "What magic will you build ?"
|
21 |
+
|
22 |
+
# from smolagents import tool
|
23 |
+
|
24 |
+
|
25 |
@tool
|
26 |
+
def search_hotels(
|
27 |
+
cityname: str,
|
28 |
+
check_in_date: str,
|
29 |
+
check_out_date: str,
|
30 |
+
num_of_adults: int = 1,
|
31 |
+
num_of_rooms: int = 1,
|
32 |
+
|
33 |
+
) -> str:
|
34 |
+
"""Searches for hotels in a given city using MakCorps API.
|
35 |
+
|
36 |
Args:
|
37 |
+
cityname: Name of the city to search hotels in.
|
38 |
+
check_in_date: Date of check-in in YYYY-MM-DD format.
|
39 |
+
check_out_date: Date of check-out in YYYY-MM-DD format.
|
40 |
+
num_of_adults: Number of adults staying.
|
41 |
+
num_of_rooms: Number of rooms required.
|
42 |
"""
|
43 |
+
import requests
|
44 |
+
import os
|
45 |
+
|
46 |
+
api_key = '67f1515138cc22f7030316b9' #os.getenv("MAKCORPS_API_KEY") # Store API key as an environment variable for security
|
47 |
+
|
48 |
+
url_template = (
|
49 |
+
"https://api.makcorps.com/citysearch/"
|
50 |
+
"{cityname}/{page}/{currency}/{num_of_rooms}/{num_of_adults}/{check_in_date}/{check_out_date}"
|
51 |
+
)
|
52 |
+
|
53 |
+
url = url_template.format(
|
54 |
+
cityname=cityname,
|
55 |
+
page=page,
|
56 |
+
currency=currency,
|
57 |
+
num_of_rooms=num_of_rooms,
|
58 |
+
num_of_adults=num_of_adults,
|
59 |
+
check_in_date=check_in_date,
|
60 |
+
check_out_date=check_out_date,
|
61 |
+
)
|
62 |
+
|
63 |
+
full_url = f"{url}?api_key={api_key}"
|
64 |
+
|
65 |
+
try:
|
66 |
+
response = requests.get(full_url)
|
67 |
+
data = response.json()
|
68 |
+
|
69 |
+
# Format and return top 3 hotels for brevity
|
70 |
+
if "data" not in data or not data["data"]:
|
71 |
+
return f"No hotel data found for {cityname}."
|
72 |
+
|
73 |
+
hotels = data["data"]
|
74 |
+
formatted_hotels = []
|
75 |
+
|
76 |
+
for hotel in hotels[:3]: # Limit to top 3 results
|
77 |
+
name = hotel.get("hotel_name", "Unknown Hotel")
|
78 |
+
price = hotel.get("lowest_avg_price", "N/A")
|
79 |
+
formatted_hotels.append(f"{name} - from {price} {currency}")
|
80 |
+
|
81 |
+
return f"Top hotels in {cityname}:\n" + "\n".join(formatted_hotels)
|
82 |
+
|
83 |
+
except Exception as e:
|
84 |
+
return f"Error fetching hotel data: {str(e)}"
|
85 |
+
|
86 |
|
87 |
@tool
|
88 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
121 |
|
122 |
agent = CodeAgent(
|
123 |
model=model,
|
124 |
+
tools=[final_answer,search_hotels,DuckDuckGoSearchTool], ## add your tools here (don't remove final answer)
|
125 |
max_steps=6,
|
126 |
verbosity_level=1,
|
127 |
grammar=None,
|