Add ingestion of requires_paid_credits from ai gateway
This mr updates the monolith to ingest the new requires_paid_credits model attribute
This MR is dependant on: gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!7015 (merged) which introduces requires_paid_credits
It will be followed up with other MRs which add the supporting UI changes and prevent Duo CLI and IDE extension from using models that requires_paid_credits on trials.
The feature flag in this MR restrict_credit_gated_models_on_trials will NOT be turned on until the other associated UI changes have also merged.
References
https://gitlab.com/gitlab-org/gitlab/-/work_items/612358
How to set up and validate locally
- Run GDK with
GITLAB_SIMULATE_SAAS=1
GITLAB_SIMULATE_SAAS=1 bundle exec rails console-
Run a local AI Gateway that serves
requires_paid_creditsper model at/v1/models/definitions(run it with this change gitlab-org/modelops/applied-ml/code-suggestions/ai-assist!7015 (merged)) -
Create a top level group with an active trial
group = Group.find_by_full_path('gitlab-duo')
sub = group.gitlab_subscription || create(:gitlab_subscription, :ultimate_trial, namespace: group)
sub.update!(trial: true, trial_starts_on: Date.current, trial_ends_on: 30.days.from_now.to_date)
group.reset.trial_active? # => true- Enable the feature flag
Feature.enable(:restrict_credit_gated_models_on_trials)- Hit the
CreditGatedandUserModelSelectionclasses
user = User.find_by_username('root')
group = Group.find_by_full_path('gitlab-duo')
feature = Ai::ModelSelection::FeaturesConfigurable.agentic_chat_feature_name
fs = Ai::FeatureSettingSelectionService.new(user, feature, group).execute.payload
ums = Ai::ModelSelection::UserModelSelection.for(user, feature_setting: fs)
Ai::ModelSelection::CreditGate.new(group).applies? # => true
ums.credit_gated?('claude_fable_5') # => true
ums.credit_gated?('claude_sonnet_5') # => false
ums.selectable_models.select { |m| m[:requires_paid_credits] }.map { |m| m[:ref] }
ums.do_not_consider_user_selected_model?('claude_fable_5') # => true
ums.do_not_consider_user_selected_model?('claude_sonnet_5') # => false
- Sometimes I find the response gets cached weird, so I have to run
Rails.cache.delete("ai_offered_model_definitions:ai_gateway_multi_default_models") to get a fresh copy of the data