Advanced Conversations
Context Management and Complex Conversations
10-15 min
Advanced Conversations with the ChatGPT API
Understanding the Message System
The ChatGPT API uses a message system to manage conversations. Each message has a role and content:
const messages = [
{ role: 'system', content: 'Vous êtes un assistant spécialisé en programmation JavaScript.' },
{ role: 'user', content: 'Comment déclarer une variable en JavaScript ?' },
{ role: 'assistant', content: 'En JavaScript, vous pouvez déclarer une variable de trois façons :\n\n1. Avec `var` (déconseillé) :\n```javascript\nvar maVariable = 10;\n```\n\n2. Avec `let` (recommandé pour les variables qui changent) :\n```javascript\nlet maVariable = 10;\n```\n\n3. Avec `const` (pour les valeurs constantes) :\n```javascript\nconst maVariable = 10;\n```' },
{ role: 'user', content: 'Et comment déclarer une fonction ?' }
];
Message Roles
The ChatGPT API recognizes three main roles:
- system: Global instructions that define the assistant's behavior
- user: Messages sent by the user
- assistant: Responses generated by the model
Context Management
To maintain the context of a conversation, you need to keep the message history:
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion