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, specifically using its state-of-the-art language model, GPT-3.5 Turbo, 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.
Before you start
In order to complete the project you will need to create a developer account with OpenAI and store your API key as an environment variable. Instructions for these steps are outlined below.
Create a developer account with OpenAI
-
Go to the API signup page.
-
Create your account (you'll need to provide your email address and your phone number).
-
Go to the API keys page.
-
Create a new secret key.
- Take a copy of it. (If you lose it, delete the key and create a new one.)
Add a payment method
OpenAI sometimes provides free credits for the API, but this can vary based on geography. You may need to add debit/credit card details.
Using the gpt-3.5-turbo model in this project should incur a cost less than 1 US cent (but if you rerun tasks, you will be charged every time). For more information on pricing, see OpenAI's pricing page.
-
Go to the Payment Methods page.
-
Click Add payment method.
- Fill in your card details.
Add an environment variable for your OpenAI key
-
In the Workbook, click on "Environment," in the left sidebar.
-
Click on the plus button next to "Environment variables" to add environment variables.
-
In the "Name" field, type "OPENAI". In the "Value" field, paste in your secret key.
- Click "Create", then you'll see the following pop-up window. Click "Connect," then wait 5-10 seconds for the kernel to restart, or restart it manually in the Run menu.
1 - Setting your API key as an evironment variable
2 - Defining the model and client
# Start your code here!
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'])
# Define the temperature - greater determinism
temperature = 0.0
# Define the maximum number of tokens
# max_tokens = 100
# Start coding here
# Add as many cells as you like# # Start your code here!
# import os
# from openai import OpenAI
# # Define the model to use
# model = "gpt-3.5-turbo"
# # Define the client
# client = OpenAI(api_key=os.environ["OPENAI"])
# # Start coding here
# # Add as many cells as you like3 - Defining the conversation
# Initialize the conversation
conversation = [{'role': 'system',
'content': 'You will help with training individuals preparing for a Financial Systems Manager job interview at a nonprofit organization.'}]
user_msgs = ['What qualities stand out for a Financial Systems Manager role?',
'What should I say I want to improve for the company?',
"What if I don't meet every requirement?",
'How should I prepare for the interview?']# Initialize the conversation
conversation = [{'role': 'system',
'content': 'You are a helpful Paris, France tourist guide expert.'}]
user_msgs = ['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?']4 - Creating a conversation loop
# Initialize the for loop
for q in user_msgs:
print('User: ', q)
# Create a dictionary for the user message from q and append to conversation
user_dict = {'role': 'user', 'content': q}
conversation.append(user_dict)
# Create the API request
response = client.chat.completions.create(
model=model,
messages=conversation,
temperature=temperature,
# max_tokens=max_tokens
)
# Convert the assistant's message to a dict and append to conversation
assistant_dict = {'role': 'assistant', 'content': response.choices[0].message.content}
conversation.append(assistant_dict)
print('Assistant: ', response.choices[0].message.content, '\n')