help@rskworld.in +91 93305 39277
RSK World
  • Home
  • Development
    • Web Development
    • Mobile Apps
    • Software
    • Games
    • Project
  • Technologies
    • Data Science
    • AI Development
    • Cloud Development
    • Blockchain
    • Cyber Security
    • Dev Tools
    • Testing Tools
  • Blog
  • About
  • Contact

Theme Settings

Color Scheme
Display Options
Font Size
100%
Back to Project
RSK World
travel-assistant-bot
/
services
RSK World
travel-assistant-bot
Travel Assistant Bot - Python + Flask + OpenAI API + Travel Bot + Flight Search + Hotel Booking + Weather
services
  • __pycache__
  • __init__.py169 B
  • cache.py560 B
  • flight_service.py1.1 KB
  • hotel_service.py971 B
  • openai_service.py1.5 KB
  • recommendation_service.py776 B
  • weather_service.py1.4 KB
openai_service.py
services/openai_service.py
Raw Download
Find: Go to:
# RSK World - Free Programming Resources & Source Code
# Founder: Molla Samser | Designer & Tester: Rima Khatun
# Website: https://rskworld.in/contact.php | Year: 2026
import os
from typing import List, Dict

try:
    from openai import OpenAI  # type: ignore
except Exception:  # pragma: no cover
    OpenAI = None  # fallback when library not present


def _fallback(messages: List[Dict]):
    last = messages[-1]["content"] if messages else ""
    text = last.lower()
    if any(k in text for k in ["flight", "flights", "book flight"]):
        return "To search flights, provide origin, destination, and date."
    if any(k in text for k in ["hotel", "hotels", "stay"]):
        return "To search hotels, provide city, check-in, and check-out dates."
    if "weather" in text:
        return "To get weather, provide a city or location name."
    if any(k in text for k in ["plan", "itinerary"]):
        return "Tell me your trip goals; I can build an itinerary."
    return "I can help with flights, hotels, recommendations, itinerary, and weather."


def generate_response(messages: List[Dict]) -> str:
    api_key = os.getenv("OPENAI_API_KEY")
    if not api_key or not OpenAI:
        return _fallback(messages)
    client = OpenAI(api_key=api_key)
    try:
        chat = client.chat.completions.create(
            model=os.getenv("OPENAI_MODEL", "gpt-4o-mini"),
            messages=messages,
            temperature=0.4,
        )
        return chat.choices[0].message.content or _fallback(messages)
    except Exception:
        return _fallback(messages)

42 lines•1.5 KB
python
🚀 Support RSK World

Subscribe to our YouTube channel for latest tutorials & updates!



Click subscribe & support our work ❤️

About RSK World

Founded by Molla Samser, with Designer & Tester Rima Khatun, RSK World is your one-stop destination for free programming resources, source code, and development tools.

Founder: Molla Samser
Designer & Tester: Rima Khatun

Development

  • Game Development
  • Web Development
  • Mobile Development
  • AI Development
  • Development Tools

Legal

  • Terms & Conditions
  • Privacy Policy
  • Disclaimer

Contact Info

Nutanhat, Mongolkote
Purba Burdwan, West Bengal
India, 713147

+91 93305 39277

hello@rskworld.in
support@rskworld.in

© 2026 RSK World. All rights reserved.

Content used for educational purposes only. View Disclaimer