Instance level model selection migration and rails model
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
What is this issue about
We need instance level Model Selection to get this Model Selection access for all scopes e.i GitLab.com, Dedicated, and Self-Managed using the GitLab.com AIG. In this issue we are discussing the migrations and MVC Models changes needed to implement it.
How to setup locally
See this comment
Implementation Proposal
We can implement the Ai::ModelSelection::FeaturesConfigurable
concern so we won't have to worry about a lot of the shared logic like validation and such. To implement it you can generate the following model.
gdk rails generate model Ai::ModelSelection::InstanceFeatureSetting feature:integer:index offered_model_ref:text offered_model_name:string
The migration file should look something like this:
class CreateAiNamespaceFeatureSettings < Gitlab::Database::Migration[2.3]
milestone '18.5'
def change
create_table :ai_instance_feature_settings do |t|
t.timestamps_with_timezone null: false
t.integer :feature, null: false, limit: 2, index: { unique: true }
t.text :offered_model_ref, limit: 255, null: true
t.text :offered_model_name, limit: 255, null: true
end
end
end
The model must be at the path ee/app/models/ai/model_selection/instance_feature_setting.rb
should look something like this:
# frozen_string_literal: true
module Ai
module ModelSelection
class InstanceFeatureSetting < ApplicationRecord
include ::Ai::ModelSelection::FeaturesConfigurable
self.table_name = "ai_instance_feature_settings"
validates :feature, :uniqueness
scope :non_default, -> { where.not(offered_model_ref: [nil, ""]) }
def self.find_or_initialize_by_feature(feature)
return unless ::Feature.enabled?(:ai_model_switching)
feature_name = get_feature_name(feature)
find_or_initialize_by(feature: feature_name)
end
def model_selection_scope
:instance
end
def set_to_gitlab_default?
offered_model_ref.blank?
end
end
end
end
Implement some tests the same way it is done in ee/spec/models/ai/model_selection/namespace_feature_setting_spec.rb
(There is a lot of shared examples you can reuse)
This should be enough to start development for this.