A system prompt is a message whose role is "system" and whose content sets the assistant’s behavior in an OpenAI chat-completions request. Without one, the assistant defaults to being helpful. section 16.1.1
Use the message roles to separate behavioral instructions from the request and response:
- System messages describe how the assistant should behave, such as being knowledgeable about recent facts, writing essays, or telling jokes. section 16.1.1
- User messages contain questions or remarks for the assistant to address. section 16.1.1
- Assistant messages represent generated responses and can participate in back-and-forth conversation through conversation history. section 16.1.1
Set a factual-answering behavior
Place a system message before the user’s question: {"role": "system", "content": "You are a helpful assistant, knowledgeable about recent facts."}. Then add {"role": "user", "content": "Who won the Nobel Prize in Economics in 2000?"}. section 16.1.1
Listing 16.1 Checking historical facts with OpenAI API
from openai import OpenAI
openai_api_key=put your actual OpenAI API key here, in quotes #1
client=OpenAI(api_key=openai_api_key) #2
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": #3
'''You are a helpful assistant, knowledgeable about recent facts.'''},
{"role": "user", "content":
'''Who won the Nobel Prize in Economics in 2000?'''} #4
]
)
print(completion.choices[0].message.content)
Inspect a complete Python request showing the OpenAI client, model selection, system prompt, user message, and printed response. section 16.1.1

















































