Skip to content

feat: add support for additional context

What does this merge request do and why?

For gitlab-org/gitlab#477253 (closed)

This MR adds an additional context type to the AI gateway in order to accept additional context being passed through from the duo chat graphql api. Thank you to @maddievn for helping figure out how to make this work :)

In order for this to work with the Rails monolith, gitlab-org/gitlab!161898 (merged) will need to be merged first.

Screen recording

demo_1_postman_additional_context

Steps to validate

To validate just the aigw part (bypassing the monolith entirely):

  1. In your gdk directory run gdk config set gitlab_ai_gateway.enabled false

  2. cd gitlab-ai-gateway

  3. Add a Python debugger in agent.py similar to !1194 (9904fa2d)

  4. poetry run ai_gateway

  5. Use cURL or similar, I used PostMan, to hit the AIGW directly: http://localhost:5052/v2/chat/agent

    {
      "prompt": "string",
      "options": {
        "additional_context": [
            {
            "name": "something",
            "type": "snippet",
            "content": "some content from postman"
            }
        ],
        "chat_history": "string",
        "agent_scratchpad": {
          "agent_type": "react",
          "steps": [
            {
              "thought": "string",
              "tool": "string",
              "tool_input": "string",
              "observation": "string"
            }
          ]
        },
        "context": {
          "type": "issue",
          "content": "string"
        },
        "current_file": {
          "file_path": "string",
          "data": "string",
          "selected_code": true
        }
      },
      "model_metadata": {
        "endpoint": "https://example.com/",
        "name": "string",
        "provider": "string",
        "api_key": "string"
      }
    }
  6. In your terminal where you're running the ai gateway, the python debugger should catch - here you can inspect agent_request and note the additional_context that is passed through (see vid above)

Merge request checklist

  • Tests added for new functionality. If not, please raise an issue to follow up.
  • Documentation added/updated, if needed.
Edited by Missy Davies

Merge request reports

Loading