Skip to content
代码片段 群组 项目
未验证 提交 953dbb6d 编辑于 作者: Eugie Limpin's avatar Eugie Limpin 提交者: GitLab
浏览文件

Merge branch 'migrate-to-3_5-sonnet' into 'master'

No related branches found
No related tags found
无相关合并请求
---
name: use_sonnet_35
feature_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/468334
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/157696
rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/469499
milestone: '17.2'
group: group::ai framework
type: gitlab_com_derisk
default_enabled: false
...@@ -70,7 +70,7 @@ def default_options ...@@ -70,7 +70,7 @@ def default_options
def model(options) def model(options)
return options[:model] if options[:model].present? return options[:model] if options[:model].present?
CLAUDE_3_SONNET Feature.enabled?(:use_sonnet_35, user) ? CLAUDE_3_5_SONNET : CLAUDE_3_SONNET
end end
def provider(options) def provider(options)
......
...@@ -4,6 +4,7 @@ module Gitlab ...@@ -4,6 +4,7 @@ module Gitlab
module Llm module Llm
module Concerns module Concerns
module AvailableModels module AvailableModels
CLAUDE_3_5_SONNET = 'claude-3-5-sonnet-20240620'
CLAUDE_3_SONNET = 'claude-3-sonnet-20240229' CLAUDE_3_SONNET = 'claude-3-sonnet-20240229'
CLAUDE_3_HAIKU = 'claude-3-haiku-20240307' CLAUDE_3_HAIKU = 'claude-3-haiku-20240307'
CLAUDE_2_1 = 'claude-2.1' CLAUDE_2_1 = 'claude-2.1'
...@@ -13,7 +14,8 @@ module AvailableModels ...@@ -13,7 +14,8 @@ module AvailableModels
VERTEX_MODEL_CODE = 'code-bison' VERTEX_MODEL_CODE = 'code-bison'
VERTEX_MODEL_CODECHAT = 'codechat-bison' VERTEX_MODEL_CODECHAT = 'codechat-bison'
VERTEX_MODEL_TEXT = 'text-bison' VERTEX_MODEL_TEXT = 'text-bison'
ANTHROPIC_MODELS = [CLAUDE_2_1, CLAUDE_3_SONNET, CLAUDE_3_HAIKU, DEFAULT_INSTANT_MODEL].freeze ANTHROPIC_MODELS = [CLAUDE_2_1, CLAUDE_3_SONNET, CLAUDE_3_5_SONNET, CLAUDE_3_HAIKU,
DEFAULT_INSTANT_MODEL].freeze
VERTEX_MODELS = [VERTEX_MODEL_CHAT, VERTEX_MODEL_CODECHAT, VERTEX_MODEL_CODE, VERTEX_MODEL_TEXT].freeze VERTEX_MODELS = [VERTEX_MODEL_CHAT, VERTEX_MODEL_CODECHAT, VERTEX_MODEL_CODE, VERTEX_MODEL_TEXT].freeze
AVAILABLE_MODELS = { AVAILABLE_MODELS = {
......
...@@ -74,6 +74,7 @@ ...@@ -74,6 +74,7 @@
before do before do
allow(Gitlab::Llm::Logger).to receive(:build).and_return(logger) allow(Gitlab::Llm::Logger).to receive(:build).and_return(logger)
allow(instance).to receive(:ai_client).and_return(ai_client) allow(instance).to receive(:ai_client).and_return(ai_client)
stub_feature_flags(use_sonnet_35: false)
end end
shared_examples 'performing request to the AI Gateway' do shared_examples 'performing request to the AI Gateway' do
...@@ -137,6 +138,53 @@ ...@@ -137,6 +138,53 @@
end end
end end
context 'when using Sonnet 3.5 model' do
let(:expected_model) { described_class::CLAUDE_3_5_SONNET }
before do
stub_feature_flags(use_sonnet_35: true)
end
it 'calls the AI Gateway streaming endpoint and yields response without stripping it' do
expect(ai_client).to receive(:stream).with(endpoint: endpoint, body: body).and_yield(response)
.and_return(response)
expect { |b| instance.request(prompt, &b) }.to yield_with_args(response)
end
it_behaves_like 'performing request to the AI Gateway'
it_behaves_like 'tracks events for AI requests', 4, 2, klass: 'Gitlab::Llm::Anthropic::Client' do
before do
allow(ai_client).to receive(:stream).with(endpoint: endpoint, body: body).and_return(response)
end
end
context 'when additional params are passed in as options' do
let(:options) do
{ temperature: 1, stop_sequences: %W[\n\Foo Bar:], max_tokens_to_sample: 1024, disallowed_param: 1, topP: 1 }
end
let(:params) do
{
max_tokens_to_sample: 1024,
stop_sequences: ["\n\Foo", "Bar:"],
temperature: 1
}
end
it_behaves_like 'performing request to the AI Gateway'
end
context 'when unit primitive is passed' do
let(:endpoint) { "#{described_class::BASE_ENDPOINT}/test" }
subject(:request) { instance.request(prompt, unit_primitive: :test) }
it_behaves_like 'performing request to the AI Gateway'
end
end
context 'when invalid model is passed' do context 'when invalid model is passed' do
let(:model) { 'test' } let(:model) { 'test' }
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册