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):
-
In your gdk directory run
gdk config set gitlab_ai_gateway.enabled false
-
cd gitlab-ai-gateway
-
Add a Python debugger in
agent.py
similar to !1194 (9904fa2d) -
poetry run ai_gateway
-
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" } }
-
In your terminal where you're running the ai gateway, the python debugger should catch - here you can inspect
agent_request
and note theadditional_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.