Spaces:
Sleeping
Sleeping
Updated app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,49 @@ 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 my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 13 |
#Keep this format for the description / args / args description but feel free to modify the tool
|
|
|
|
| 8 |
from Gradio_UI import GradioUI
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
+
|
| 12 |
+
@tool
|
| 13 |
+
def search_hotels_with_prices(city_code: str, check_in_date: str, check_out_date: str, adults: int) -> str:
|
| 14 |
+
"""A tool that searches for hotels with prices using the Amadeus API.
|
| 15 |
+
Args:
|
| 16 |
+
city_code: The IATA city code (e.g., 'NYC' for New York).
|
| 17 |
+
check_in_date: The check-in date in 'YYYY-MM-DD' format.
|
| 18 |
+
check_out_date: The check-out date in 'YYYY-MM-DD' format.
|
| 19 |
+
adults: The number of adults.
|
| 20 |
+
"""
|
| 21 |
+
amadeus_api_key = 'YOUR_AMADEUS_API_KEY'
|
| 22 |
+
amadeus_api_secret = 'YOUR_AMADEUS_API_SECRET'
|
| 23 |
+
|
| 24 |
+
# Get access token
|
| 25 |
+
auth_response = requests.post(
|
| 26 |
+
'https://test.api.amadeus.com/v1/security/oauth2/token',
|
| 27 |
+
data={
|
| 28 |
+
'grant_type': 'client_credentials',
|
| 29 |
+
'client_id': amadeus_api_key,
|
| 30 |
+
'client_secret': amadeus_api_secret
|
| 31 |
+
}
|
| 32 |
+
)
|
| 33 |
+
auth_data = auth_response.json()
|
| 34 |
+
access_token = auth_data['access_token']
|
| 35 |
+
|
| 36 |
+
# Search for hotels
|
| 37 |
+
search_response = requests.get(
|
| 38 |
+
'https://test.api.amadeus.com/v2/shopping/hotel-offers',
|
| 39 |
+
headers={'Authorization': f'Bearer {access_token}'},
|
| 40 |
+
params={
|
| 41 |
+
'cityCode': city_code,
|
| 42 |
+
'checkInDate': check_in_date,
|
| 43 |
+
'checkOutDate': check_out_date,
|
| 44 |
+
'adults': adults
|
| 45 |
+
}
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
if search_response.status_code == 200:
|
| 49 |
+
hotels = search_response.json()
|
| 50 |
+
return yaml.dump(hotels, default_flow_style=False)
|
| 51 |
+
else:
|
| 52 |
+
return f"Error fetching hotel offers: {search_response.status_code} - {search_response.text}"
|
| 53 |
+
|
| 54 |
@tool
|
| 55 |
def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
|
| 56 |
#Keep this format for the description / args / args description but feel free to modify the tool
|