Skip to content

Associate the AI responses with user prompts

Denys Mishunov requested to merge dmishunov/duo-chat-refactor-state into master

What does this MR do and why?

The MR refactors the state store for GitLab Duo Chat to:

  • Simplify it and provide SSOT when mutating the state - just one addDuoChatMessage action, and types.ADD_MESSAGE mutation instead of multiple similar ones
  • Extend GraphQL aiCompletionResponse subscription with additional fields (requestId, role, timestamp) for every message
  • Extend aiMessages query (when fetching the cached messages) with timestamp field to match the updated signature of the subscription
  • Updated the GitLab Duo Chat application to reflect those changes

But the main functional change is that the new types.ADD_MESSAGE mutation is smart and, in general, dispatches the incoming messages using three scenarios: - if a message with the same requestId already exists in the state and has the same role as the incoming message, we update the existing one instead of creating a new entry - if the already existing message (same requestId) has role different from the incoming message, we assume that the existing message is the user prompt and the incoming message is the response from the AI. Hence we inject the incoming message right after the user prompt - if there's no message with the same requestId, we follow the previous process and push the incoming message to the end of the state

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

Before After
chat-messages-associasion chat-messages-associasion-FIXED

How to set up and validate locally

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

References https://gitlab.com/gitlab-org/gitlab/-/issues/420849

Edited by Denys Mishunov

Merge request reports