How to call the ChatGPT API using Python?

Hello everyone, I have a question about calling the GPT-4 API.

I would like the ChatGPT role to assume the persona of a professional and provide a response based on the format of my input. Below is the structure of the program I’ve written.

Could you please confirm if it’s correct?

system_prompt refers to the role I’m asking GPT-4 to assume and the way it should respond to the questions. input_text is the content I’m providing for GPT-4 to respond to.

  • response = openai.ChatCompletion.create(
  • model=“gpt-4”,
  • messages=[
  • {"role": "system", "content": system_prompt},
    
  • {"role": "user", "content": input_text}
    
  • ]
  • )

However, I am still a bit confused about the differences between roles like “system,” “user,” and “assistant.” What are the distinctions between these roles?

Thank you

Looks about right to me, I think.
Generally, anything the assistant outputs has the assistant role, anything the user inputs has the user role, and everything else that your code interjects (with the exception of function result output which has the “function” role) generally comes from ‘system’ (like the system prompt you have there, or other injected information like timestamps or external information fetched through RAG, or bot errors…).