Teach the AI new tasks by providing examples in the conversation.
1# 4_few_shot_learning.py
2from openai import OpenAI
3client = OpenAI()
4
5print("Teaching the AI a new task (sentiment analysis) with examples...")
6
7messages = [
8 {"role": "system", "content": "You are a sentiment classifier. Respond with only 'Positive', 'Negative', or 'Neutral'."},
9
10 # Example 1
11 {"role": "user", "content": "I love this product!"},
12 {"role": "assistant", "content": "Positive"},
13
14 # Example 2
15 {"role": "user", "content": "This is terrible."},
16 {"role": "assistant", "content": "Negative"},
17
18 # Now, the real question
19 {"role": "user", "content": "It's okay, not great."}
20]
21
22response = client.chat.completions.create(
23 model="gpt-4o-mini",
24 messages=messages
25)
26
27print(f"\nAI's classification for 'It's okay, not great.':")
28print(response.choices[0].message.content)No output yet...