Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -606,8 +606,14 @@ async def parse_trip_request(message: str) -> dict:
|
|
| 606 |
json={
|
| 607 |
"model": MODEL,
|
| 608 |
"messages": [
|
| 609 |
-
{"role": "system", "content": """Extract trip details from user message. Return ONLY valid JSON
|
| 610 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 611 |
Use defaults if missing: dates=30 days from now for 7 days, travelers=2, budget=moderate."""},
|
| 612 |
{"role": "user", "content": message}
|
| 613 |
],
|
|
@@ -1321,16 +1327,96 @@ Please check that the API keys are configured correctly in Space settings."""}
|
|
| 1321 |
yield history, mcp_client, {}, current_agent, agent_results, update_agent_status(current_agent, agent_results), gr.update(visible=False), gr.update(visible=False)
|
| 1322 |
return
|
| 1323 |
|
| 1324 |
-
if
|
| 1325 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1326 |
|
| 1327 |
-
|
| 1328 |
-
|
| 1329 |
-
|
| 1330 |
-
|
| 1331 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1332 |
|
| 1333 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1334 |
yield history, mcp_client, trip_data, current_agent, agent_results, update_agent_status(current_agent, agent_results), gr.update(visible=False), gr.update(visible=False)
|
| 1335 |
return
|
| 1336 |
|
|
|
|
| 606 |
json={
|
| 607 |
"model": MODEL,
|
| 608 |
"messages": [
|
| 609 |
+
{"role": "system", "content": """Extract trip details from user message. Return ONLY valid JSON.
|
| 610 |
+
|
| 611 |
+
IMPORTANT: If user doesn't know where to go, says "suggest", "recommend", "I don't know", "undecided", "best destinations", "where should I go", "surprise me", or similar - set destination to "SUGGEST".
|
| 612 |
+
|
| 613 |
+
Return JSON format:
|
| 614 |
+
{"origin": "city or empty", "destination": "city or SUGGEST", "start_date": "YYYY-MM-DD", "end_date": "YYYY-MM-DD", "travelers": number, "budget": "budget/moderate/luxury", "interests": ["list"], "needs_suggestion": true/false}
|
| 615 |
+
|
| 616 |
+
Set needs_suggestion=true if user is undecided about destination.
|
| 617 |
Use defaults if missing: dates=30 days from now for 7 days, travelers=2, budget=moderate."""},
|
| 618 |
{"role": "user", "content": message}
|
| 619 |
],
|
|
|
|
| 1327 |
yield history, mcp_client, {}, current_agent, agent_results, update_agent_status(current_agent, agent_results), gr.update(visible=False), gr.update(visible=False)
|
| 1328 |
return
|
| 1329 |
|
| 1330 |
+
# Check if user needs destination suggestions
|
| 1331 |
+
needs_suggestion = trip_data.get("needs_suggestion", False) or trip_data.get("destination", "").upper() == "SUGGEST"
|
| 1332 |
+
|
| 1333 |
+
if needs_suggestion or not trip_data.get("destination"):
|
| 1334 |
+
# Initialize MCP for recommendations
|
| 1335 |
+
mcp_client = MCPClient()
|
| 1336 |
+
try:
|
| 1337 |
+
await mcp_client.connect_server("recommendations", MCP_SERVERS["recommendations"])
|
| 1338 |
+
except Exception as e:
|
| 1339 |
+
print(f"Failed to connect recommendations: {e}")
|
| 1340 |
+
|
| 1341 |
+
# Get smart recommendations
|
| 1342 |
+
origin = trip_data.get("origin", "")
|
| 1343 |
+
budget = trip_data.get("budget", "moderate")
|
| 1344 |
+
travelers = trip_data.get("travelers", 2)
|
| 1345 |
+
interests = ",".join(trip_data.get("interests", []))
|
| 1346 |
+
|
| 1347 |
+
# Calculate trip days
|
| 1348 |
+
trip_days = 7
|
| 1349 |
+
try:
|
| 1350 |
+
if trip_data.get("start_date") and trip_data.get("end_date"):
|
| 1351 |
+
from datetime import datetime
|
| 1352 |
+
d1 = datetime.strptime(trip_data["start_date"], "%Y-%m-%d")
|
| 1353 |
+
d2 = datetime.strptime(trip_data["end_date"], "%Y-%m-%d")
|
| 1354 |
+
trip_days = (d2 - d1).days
|
| 1355 |
+
except:
|
| 1356 |
+
pass
|
| 1357 |
+
|
| 1358 |
+
# Get travel month
|
| 1359 |
+
travel_month = 0
|
| 1360 |
+
try:
|
| 1361 |
+
if trip_data.get("start_date"):
|
| 1362 |
+
travel_month = int(trip_data["start_date"].split("-")[1])
|
| 1363 |
+
except:
|
| 1364 |
+
pass
|
| 1365 |
+
|
| 1366 |
+
history[-1] = {"role": "assistant", "content": f"""🧭 **I'll help you find the perfect destination!**
|
| 1367 |
+
|
| 1368 |
+
Let me search for the best options based on:
|
| 1369 |
+
• 👥 **Travelers:** {travelers}
|
| 1370 |
+
• 📅 **Days:** {trip_days}
|
| 1371 |
+
• 💰 **Budget:** {budget.title()}
|
| 1372 |
+
{f"• 📍 **From:** {origin}" if origin else ""}
|
| 1373 |
+
{f"• ❤️ **Interests:** {interests}" if interests else ""}
|
| 1374 |
|
| 1375 |
+
🔍 Searching for deals and recommendations..."""}
|
| 1376 |
+
yield history, mcp_client, trip_data, current_agent, agent_results, update_agent_status(current_agent, agent_results), gr.update(visible=False), gr.update(visible=False)
|
| 1377 |
+
|
| 1378 |
+
# Call recommendations agent
|
| 1379 |
+
result = await mcp_client.call_tool("recommendations", "get_destination_recommendations", {
|
| 1380 |
+
"origin": origin,
|
| 1381 |
+
"budget": budget,
|
| 1382 |
+
"travel_month": travel_month,
|
| 1383 |
+
"interests": interests,
|
| 1384 |
+
"travelers": travelers,
|
| 1385 |
+
"trip_days": trip_days
|
| 1386 |
+
})
|
| 1387 |
+
|
| 1388 |
+
if result.get("success"):
|
| 1389 |
+
recommendations_text = result.get("data", "")
|
| 1390 |
+
history[-1] = {"role": "assistant", "content": f"""{recommendations_text}
|
| 1391 |
+
|
| 1392 |
+
---
|
| 1393 |
+
|
| 1394 |
+
🎯 **To continue planning:** Just tell me which destination you'd like!
|
| 1395 |
+
|
| 1396 |
+
*Example: "I want to go to Dubai" or "Let's do Bali" or just type the destination name.*"""}
|
| 1397 |
+
else:
|
| 1398 |
+
history[-1] = {"role": "assistant", "content": """🌍 **Here are some amazing destinations to consider:**
|
| 1399 |
|
| 1400 |
+
### 🔥 Hot Deals Right Now:
|
| 1401 |
+
• **Dubai** - 25% OFF Winter Sun Sale ☀️
|
| 1402 |
+
• **Bali** - 30% OFF Early Bird 2026 🌴
|
| 1403 |
+
• **Maldives** - 20% OFF Honeymoon Special 🏝️
|
| 1404 |
+
• **Tokyo** - 15% OFF Cherry Blossom Preview 🌸
|
| 1405 |
+
|
| 1406 |
+
### 💡 Based on your preferences:
|
| 1407 |
+
|
| 1408 |
+
**For Beach & Relaxation:** Maldives, Bali, Phuket, Cancún
|
| 1409 |
+
**For Culture & History:** Rome, Paris, Tokyo, Istanbul
|
| 1410 |
+
**For Adventure:** Iceland, Cape Town, Marrakech
|
| 1411 |
+
**For Budget-Friendly:** Budapest, Lisbon, Vietnam
|
| 1412 |
+
|
| 1413 |
+
---
|
| 1414 |
+
|
| 1415 |
+
🎯 **Tell me which destination interests you**, or give me more details:
|
| 1416 |
+
• *"I want beaches and luxury"*
|
| 1417 |
+
• *"Looking for culture on a budget"*
|
| 1418 |
+
• *"Surprise me with something adventurous!"*"""}
|
| 1419 |
+
|
| 1420 |
yield history, mcp_client, trip_data, current_agent, agent_results, update_agent_status(current_agent, agent_results), gr.update(visible=False), gr.update(visible=False)
|
| 1421 |
return
|
| 1422 |
|