OpenAI API - Chat Completions Exercise
Exercise 1: Basic Interaction with the Chat Model
Your first task is to have an introductory conversation with the model. Ask about its abilities, strengths, and limitations. This will give you a taste of basic interaction with OpenAIâs chat model.
Exercise 2: Exploring System and User Roles
In this exercise, try defining user and system roles in messages. Your task is to use âsystemâ and âuserâ as roles.
Example:
python
import openaiopenai.ChatCompletion.create(model="gpt-3.5-turbo",messages=[{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "Who won the world series in 2020?"},])
Exercise 3: System Role Constraints
Modify the system role further. Test how explicit and directive you must be. Create context where the model behaves as a Shakespearean character, a sci-fi novel writer, or a sports commentator.
Example:
python
openai.ChatCompletion.create(model="gpt-3.5-turbo",messages=[{"role": "system", "content": "You are an assistant that speaks like Shakespeare."},{"role": "user", "content": "Tell me about the weather today."},])
Try with different characters and observe how the model responds.
Exercise 4: Using Temperature and Top-P
Start configuring the modelâs response using temperature
and top_p
. Choose a fixed instruction and adjust these parameters for different outputs.
- Try a high and a low temperature. What changes do you see in terms of diversity of output?
- Next, adjust âtop_pâ. What changes do you see in terms of focus and variability of output?
Document your findings.
Exercise 5: Creative Control
Create a âChoose your own adventureâ story using the chat model. Begin the story by setting the adventureâs context and let the model suggest the next events. Use the âsystemâ role to direct the storyline. This exercise will test your understanding of how to use the âsystemâ role creatively.
Remember, iterative learning and repeated experimenting with the parameters will provide the best understanding. Have fun!