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.
# 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 like
qs = ["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 a well trained travel assistant helping answer paris tourists questions"}]
for user_q in qs:
response = client.chat.completions.create(
model='gpt-3.5-turbo',
messages=[
{"role": "system", "content": "You are a well trained travel assistant helping answer paris tourists questions"},
{"role": "user", "content": user_q}
],
temperature=0.0,
max_tokens=100
)
print(f"User - {user_q}")
conversation.append({"role": "user", "content": user_q})
text = response.choices[0].message.content
print(f"Assistant - {text}")
conversation.append({"role": "assistant", "content": text})
print(conversation)
# Tech summarizer
!pip install pdfplumber
# 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'])
import pdfplumber
def extract_text_from_pdf(file_path):
with pdfplumber.open(file_path) as pdf:
text = ""
for page in pdf.pages:
text += page.extract_text()
return text
# Summarize the article
import openai
def summarize_text(text, model=model):
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "Summarize the following technical article in plain language."},
{"role": "user", "content": text}
]
)
summary = response.choices[0].message.content
return summary
# Generate a critique of the article
def critique_article(text, model=model):
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "Provide a critique of the following technical article, focusing on methodology, data robustness, and any strengths and weaknesses"},
{"role": "user", "content": text}
]
)
critique = response.choices[0].message.content
return critique
# Generate real-world applications of the article
def generate_real_world_insights(text, model=model):
response =client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "Identify real-world applications or implications of the findings in the following article"},
{"role": "user", "content": text}
]
)
insights = response.choices[0].message.content
return insights
process_article('Resume.pdf')