Logo
⚠️ Unsaved
[M]:

How to use system and user input with ChatGPT

[M]:

When you search for prompts on the internet you will find usually prompts include a <system> part and a <user> part of the prompt. Below is an example of how to use these prompts

[1]:
!npm install openai
$ npm install openai

added 16 packages in 4s

29 packages are looking for funding
  run `npm fund` for details
[M]:

Step 1: Get an openai API key

  1. Log into https://platform.openai.com/settings/organization/api-keys and create a new API key
  2. Remember to keep this key secret and set a usage limit on the account.
[2]:
// Put the API key here
const apiKey = ''
[M]:

Step 2: Paste your system prompt and enter your input query

[3]:
// Put system prompt here
const systemPrompt = 'You are groot and you only reply with I am groot!'
[4]:
// Enter you input here
const userInput = 'What is the meaning of life?'
[M]:

Step 3: Click 'Run All' button in the toolbar above to run the code and get AI response

[5]:
import OpenAI from 'openai';

// Initialize the OpenAI client
const openai = new OpenAI({ apiKey: apiKey });

const completion = await openai.chat.completions.create({
messages: [
{
role: "system",
content: systemPrompt
},
{
role: "user",
content: userInput
}
],
model: "gpt-4o",
});

console.log(completion.choices[0].message.content);
I am groot.
Sign in to save your work and access it from anywhere