Dino Geek, try to help you

How to maintain the context of a conversation with the ChatGPT API?


You can maintain the context in a conversation with the ChatGPT API by including the conversation history in the ‘messages’ parameter when making a request to the API. You should include not only the user’s messages, but also the assistant’s responses to ensure the model has full context.

Each message object should have a ‘role’ field that can be ‘system’, ‘user’, or ‘assistant’, and a ‘content’ field for the text of the message from the role. The ‘system’ message usually sets the behavior of the assistant at the start of the conversation.

Here is an example of a conversation with 2 user messages and 2 assistant messages:

```
‘messages’:[ {role: ‘system’, content: ‘You are a helpful assistant.’}, {role: ‘user’, content: ‘Who won the world series in 2020?’}, {role: ‘assistant’, content: ‘The Los Angeles Dodgers won the World Series in 2020.’}, {role: ‘user’, content: ‘Where was it played?’}, {role: ‘assistant’, content: ‘The 2020 World Series was played in Arlington, Texas at the Globe Life Field, which was the new home stadium for the Texas Rangers.’}
]
```

The assistant will respond according to the full history, so it’ll answer appropriately taking into account of previous messages. The conversation history should also be in chronological order.

Keep in mind that very long conversations are more likely to receive incomplete replies – for instance, if a conversation has 4096 tokens and you add one more message, the oldest message might be truncated.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use