✈️ Travel Suggestion
GPT-4o mini via OpenAI
Concept
This demo asks an LLM to suggest one thing to do in a city you name. It uses OpenAI's GPT-4o mini because the task is open-ended creative writing that benefits from strong instruction-following, while staying cheap and fast enough for an interactive demo.
A short system prompt ("You are a witty travel guide") gives the model a consistent persona for every request, and the user prompt asks for exactly one suggestion so the reply stays short enough to fit in the result card.
Theory & Concepts
Prompt Engineering for UI Constraints
The Travel Suggestion demo illustrates how careful prompt design can adapt LLM outputs to fit specific application requirements:
- Enforcing Brevity: In a UI designed around compact result cards, long-winded answers break the layout. By explicitly structuring the user prompt as "Suggest one thing to do in {city}", we force the GPT-4o mini model to narrow its focus. This guarantees a concise, punchy response that fits perfectly into the demo's visual design.
- Stateless Persona Maintenance: Every time you click "Suggest something," the backend makes a fresh, isolated API call. Because the OpenAI API is stateless, it doesn't remember your previous city searches. Therefore, we must inject the system prompt ("You are a witty travel guide.") into every single request to guarantee the tone remains consistently playful, regardless of how many times you use the tool.
Request flow
Code flow
city] -->|POST /travel| B[app.py
travel route] B -->|city| C[travel.py
get_travel_suggestion] C -->|prompt| D[OpenAI API
GPT-4o mini] D -->|suggestion| C C -->|suggestion| B B -->|JSON result| A
Backend
Generates the suggestion via OpenAI's chat completions API.from config import get_openai_client
# gpt-4o-mini: fast, cheap, and good enough for a short creative reply.
TRAVEL_MODEL = "gpt-4o-mini"
def get_travel_suggestion(city: str = "Bangalore") -> str:
client = get_openai_client()
response = client.chat.completions.create(
model=TRAVEL_MODEL,
messages=[
{
"role": "system",
# A brief persona keeps every response short and fun.
"content": "You are a witty travel guide.",
},
{
"role": "user",
# Asking for exactly one suggestion keeps the reply concise.
"content": f"Suggest one thing to do in {city}.",
},
],
)
return response.choices[0].message.content
API route
Exposes the travel suggester over HTTP asPOST /travel.
@bp.route("/travel", methods=["POST"])
def travel():
data = request.get_json(force=True)
# Fall back to Bangalore so the demo always has a usable city.
city = (data.get("city") or "").strip() or "Bangalore"
try:
text = get_travel_suggestion(city)
return jsonify({"result": text})
except Exception as e:
return jsonify({"error": str(e)}), 500