NIUBOYI»Home › › › Chatgpt帮助文档 › 中文 | English
微信扫一扫 分享朋友圈

已有 1821 人浏览分享

[api设置]    How to Use Chat-Style Prompts with the OpenAI API: A Precursor to Fine-Tuning

api设置 2024-6-6 17:00:511821 0
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:

微信截图_20240606170216.png

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!'}
...}
  • WeChat Official Account

  • Scan to Visit Mobile Site

QQ|NIUBOYI ( 京ICP备17025393号 )|网站地图

GMT+8, 2026-10-31 07:15 , Processed in 0.047880 second(s), 41 queries .

POWERED BY NIUBOYIAI! 主理人:NIUBOYIAI  点亮哥

Copyright © 2001-2020, NIUBOYI AI.