Skip to content

Mistral prompt for Code generations

What does this MR do and why?

This MR enables the setting/use of self-hosted models (Mistral/Mixtral) for code suggestions.

This MR is based on !152380 (merged) and the FE is being handled in !152107 (merged)

TODO/BLOCKING MERGE: We need to evaluate the prompt

Screenshots or screen recordings

Screen_Recording_2024-05-16_at_12.26.15

How to set up and validate locally

  • Ensure you have purchased Duo Pro and that the instance is running as an SM instance.

  • Verify the value of GITLAB_SIMULATE_SAAS by executing echo $GITLAB_SIMULATE_SAAS; it should be 0.

If you don't have a Duo Pro record, you can create one from rails c using:

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'
)
  • In a separate terminal, if gdk is running, execute the following:
gdk stop rails-web && GITLAB_RAILS_RACK_TIMEOUT_ENABLE_LOGGING=false PUMA_SINGLE_MODE=true GITLAB_SIMULATE_SAAS=0 gdk rails s
  1. In the Rails console, enable the experiment fully:

    > Feature.enable(:self_managed_code_suggestions)
    > Feature.enable(:ai_custom_model)
    > ApplicationSetting.first.update(duo_features_enabled: true)

    This MVP requires the Ai::SelfHostedModel record to be created in the database.

    The table/model exists on the target branch, but the UI doesn't yet exist there: Front-end iteration for self-deployed model con... (!152107 - merged).

Please create a record in the Rails console: ::Ai::SelfHostedModel.create!(model: 0, endpoint: 'http://127.0.0.1:11434/v1', name: 'mistral-7B', api_token: 'token')

  1. Log in as an admin.

  2. Visit the index page Admin Area > AI-Powered Features > Features.

  3. Use Mistral for Code Generations.

    Screenshot_2024-05-16_at_12.07.10

Make sure that you have the AI gateway up and running in the GDK.

Set up a locally hosted Mistral model using OLLAMA. In a separate terminal, run ollama serve.

Follow the above recording to verify the changes.

Edited by Mohamed Hamda

Merge request reports