Zero-shot prompting with reviews
As well as answering questions, transforming text, and generating new text, OpenAI's models can also be used for classification tasks, such as categorization and sentiment analysis.
In this exercise, you'll explore using OpenAI's chat models for sentiment classification using reviews from an online shoe store called Toe-Tally Comfortable.
Latihan ini adalah bagian dari kursus
Working with the OpenAI API
Petunjuk latihan
- Define a
promptto classify the sentiment of the statements provided using the numbers1to5(positive to negative). - Create a request to the Chat Completions endpoint to send this prompt to
gpt-4o-mini.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
client = OpenAI(api_key="")
# Define a multi-line prompt to classify sentiment
prompt = """____:
1. Unbelievably good!
2. Shoes fell apart on the second use.
3. The shoes look nice, but they aren't very comfortable.
4. Can't wait to show them off!"""
# Create a request to the Chat Completions endpoint
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": ____}],
max_completion_tokens=100
)
print(response.choices[0].message.content)