The way prompts are used in the ChatGPT interface and the API is different. ChatGPT is a trained model, while the API is a base model, so their prompts are different. You need to learn the API's prompting method separately to get answers that meet expectations.
Prompting method
To have more interactive and dynamic conversations with OpenAI models, you can use messages in chat format rather than traditional sentence-style prompting.
How it works:
Instead of sending a single string as a prompt, you send a series of messages as input.
Each message in the list has attributes: role and content.
"Role" can take one of three values: "system", "user", or "assistant"
"Content" contains the message text from the role.
System instructions can provide high-level instructions for the conversation.
Messages are processed in the order they appear in the list, and the assistant responds accordingly.
Even basic requests can be made through chat, as shown below:
Now, by extending the list of messages in the conversation, communicating with the model has become easier than ever.
'messages': [{'role':'user', 'content':'Tell me a joke'},
{'role':'assistant', 'content':'Why did the chicken cross the road'},
{'role':'user', 'content':'I do not know, why did the chicken cross the road'}]
System instructions
You can also use system-level instructions to guide the model's behavior throughout the conversation. For example, use system instructions and messages like this
'messages': [{'role':'system', 'content':'You are an assistant who speaks like Shakespeare.'},
{'role':'user', 'content':'Tell me a joke'},
Similar to
{...
'message':{'role':'assistant',
'content':'Why did the chicken cross the road? To get to the other side, but in fact, the other side is full of danger and peril, so it quickly returned to where it came from, really!'}
...}
|