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

Merge branch 'current-page-contexts' into 'master'

Send current page params as set of params

See merge request https://gitlab.com/gitlab-org/gitlab/-/merge_requests/177622



Merged-by: default avatarTetiana Chupryna <tchupryna@gitlab.com>
Approved-by: default avatarEduardo Bonet <ebonet@gitlab.com>
Reviewed-by: default avatarMohamed Hamda <mhamda@gitlab.com>
No related branches found
No related tags found
无相关合并请求
...@@ -13,6 +13,17 @@ def initialize(user, resource) ...@@ -13,6 +13,17 @@ def initialize(user, resource)
def serialize_for_ai(_content_limit:) def serialize_for_ai(_content_limit:)
raise NotImplementedError raise NotImplementedError
end end
def current_page_params
{
type: current_page_type,
title: resource.title
}
end
def current_page_type
raise NotImplementedError
end
end end
end end
end end
...@@ -25,6 +25,12 @@ def current_page_short_description ...@@ -25,6 +25,12 @@ def current_page_short_description
The user is currently on a page that displays a ci build which the user might refer to, for example, as 'current', 'this' or 'that'. The user is currently on a page that displays a ci build which the user might refer to, for example, as 'current', 'this' or 'that'.
SENTENCE SENTENCE
end end
def current_page_params
{
type: current_page_type
}
end
end end
end end
end end
......
---
name: current_page_context_prompt_in_aigw
feature_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/508317
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/177622
rollout_issue_url:
milestone: '17.9'
group: group::duo chat
type: wip
default_enabled: false
...@@ -314,6 +314,7 @@ def conversation ...@@ -314,6 +314,7 @@ def conversation
end end
def current_resource_params def current_resource_params
return current_page_params if Feature.enabled?(:current_page_context_prompt_in_aigw, context.current_user)
return unless current_resource_type return unless current_resource_type
{ {
...@@ -336,6 +337,13 @@ def current_resource_content ...@@ -336,6 +337,13 @@ def current_resource_content
end end
strong_memoize_attr :current_resource_content strong_memoize_attr :current_resource_content
def current_page_params
context.current_page_params
rescue ArgumentError
nil
end
strong_memoize_attr :current_page_params
def current_file_params def current_file_params
return unless current_selection || current_blob return unless current_selection || current_blob
......
...@@ -13,7 +13,7 @@ class GitlabContext ...@@ -13,7 +13,7 @@ class GitlabContext
attr_reader :project attr_reader :project
delegate :current_page_type, :current_page_short_description, delegate :current_page_type, :current_page_short_description, :current_page_params,
to: :authorized_resource, allow_nil: true to: :authorized_resource, allow_nil: true
# rubocop:disable Metrics/ParameterLists -- we probably need to rethink this initializer # rubocop:disable Metrics/ParameterLists -- we probably need to rethink this initializer
......
...@@ -53,6 +53,8 @@ ...@@ -53,6 +53,8 @@
end end
let(:issue_resource) { Ai::AiResource::Issue.new(user, resource) } let(:issue_resource) { Ai::AiResource::Issue.new(user, resource) }
let(:issue_page_params) { { type: issue_resource.current_page_type, title: resource.title } }
let(:answer_chunk) { create(:final_answer_chunk, chunk: "Ans") } let(:answer_chunk) { create(:final_answer_chunk, chunk: "Ans") }
let(:step_params) do let(:step_params) do
...@@ -60,10 +62,7 @@ ...@@ -60,10 +62,7 @@
messages: [{ messages: [{
role: "user", role: "user",
content: user_input, content: user_input,
context: { context: issue_page_params,
type: issue_resource.current_page_type,
content: issue_resource.current_page_short_description
},
current_file: nil, current_file: nil,
additional_context: context.additional_context additional_context: context.additional_context
}], }],
...@@ -367,7 +366,7 @@ def expect_sli_error(failed) ...@@ -367,7 +366,7 @@ def expect_sli_error(failed)
context "when error event received and it's prompt length error" do context "when error event received and it's prompt length error" do
let(:message) do let(:message) do
<<~MESSAGE <<~MESSAGE
Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'prompt is too long: 200082 tokens > 199999 maximum'}} Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'prompt is too long: 200082 tokens > 199999 maximum'}}
MESSAGE MESSAGE
end end
...@@ -435,6 +434,29 @@ def expect_sli_error(failed) ...@@ -435,6 +434,29 @@ def expect_sli_error(failed)
end end
end end
context "when there is no resource" do
let(:context) do
Gitlab::Llm::Chain::GitlabContext.new(
current_user: user,
container: nil,
resource: nil,
ai_request: nil
)
end
it "sends request without context" do
params = step_params
params[:messages].first[:context] = nil
expect_next_instance_of(Gitlab::Duo::Chat::StepExecutor) do |react_agent|
expect(react_agent).to receive(:step).with(hash_including(params))
.and_yield(action_event).and_return([action_event])
end
agent.execute
end
end
context "when code is selected" do context "when code is selected" do
let(:selected_text) { 'code selection' } let(:selected_text) { 'code selection' }
let(:current_file) do let(:current_file) do
...@@ -485,6 +507,41 @@ def expect_sli_error(failed) ...@@ -485,6 +507,41 @@ def expect_sli_error(failed)
end end
end end
context "when current page is included in context" do
it "pass current page params" do
params = step_params
params[:messages].first[:context] = issue_page_params
expect_next_instance_of(Gitlab::Duo::Chat::StepExecutor) do |react_agent|
expect(react_agent).to receive(:step).with(params)
.and_yield(action_event).and_return([action_event])
end
agent.execute
end
context "with feature flag disabled" do
before do
stub_feature_flags(current_page_context_prompt_in_aigw: false)
end
it "pass current page description" do
params = step_params
params[:messages].first[:context] = {
type: issue_resource.current_page_type,
content: issue_resource.current_page_short_description
}
expect_next_instance_of(Gitlab::Duo::Chat::StepExecutor) do |react_agent|
expect(react_agent).to receive(:step).with(params)
.and_yield(action_event).and_return([action_event])
end
agent.execute
end
end
end
context 'when Duo chat is self-hosted' do context 'when Duo chat is self-hosted' do
let_it_be(:self_hosted_model) { create(:ai_self_hosted_model, api_token: 'test_token') } let_it_be(:self_hosted_model) { create(:ai_self_hosted_model, api_token: 'test_token') }
let_it_be(:ai_feature) { create(:ai_feature_setting, self_hosted_model: self_hosted_model, feature: :duo_chat) } let_it_be(:ai_feature) { create(:ai_feature_setting, self_hosted_model: self_hosted_model, feature: :duo_chat) }
......
...@@ -9,4 +9,11 @@ ...@@ -9,4 +9,11 @@
.to raise_error(NotImplementedError) .to raise_error(NotImplementedError)
end end
end end
describe '#current_page_params' do
it 'returns params to construct prompt' do
expect { described_class.new(nil, nil).current_page_params }
.to raise_error(NotImplementedError)
end
end
end end
...@@ -37,4 +37,10 @@ ...@@ -37,4 +37,10 @@
.to include("The user is currently on a page that displays a ci build") .to include("The user is currently on a page that displays a ci build")
end end
end end
describe '#current_page_params' do
it 'returns params to construct prompt' do
expect(wrapped_build.current_page_params.keys).to eq([:type])
end
end
end end
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册