-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_plan.py
More file actions
308 lines (265 loc) · 11 KB
/
Copy pathtest_plan.py
File metadata and controls
308 lines (265 loc) · 11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
"""
Dream Destiny - Manual Test Client
===================================
Edit the TRIP_REQUEST block below and run:
python test_plan.py
Make sure all 6 services are running first:
Port 8000 - planner-service (uvicorn main:app --port 8000)
Port 8001 - tourism-service (uvicorn main:app --port 8001)
Port 8002 - hotel-service (uvicorn app.main:app --port 8002)
Port 8003 - route-service (uvicorn app.main:app --port 8003)
Port 8004 - bus-service (uvicorn app.main:app --port 8004)
Port 8005 - train-service (uvicorn app.main:app --port 8005)
"""
import json
import sys
import time
import urllib.request
import urllib.error
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8")
# ==============================================================================
# EDIT THIS BLOCK TO CHANGE YOUR TEST INPUT
# ==============================================================================
TRIP_REQUEST = {
"origin": "panipat",
"destination": "rajapalayam",
"start_date": "2026-10-15",
"end_date": "2026-10-18",
"travelers": 2,
"preferences": {
# Budget level: "low" | "medium" | "high"
"budget": {
"level": "medium"
},
# Transport mode : "train" | "bus" | "flight" | "any"
# Berth/class : "1A" (First AC) | "2A" (Second AC) | "3A" (Third AC) | "CC" (Chair Car)
# "SL" (Sleeper) | "2S" (Second Sitting) | "GN" (General)
# "any" or null -> show all available classes
"transport": {
"mode": "flight",
"berth_preference": "any"
},
# Hotel category: "budget" | "mid_range" | "luxury" | "any"
"hotel": {
"category": "mid_range"
},
# Travel pace: "relaxed" | "moderate" | "intensive"
"activities": {
"pace": "moderate",
"interests": ["history", "nature"],
"family_friendly": None,
"accessibility": None,
},
# Food preferences (optional - uncomment if needed)
# "food": {
# "dietary_restrictions": "none", # "none"|"vegetarian"|"vegan"|"halal"|"gluten_free"
# "cuisines": ["South Indian"],
# "avoid_street_food": False
# }
}
}
# ==============================================================================
# WHICH ENDPOINT TO HIT
# ==============================================================================
# POST /plan -> Full AI itinerary (Gemini 2.5 Flash decides everything)
# POST /plan/context -> Raw aggregated data only (no LLM, instant)
ENDPOINT = "http://localhost:8000/plan"
#ENDPOINT = "http://localhost:8000/plan/context"
# ==============================================================================
def call_api(endpoint, body):
data = json.dumps(body, default=str).encode("utf-8")
req = urllib.request.Request(
endpoint,
data=data,
headers={"Content-Type": "application/json"},
method="POST",
)
with urllib.request.urlopen(req, timeout=120) as resp:
return json.loads(resp.read().decode("utf-8"))
def print_transport_block(label, t):
if not t:
return
print()
print(" " + label)
# Instruction line
instr = t.get("instruction")
if instr:
print(" >> %s" % instr)
dep_stn = t.get("departure_station") or ""
arr_stn = t.get("arrival_station") or ""
is_direct = t.get("is_direct", True)
tag = "[DIRECT]" if is_direct else "[BOARD FROM HUB/NEARBY CITY]"
if dep_stn or arr_stn:
print(" Route : %s -> %s %s" % (dep_stn or "?", arr_stn or "?", tag))
if t.get("mode") == "flight":
print(" Flight : %s (%s) - %s" % (t.get("flight_number", "?"), t.get("flight_id", "?"), t.get("airline", "?")))
print(" Schedule: Departs %s @ %s -> Arrives %s @ %s" % (
t.get("departure_date", ""), t.get("departure_time", "?"),
t.get("arrival_date", ""), t.get("arrival_time", "?")
))
print(" Details : Class: %s | Fare: Rs.%s/person" % (
t.get("travel_class", "?"),
t.get("fare_per_person", "?")
))
elif t.get("mode") == "train":
print(" Train : %s - %s" % (t.get("train_number", "?"), t.get("train_name", "?")))
print(" Schedule: Departs %s @ %s -> Arrives %s @ %s" % (
t.get("departure_date", ""), t.get("departure_time", "?"),
t.get("arrival_date", ""), t.get("arrival_time", "?")
))
print(" Details : Class: %s | Seats: %s %s | Rs.%s/person" % (
t.get("travel_class", "?"),
t.get("seats_available", "?"),
t.get("seat_status", ""),
t.get("fare_per_person", "?")
))
else:
print(" Bus : %s - %s" % (t.get("operator_name", "?"), t.get("bus_type", "?")))
print(" Schedule: Departs @ %s -> Arrives @ %s" % (
t.get("departure_time", "?"), t.get("arrival_time", "?")))
print(" Details : Seats: %s | Rs.%s/person" % (
t.get("seats_available", "?"), t.get("fare_per_person", "?")))
if t.get("reasoning"):
print(" Reason : %s" % t.get("reasoning"))
def print_itinerary(res):
s = res.get("summary", {})
print()
print("=" * 65)
print(" TRIP: %s -> %s" % (s.get("origin"), s.get("destination")))
print(" Days: %s | Travelers: %s" % (s.get("days"), s.get("travelers")))
print(" Pace: %s | Budget: %s" % (s.get("pace"), s.get("budget_level")))
print("=" * 65)
hotel = res.get("hotel")
if hotel:
print()
print(" HOTEL SELECTED")
print(" Name : %s" % hotel.get("hotel_name"))
print(" ID : %s" % hotel.get("hotel_id"))
if hotel.get("reasoning"):
print(" Reason : %s" % hotel.get("reasoning"))
ob = res.get("outbound_transport")
print_transport_block(
"OUTBOUND TRANSPORT (%s)" % (ob.get("leg", "") if ob else ""),
ob
)
rb = res.get("return_transport")
print_transport_block(
"RETURN TRANSPORT (%s)" % (rb.get("leg", "") if rb else ""),
rb
)
print()
print(" DAY-BY-DAY ITINERARY")
for day in res.get("days", []):
date_str = "(%s)" % day.get("date", "") if day.get("date") else ""
theme = day.get("theme") or ""
print()
print(" -- Day %d %s %s" % (day["day"], date_str, theme))
for act in day.get("activities", []):
t = act.get("start_time") or "--:--"
d = act.get("duration_minutes")
dur = "%dmin" % d if d else "?"
print(" %s %s (%s)" % (t, act["attraction_name"], dur))
if act.get("notes"):
print(" -> %s" % act["notes"])
for leg in day.get("transport", []):
print(" [TRANSPORT] %s - %s" % (leg.get("mode"), leg.get("leg", "")))
cb = res.get("cost_breakdown")
if cb:
print()
print(" COST BREAKDOWN (%s)" % cb.get("currency", "INR"))
print(" Transport Cost : Rs. %s" % cb.get("transport_cost", 0))
print(" Hotel Cost : Rs. %s" % cb.get("hotel_cost", 0))
print(" Activities Est. : Rs. %s" % cb.get("activities_estimated_cost", 0))
print(" -----------------------------------------")
print(" TOTAL TRIP COST : Rs. %s" % cb.get("total_cost", 0))
elif res.get("total_cost"):
print("\n TOTAL TRIP COST : Rs. %s" % res.get("total_cost"))
notes = res.get("planning_notes")
if notes:
print()
print(" PLANNING NOTES")
print(" %s" % notes)
print()
print("=" * 65)
print()
def print_context(res):
ctx = res.get("context", res)
status = ctx.get("service_status", {})
print()
print("=" * 65)
print(" RAW TRIP CONTEXT (no LLM)")
print("=" * 65)
print(" Service status : %s" % status)
print(" Attractions : %d" % len(ctx.get("attractions", [])))
print(" Hotels : %d" % len(ctx.get("hotels", [])))
print(" Outbound trains : %d" % len(ctx.get("outbound_trains", [])))
print(" Return trains : %d" % len(ctx.get("return_trains", [])))
print(" Outbound buses : %d" % len(ctx.get("outbound_buses", [])))
print(" Return buses : %d" % len(ctx.get("return_buses", [])))
print(" Outbound flights : %d" % len(ctx.get("outbound_flights", [])))
print(" Return flights : %d" % len(ctx.get("return_flights", [])))
route = ctx.get("route")
if route:
print(" Route distance : %s km" % route.get("distance_km"))
for r in route.get("routes", []):
print(" %-12s -> %s min" % (r.get("mode"), r.get("duration_minutes")))
print()
if ctx.get("outbound_flights"):
print(" Top Outbound Flights:")
for f in ctx.get("outbound_flights", [])[:3]:
print(" %s %s (%s) | %s -> %s | Rs.%s" % (
f.get("airline"), f.get("flight_number"), f.get("flight_id"),
f.get("departure_time"), f.get("arrival_time"), f.get("price")
))
print()
print()
print(" Top Attractions:")
for a in ctx.get("attractions", [])[:5]:
print(" %s* %s" % (a.get("rating", "?"), a.get("name")))
print()
print(" Top Hotels:")
for h in ctx.get("hotels", [])[:5]:
price = h.get("price", {}).get("per_night")
price_str = "Rs.%s/night" % price if price else "price N/A"
print(" %s* %s (%s)" % (h.get("rating", "?"), h.get("name"), price_str))
print()
def main():
transport = TRIP_REQUEST["preferences"]["transport"]
activities = TRIP_REQUEST["preferences"]["activities"]
print()
print("Endpoint : %s" % ENDPOINT)
print("Request : %s -> %s" % (TRIP_REQUEST["origin"], TRIP_REQUEST["destination"]))
print("Dates : %s to %s" % (TRIP_REQUEST["start_date"], TRIP_REQUEST["end_date"]))
print("Travelers: %d" % TRIP_REQUEST["travelers"])
print("Mode : %s" % transport.get("mode"))
print("Berth : %s" % transport.get("berth_preference", "any (not set)"))
print("Pace : %s" % activities.get("pace"))
print("Interests: %s" % activities.get("interests"))
print()
print("Calling API (this may take 20-40s for /plan with LLM)...")
t0 = time.time()
try:
res = call_api(ENDPOINT, TRIP_REQUEST)
except urllib.error.HTTPError as e:
body = e.read().decode("utf-8")
print("\n HTTP %d Error: %s" % (e.code, body))
return
except urllib.error.URLError as e:
print("\n Connection error: %s" % e.reason)
print(" Are all 6 services running?")
return
elapsed = time.time() - t0
print("Done in %.1fs" % elapsed)
if "context" in ENDPOINT or res.get("context"):
print_context(res)
else:
print_itinerary(res)
try:
dump = input("Dump full JSON? (y/N): ").strip().lower()
if dump == "y":
print(json.dumps(res, indent=2, ensure_ascii=False))
except (EOFError, KeyboardInterrupt):
pass
if __name__ == "__main__":
main()