-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat_roles.py
More file actions
64 lines (53 loc) · 2.38 KB
/
chat_roles.py
File metadata and controls
64 lines (53 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Single-turn tasks
# - Text Generation
# - Text transformation
# - Classification
# Multi-turn conversations
# - Build on previous prompts and responses
# Roles
# - System : Controls assistant's behavior (e.g. Important Template Formatting)
# - User : Instruct the assistant (e.g. Example Conversations)
# - Assistant : response to user instruction (e.g. Context Required For The New Input [often single-turn])
# Can also be written by the developer to provide examples
# Just a note not included in the actual code
default_response_sample = """
response = client.chat.completions.create(
model="gpt-4o-mini",
message=[{"role": "user", "content": prompt}]
)
"""
# First Example : Prompt Setup (Putting The Roles In Messages)
messages=[{"role": "system", "content": "You are a Python programming tutor who speaks concisely."},
{"role": "user", "content": "What is the difference between mutable and immutable objects?"}]
# Apply To Request Response
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "system", "content": "You are a Python programming tutor who speaks concisely."},
{"role": "user", "content": "What is the difference between mutable and immutable objects?"}]
)
# Second Example : Mitigating Misuse With System Messages
sys_msg = """
You are finance education assistant that helps student study for exams.
If you are asked for specific, real-world financial advice with risk to their finances, respond with:
I'm sorry, I am not allowed to provide financial advice.
"""
# Adding the Mitigating Misuse With System Messages
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "system", "content": sys_msg},
{"role": "user", "content": "Which stocks should I invest in?"}]
)
# Utilizing assistant role
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "system",
"content": "You are a Python programmign tutor who speaks concisely."},
{"role": "user",
"content": "How do you define a Python List?"},
{"role": "assistant",
"content": "Lists are defined by enclosing a comma-separated sequence of objects inside square brackets [ ]."},
{"role": "user",
"content": "What is the difference between mutable and immutable objects?"}]
)
# Show output
print(response.choices[0].message.content)