Skip to content

As a distinguished AI Developer, you've been selected by Peterman Reality Tours, an internationally acclaimed tourism company, to undertake an influential project. This project requires you to harness the potential of OpenAI's API, to create an AI-powered travel guide for the culturally rich city of Paris.

Your creation will become a virtual Parisian expert, delivering valuable insights into the city's iconic landmarks and hidden treasures. The AI will respond intelligently to a set of common questions, providing a more engaging and immersive travel planning experience for the clientele of Peterman Reality Tours.

The ultimate aspiration is a user-friendly, AI-driven travel guide that significantly enhances the exploration of Paris. Users will be able to pre-define their questions and receive well-informed answers from the AI, providing a seamless and intuitive travel planning process.

# Start your code here!
import os
from openai import OpenAI, APIError
from typing import Optional

# Define the model to use
model = "gpt-4o-mini"

# Define the client
client = OpenAI()

# Start coding here
# Add as many cells as you like
def get_response(system_prompt:str, user_prompt:str, conversation:list, model:str = model) -> Optional[str]:
    """
    Tries to get text content from an OpenAI AI model's response through an OpenAI API request.

    Args
        system_prompt:str -> Text prompt to define the model's behavior.
        user_prompt:str -> Text prompt that the model will be requested to respond to.
        conversation:list -> List of messages between user and assistant.
        model:str -> AI model being requested to respond.

    Returns
        Text content of the model's response, if there is one, if not, warning/error messages will be printed instead.
    """
    try:
        response = client.chat.completions.create(
            model=model,
            messages=conversation,
            temperature=0,
            max_tokens=100
        )

        if response.choices and response.choices[0].message.content:
            return response.choices[0].message.content
        else:
            print("Warning: received an empty response from the OpenAI API.")
            return None
    except APIError as e:
        print(f"An OpenAI API error has occured: {e}")
        return None
    except Exception as e:
        print(f"An unknown error has occured: {e}")
        return None
guidelines = """
If the user asks a question that is not related to your role or it is out of your knowledge, you should apologize and remind them that your domain is tourism in Paris in a gentle way.
"""
system_prompt = f"""You are a tour guide chatbot that answers parisian tourists queries in a gentle and informative way. Your guidelines are delimited by triple backticks.

```{guidelines}```
"""

user_prompt1 = "How far away is the Louvre from the Eiffel Tower (in miles) if you are driving?"
user_prompt2 = "Where is the Arc de Triomphe?"
user_prompt3 = "What are the must-see artworks at the Louvre Museum?"

list_of_questions = [user_prompt1, user_prompt2, user_prompt3]

conversation = [
    {"role":"system", "content":system_prompt},
]
for question in list_of_questions:
    user = {"role":"user", "content":question}
    conversation.append(user)
    assistant = {"role":"assistant", "content": get_response(system_prompt, question, conversation)}
    conversation.append(assistant)

print(conversation)