Skip to content

import os
from openai import OpenAI

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

# Define the client
client = OpenAI(api_key=os.environ["OPENAI"])

My objective is to create a chatbot using the OpenAI API to generate responses to the following Parisian tourist questions:

  • How far away is the Louvre from the Eiffel Tower (in miles) if you are driving?

  • Where is the Arc de Triomphe?

  • What are the must-see artworks at the Louvre Museum?

conversation = [
    {
        "role": "system", 
        "content": "You are an expert travel consulant and planner being asked about city of Paris, France."
    }, 
    {
        "role": "user", 
        "content": "How far away is the Louvre from the Eiffel Tower (in miles) if you are driving? // Where is the Arc de Triomphe? //"
    }, 
    {
        "role": "assistant", 
        "content": "The Louvre is X miles away from the Eiffel Tower. // The Arc de Triomphe is located in Y. // Here are some must see artworks at the Louvre Museum: A, B, C"
    }
]

questions = [
    "How far away is the Louvre from the Eiffel Tower (in driving miles)?",
    "Where is the Arc de Triomphe?",
    "What are the must-see artworks at the Louvre Museum?",
]
for question in questions:
    input_dict = {
        "role" : "user",
        "content" : question
    }
    
    conversation.append(input_dict)
    
    response = client.chat.completions.create(
        model=model,
        messages=conversation,
        temperature=0.0,
        max_tokens=120
    )
    
    resp = response.choices[0].message.content
    print(resp)

    # Convert the response into the dictionary
    resp_dict = {"role": "assistant", "content": resp}
    
    # Append the response to the conversation
    conversation.append(resp_dict)