Skip to content

Add GraphQL Delete Mutation for Deleting Self-hosted Models

What does this MR do and why?

Adds a Graphql mutation for deleting a self-hosted model. This query will be invoked by the new Vue app currently in development to replace the existing HAML front-end for self-hosted models. The mutation added here will be leveraged by this piece of work (not yet started)

Note: The Vue UI is currently behind a feature flag custom_models_vue_app

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.

Database Query Plan

A new database query is introduced in this MR for deleting a ai_self_hosted_models row.

The ActiveRecord translated query is:

DELETE FROM ai_self_hosted_models WHERE id = 1

Screenshot_2024-07-08_at_10.18.07_AM

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

Prequisites

You will need:

  • An active GitLab ultimate license
  • Disable SAAS mode when running GDK
    • echo $GITLAB_SIMULATE_SAAS should return 0
    • See the docs for more information
  • Run the following commands in your rails console
add_on = GitlabSubscriptions::AddOn.find_or_create_by!(name: "code_suggestions") {|e| e.description = "Test"}
add_on_purchase = GitlabSubscriptions::AddOnPurchase.create!(add_on: add_on, expires_on: 1.month.from_now, quantity: 5, purchase_xid: 'A-S0001')
Feature.enable(:self_managed_code_suggestions)
Feature.enable(:ai_custom_model)
ApplicationSetting.first.update(duo_features_enabled: true)
## Creates a model in the db to delete
::Ai::SelfHostedModel.create(name: "Test model to delete", model: :mistral, endpoint: "https://test.com", api_token: "")

Testing the GQL request

  1. Open the graphql explorer: http://gdk.test:3000/-/graphql-explorer
  2. Run the query below, with the test inputs provided. This should delete the model you created in the prerequisite setup
mutation SelfHostedModelDelete($input: AiSelfHostedModelDeleteInput!) {
  aiSelfHostedModelDelete(input: $input)  {
    selfHostedModel {
      id
      name
      model
      endpoint
      hasApiToken
    }
  }
}

inputs:

{
  "input": {
    "id": "gid://gitlab/Ai::SelfHostedModel/<Primary ID of the model created above>"
  }
}

Numbered steps to set up and validate the change are strongly suggested.

Related to #461055 (closed)

Edited by Julie Huang

Merge request reports