Skip to content
代码片段 群组 项目
提交 f058a82a 编辑于 作者: Mohamed Hamda's avatar Mohamed Hamda
浏览文件

Add ai_custom_models_prompts_migration FF

Add a feature flag to control prompts migration
Use the new FF to route to AiGatewayCodeCompletionMessage
Adjust the base prompt in AiGatewayCodeCompletionMessage to be nil

Changelog: changed
EE: true
上级 3dc75b1b
加载中
---
name: ai_custom_models_prompts_migration
feature_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/473156
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/160050
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/473358
milestone: '17.3'
group: group::custom models
type: development
default_enabled: false
...@@ -18,12 +18,12 @@ def request_params ...@@ -18,12 +18,12 @@ def request_params
end end
end end
private
def prompt def prompt
raise NotImplementedError, "#{self.class} has not implemented method #{__method__}" nil
end end
private
def pick_prefix def pick_prefix
prefix.last(500) prefix.last(500)
end end
......
...@@ -37,16 +37,23 @@ def params ...@@ -37,16 +37,23 @@ def params
def prompt def prompt
model_name = feature_setting.self_hosted_model.model.to_sym model_name = feature_setting.self_hosted_model.model.to_sym
case model_name # rubocop:disable Gitlab/FeatureFlagWithoutActor -- Global development flag for migrating the prompts
when :codegemma prompt_migration_enabled = ::Feature.enabled?(:ai_custom_models_prompts_migration)
CodeSuggestions::Prompts::CodeCompletion::CodeGemmaMessages.new(params) # rubocop:enable Gitlab/FeatureFlagWithoutActor
when :codestral ai_gateway_class = CodeSuggestions::Prompts::CodeCompletion::AiGatewayCodeCompletionMessage
CodeSuggestions::Prompts::CodeCompletion::CodestralMessages.new(params) model_classes = {
when :'codellama:code' codegemma: CodeSuggestions::Prompts::CodeCompletion::CodeGemmaMessages,
CodeSuggestions::Prompts::CodeCompletion::CodellamaMessages.new(params) codestral: CodeSuggestions::Prompts::CodeCompletion::CodestralMessages,
else 'codellama:code': CodeSuggestions::Prompts::CodeCompletion::CodellamaMessages
raise "Unknown model: #{model_name}" }
end
message_class = if prompt_migration_enabled
ai_gateway_class
else
model_classes.fetch(model_name) { raise "Unknown model: #{model_name}" }
end
message_class.new(params)
end end
strong_memoize_attr :prompt strong_memoize_attr :prompt
end end
......
...@@ -35,10 +35,8 @@ def prompt ...@@ -35,10 +35,8 @@ def prompt
end end
describe '#prompt' do describe '#prompt' do
it 'raises NotImplementedError for the abstract class' do it 'returns an empty prompt' do
expect do expect(described_class.new(params).prompt).to be_nil
described_class.new(params).send(:prompt)
end.to raise_error(NotImplementedError, "#{described_class} has not implemented method prompt")
end end
end end
end end
...@@ -52,6 +52,10 @@ ...@@ -52,6 +52,10 @@
params: params, unsafe_passthrough_params: unsafe_params) params: params, unsafe_passthrough_params: unsafe_params)
end end
before do
stub_feature_flags(ai_custom_models_prompts_migration: false)
end
describe '#body' do describe '#body' do
before do before do
allow(CodeSuggestions::Prompts::CodeCompletion::CodeGemmaMessages) allow(CodeSuggestions::Prompts::CodeCompletion::CodeGemmaMessages)
...@@ -85,6 +89,21 @@ ...@@ -85,6 +89,21 @@
expect(CodeSuggestions::Prompts::CodeCompletion::CodeGemmaMessages).to have_received(:new).with(params) expect(CodeSuggestions::Prompts::CodeCompletion::CodeGemmaMessages).to have_received(:new).with(params)
end end
context 'when the ai_custom_models_prompts_migration FF is enabled' do
before do
stub_feature_flags(ai_custom_models_prompts_migration: true)
allow(CodeSuggestions::Prompts::CodeCompletion::AiGatewayCodeCompletionMessage)
.to receive(:new).and_return(codgemma_messages_prompt)
end
it 'calls the base AiGatewayCodeCompletionMessage class' do
task.body
expect(CodeSuggestions::Prompts::CodeCompletion::AiGatewayCodeCompletionMessage)
.to have_received(:new).with(params)
end
end
end end
describe 'prompt selection per model name' do describe 'prompt selection per model name' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册