liveBook · Manning

Prompt

As explained in Learn Generative AI with PyTorch

The chat message role that sets assistant behavior in the OpenAI chat-completions format.

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

How Learn Generative AI with PyTorch covers it

How deep it goes
Defines role and effect, then demonstrates several behavioral instructions without detailing internal model processing.
Examples
Uses factual answering, essay writing, joke telling, and follow-up conversation as concrete API examples.
What it assumes
Assumes basic Python and API-key setup while introducing message roles through a complete request.
What you can do after
Operate/configure an OpenAI chat completion with a behavior-setting system message and a user request.
How it connects
Links system messages to user messages, assistant messages, conversation history, and chat completions.

Also explained in

Compare how 50 books explain prompt →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Generative AI with PyTorch. The section links point to the parts of the book it draws on.