Skip to content
    • @m_gill this script didn't work initially as my GDK directory is called gdk instead of the default gitlab-development-toolkit. Could we change the directory check to check for a file, like GDK_ROOT or gdk.yml?

      Everything else worked great! Thank you for putting this together.

    • Maintainer

      If you remove:

      if [[ $PWD != *gitlab-development-kit ]]; then
      	echo "You must run this script from the gitlab-development-kit directory"
      	exit 0
      fi

      and replace it with:

      case "$PWD" in
        *gdk | *gitlab-development-kit) ;;
        *) echo "You must run this script from the gitlab-development-kit directory"
          exit 0
      esac

      It should work with both gdk and gitlab-development-kit directories 😄

    • Please register or sign in to reply
  • Eduardo Bonet @eduardobonet ·
    Maintainer

    I tried to run the script, but the following line fails if not running in SaaS mode:

    Group.first.namespace_settings.update(experiment_features_enabled: true, third_party_ai_features_enabled: true)

    The step to enable saas needs to be done before

  • Author Developer

    Interesting catch @eduardobonet. I fixed this in the script 👍

  • Maintainer

    @m_gill I had to make the following adjustments in the script for it to work in my case:

    • Set -e so execution stops when an error is encountered
    • Ensure the script commands themselves run with simulated SAAS
    • Add restarts between ruby scripts where needed for changes to load
    • Add check that the user has a license set up
    • Reference gitlab-org group by name instead of Group.first (it wasn't the first one in my db)
    • Create subscription if it doesn't exist
    • Use ! methods for updates so errors are more obvious
    • Use new setup for GCP credentials from !133138 (merged)
    @@ -1,5 +1,9 @@
     #!/usr/bin/env bash
     
    +set -e
    +
    +export GITLAB_SIMULATE_SAAS=1
    +
     echo "Let's get started setting up your AI environment!"
     echo "This script will configure your GDK to support AI features."
     echo "You will still need to enable any feature-specific feature flags, which you can find here:"
    @@ -23,8 +27,8 @@
     echo "What is your OpenAI API key? Leave this blank if you don't need to set OpenAI up right now."
     read -r openai_key
     
    -echo "What is the full path to your VertexAI credentials? Leave this blank if you don't need to set VertexAI up right now."
    -read -r vertex_credentials_path
    +echo "What is your GCP project for Vertex AI API access? Leave this blank if you don't need to set VertexAI up right now."
    +read -r vertex_project
     
     echo "Do you want to setup the embeddings database? Y/N"
     read -r setup_embeddings
    @@ -57,20 +61,26 @@
            string="export GITLAB_SIMULATE_SAAS=0"
            replace="export GITLAB_SIMULATE_SAAS=1"
            sed -i -e "s/$string/$replace/" $filename
    +    gdk restart
     else
            echo "Need to update"
            echo "export GITLAB_SIMULATE_SAAS=1" >> $filename
    +    gdk restart
     fi
     
     
     # Setup Ultimate
     
     echo "Being on an Ultimate plan is sometimes a requirement to use AI as a customer."
    -echo "The first group in your GDK (usually gitlab-org) will be set to an Ultimate plan."
    +echo "Your gitlab-org group will be set to an Ultimate plan."
     
     cd gitlab
     
     cat <<EOF >ensure_ultimate.rb
    +if License.count.zero?
    +    fail "No license found. Did you follow https://about.gitlab.com/handbook/developer-onboarding/#working-on-gitlab-ee-developer-licenses?"
    +end
    +
     # Allow use of licensed features
     Gitlab::CurrentSettings.update(check_namespace_plan: true)
     
    @@ -80,9 +90,15 @@
            ultimate_plan = Plan.create(name: "ultimate", title: "Ultimate")
     end
     
    +group = Group.find_by_full_path('gitlab-org')
     
    -Group.first.gitlab_subscription.update(hosted_plan_id: ultimate_plan.id)
    +if group.gitlab_subscription
    +    group.gitlab_subscription.update!(hosted_plan_id: ultimate_plan.id)
    +else
    +    GitlabSubscription.create!(namespace: group, hosted_plan_id: ultimate_plan.id)
    +end
     
    +
     EOF
     
     rails r ensure_ultimate.rb
    @@ -92,10 +108,10 @@
     # Setup toggles
     
     echo "Experimental features and third-party AI services are both options that must be enabled to use AI as a customer."
    -echo "These settings will be enabled for the first group in your GDK (usually gitlab-org)"
    +echo "These settings will be enabled for the gitlab-org group on your GDK"
     
     
    -echo "Group.first.namespace_settings.update(experiment_features_enabled: true, third_party_ai_features_enabled: true)" | rails console
    +echo "Group.find_by_full_path('gitlab-org').namespace_settings.update!(experiment_features_enabled: true, third_party_ai_features_enabled: true)" | rails console
     cd ../
     
     
    @@ -135,14 +151,12 @@
            cd ../
     fi
     
    -if [[ $vertex_credentials_path ]]; then
    +if [[ $vertex_project ]]; then
            echo "Configuring VertexAI..."
            cd gitlab
     
            cat <<EOF >configure_vertex.rb
    -file = File.read('$vertex_credentials_path')
    -Gitlab::CurrentSettings.update(vertex_ai_credentials: file )
    -Gitlab::CurrentSettings.update(vertex_ai_project: JSON.parse(file)["project_id"])
    +Gitlab::CurrentSettings.update(vertex_ai_project: '$vertex_project')
     EOF
     
            rails r configure_vertex.rb
    @@ -219,4 +233,3 @@
            cd ../
     
     fi
  • Author Developer

    I replaced the old seeding script with the new rake task and set the file to public:

    cat <<EOF >setup_embeddings.rb
    ActiveRecord::Base.logger = nil if Rails.env.development?
    
    sha = 'f7bfb0bd48fbb33c620146f5df5a88d54e489127'
    number_of_rows = 12739
    url = "https://gitlab.com/gitlab-org/enablement-section/tanuki-bot/-/raw/#{sha}/pgvector/tanuki_bot_mvc.json?inline=false"
    
    Dir.mktmpdir do |dir|
      puts "> Loading file size"
      content_length = HTTParty.head(url).headers.fetch('content-length').to_i
    
      File.open("#{dir}/tanuki_bot_mvc.json", "wb") do |file|
        puts "> Downloading file"
        cursor = 0
        i = 0
        HTTParty.get(url, stream_body: true) do |fragment|
          file.write(fragment)
          cursor += fragment.length
          i += 1
          puts "#{ cursor / 2**20 }MiB (#{((cursor/content_length.to_f) * 100).round(2)}%)" if i % 1000 == 0 || cursor == content_length
        end
      end
    
      puts "> Reading file"
      Embedding::TanukiBotMvc.transaction do
        Embedding::TanukiBotMvc.delete_all
    
        i = 0
        File.readlines("#{dir}/tanuki_bot_mvc.json").each do |line|
          attributes = JSON.parse(line)
          Embedding::TanukiBotMvc.create!(attributes)
          i += 1
    
          count = Embedding::TanukiBotMvc.count
          puts "#{count}/#{number_of_rows} (#{((count/number_of_rows.to_f) * 100).round(2)}%)" if i % 100 == 0 || i == number_of_rows
        end
    
        # Delete records with no meaningful content
        Embedding::TanukiBotMvc.where.not("content ~ ?", '\w').delete_all
        # Delete records without titles as these likely no longer exist
        Embedding::TanukiBotMvc.where("metadata -> 'title' IS NULL").delete_all
    
        true
      end
    
      puts "> Transaction completed"
      puts "Number of records: #{Embedding::TanukiBotMvc.count}"
    end
    EOF
    
    	rails r setup_embeddings.rb
    
    	rm setup_embeddings.rb
    
  • Maintainer

    If anyone has issues with postgres when building pgvector/vector eg:

    --------------------------------------------------------------------------------
    Building pgvector/vector.so version v0.4.1
    --------------------------------------------------------------------------------
    In file included from src/ivfbuild.c:1:
    In file included from /Users/carladrago/.asdf/installs/postgres/14.9/include/server/postgres.h:46:
    /Users/carladrago/.asdf/installs/postgres/14.9/include/server/c.h:59:10: fatal error: 'stdio.h' file not found
    #include <stdio.h>

    uninstalling then reinstalling postgres worked for me:

    asdf uninstall postgres 14.9 && asdf install postgres 14.9

0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment