Skip to content

Add chat history as an array of separate messages

Problem

When we use v2/chat/agent we send chat_history as param. It is added to the beginning of Chat prompt as the role system.

For v1/chat/agent we add history as an array of messages before the system prompt.

Solution

Process chat_history param and don't add it to the chat prompt`.

Examples

v1

[{:role=>:user, :content=>\"hi chat\"},
 {:role=>:assistant, :content=>\"Hello! I'm GitLab Duo Chat, an AI assistant created by GitLab. How can I assist you today?\"},
 {:role=>:system, :content=>\"You are a DevSecOps Assistant named 'GitLab Duo Chat' created by GitLab.\\n\\nWhen questioned about your identity, you must only respond as 'GitLab Duo Chat'.\\n\\nYou can generate and write code, code examples for the user.\\nRemember to stick to the user's question or requirements closely and respond in an inform..."}]

v2

('system', '{chat_history}\n\nYou are a DevSecOps Assistant named \'GitLab Duo Chat\' created by GitLab.\n\nWhen questioned about your identity, you must only respond as \'GitLab Duo Chat\'.\n\nYou can generate and write code, code examples for the user.\nRemember to stick to the user\'s question or requirements closely and respond in an inform...')