Skip to content

chore: Add additional context type for terminal to API

What does this MR do and why?

Adds a new AI Additional Context Type of "terminal" to the GraphQL API.

Uses the "include_terminal_context" cloud connector unit primitive.

Merge Chain ⛓️

Project MR -
Cloud Connector Move explain_terminal unit primitive to included context
AI Gateway feat: add additional context type 'terminal'
Rails Monolith Add additional context type for terminal to API <-- You are here!

References

Please include cross links to any resources that are relevant to this MR. This will give reviewers and future readers helpful context to give an efficient review of the changes introduced.

Depends on gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!2059 (merged)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

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

Before After

How to set up and validate locally

  1. Run bundle exec rails c

  2. Start gdk with LLM debug. In your gdk directory run the following commands:

    1. export LLM_DEBUG=1
    2. gdk start
    3. tail -f rails/log/llm.log
  3. Navigate to http://gdk.test:3000/-/graphql-explorer

  4. Run the following mutation:

    mutation newTerminalChatMessage{
      aiAction(input: {chat: {
        resourceId: "gid://gitlab/User/1",
        content: "Explain terminal input",
        additionalContext: [
          { 
            id: "test"
            category: TERMINAL,
            content: "$ git status"
          }
      ]}}) {
        clientMutationId
        errors
        requestId
      }
    }
  5. Check LLM logs

  6. You should see a record similar to this truncated example

    {"severity":"DEBUG","time":"2024-08-08T09:40:34.337Z","action_name":"chat","options":{"content":"Explain terminal input","additional_context":[{"type":"terminal","content":"$ git status"}],"referer_url":"http://gdk.test:3000/-/graphql-explorer"}}
  7. Run the following query, replacing <requestId> with the value from the response in step 4.

query getAiMessages {
  aiMessages(requestIds: ["<requestId>"]) {
    nodes {
      requestId
      role
      content
      contentHtml
      timestamp
      errors
      extras {
        sources
        additionalContext {
          id
          category
          metadata
          content
        }
      }
    }
  }
}
  1. The result should contain:
  • "category": "TERMINAL",
  • "content": "$ git status",
  • no errors
Edited by Anna Springfield

Merge request reports

Loading