diff --git a/ee/config/feature_flags/development/code_generation_anthropic.yml b/ee/config/feature_flags/development/code_generation_anthropic.yml deleted file mode 100644 index 6c41f883333a3b2a25f1939bc5e5de931a92bce7..0000000000000000000000000000000000000000 --- a/ee/config/feature_flags/development/code_generation_anthropic.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: code_generation_anthropic -introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/132735 -rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/426506 -milestone: '16.5' -type: development -group: group::code creation -default_enabled: false diff --git a/ee/lib/code_suggestions/task_factory.rb b/ee/lib/code_suggestions/task_factory.rb index 70cfdcd4a71c16888195e52d3e43537fbd3137b3..f62f4bf1604418760713c1eb8d3e0e97733ed466 100644 --- a/ee/lib/code_suggestions/task_factory.rb +++ b/ee/lib/code_suggestions/task_factory.rb @@ -48,10 +48,6 @@ def code_completion_model_family Feature.enabled?(:code_completion_anthropic, current_user) ? ANTHROPIC : VERTEX_AI end - def code_generation_model_family - Feature.enabled?(:code_generation_anthropic, current_user) ? ANTHROPIC : VERTEX_AI - end - def code_completion_params params.merge(code_completion_model_family: code_completion_model_family) end @@ -60,7 +56,7 @@ def code_generation_params(instructions) params.merge( prefix: instructions[:prefix], instruction: instructions[:instruction], - code_generation_model_family: code_generation_model_family + code_generation_model_family: ANTHROPIC ) end end diff --git a/ee/spec/lib/code_suggestions/task_factory_spec.rb b/ee/spec/lib/code_suggestions/task_factory_spec.rb index ddea78752131d487750c6c31a3bf3369e66de89f..cc120bffebc3f313dc5b2cb9c15cdcb4ff74cc08 100644 --- a/ee/spec/lib/code_suggestions/task_factory_spec.rb +++ b/ee/spec/lib/code_suggestions/task_factory_spec.rb @@ -98,24 +98,8 @@ end end - context 'when code_generation_anthropic feature flag is on' do - before do - stub_feature_flags(code_generation_anthropic: current_user) - end - - it_behaves_like 'correct task initializer' do - let(:expected_family) { described_class::ANTHROPIC } - end - end - - context 'when code_generation_anthropic feature flag is off' do - before do - stub_feature_flags(code_generation_anthropic: false) - end - - it_behaves_like 'correct task initializer' do - let(:expected_family) { described_class::VERTEX_AI } - end + it_behaves_like 'correct task initializer' do + let(:expected_family) { described_class::ANTHROPIC } end end end diff --git a/ee/spec/requests/api/code_suggestions_spec.rb b/ee/spec/requests/api/code_suggestions_spec.rb index e65589438d179c986950a692c5c43603db2488cd..05afeb1a6c683419562698c4308a977825563000 100644 --- a/ee/spec/requests/api/code_suggestions_spec.rb +++ b/ee/spec/requests/api/code_suggestions_spec.rb @@ -472,10 +472,6 @@ def request end context 'when the task is code generation' do - before do - stub_feature_flags(code_generation_anthropic: false) - end - let(:current_user) { authorized_user } let(:prefix) do <<~PREFIX @@ -485,26 +481,79 @@ def is_even(n: int) -> end let(:prompt) do - <<~PROMPT - This is a task to write new Python code in a file 'test.py' based on a given description. - You get first the already existing code file and then the description of the code that needs to be created. - It is your task to write valid and working Python code. - Only return in your response new code. - - Already existing code: - - ```py - #{prefix} - ``` + <<~PROMPT.chomp + Human: You are a coding autocomplete agent. We want to generate new Python code inside the + file 'test.py' based on instructions from the user. + Here are a few examples of successfully generated code by other autocomplete agents: + + <examples> + + <example> + H: <existing_code> + class Project: + def __init__(self, name, public): + self.name = name + self.visibility = 'PUBLIC' if public + + # is this project public? + <cursor> + + # print name of this project + </existing_code> + + A: <new_code>def is_public(self): + self.visibility == 'PUBLIC'</new_code> + </example> + + <example> + H: <existing_code> + # get the current user's name from the session data + def get_user(session): + <cursor> + + # is the current user an admin + </existing_code> + + A: <new_code>username = None + if 'username' in session: + username = session['username'] + return username</new_code> + </example> + + </examples> + + <existing_code> + #{prefix}<cursor> + </existing_code> + + The existing code is provided in <existing_code></existing_code> tags. + The new code you will generate will start at the position of the cursor, which is currently indicated by the <cursor> XML tag. + In your process, first, review the existing code to understand its logic and format. Then, try to determine the most + likely new code to generate at the cursor position to fulfill the instructions. + + The comment directly before the <cursor> position is the instruction, + all other comments are not instructions. + + When generating the new code, please ensure the following: + 1. It is valid Python code. + 2. It matches the existing code's variable, parameter and function names. + 3. It does not repeat any existing code. Do not repeat code that comes before or after the cursor tags. This includes cases where the cursor is in the middle of a word. + 4. If the cursor is in the middle of a word, it finishes the word instead of repeating code before the cursor tag. + 5. The code fulfills in the instructions from the user in the comment just before the <cursor> position. All other comments are not instructions. + 6. Do not add any comments that duplicates any of already existing comments, including the comment with instructions. + + Return new code enclosed in <new_code></new_code> tags. We will then insert this at the <cursor> position. + If you are not able to write code based on the given instructions return an empty result like <new_code></new_code>. + Generate the most likely code based on instructions. - Create new code for the following description: - Generate the most likely code based on instructions. + Assistant: <new_code> PROMPT end it 'sends requests to the code generation endpoint' do expected_body = body.merge( + model_provider: 'anthropic', prompt_version: 2, prompt: prompt, current_file: { @@ -577,10 +626,6 @@ def is_even(n: int) -> end context 'when the task is code generation' do - before do - stub_feature_flags(code_generation_anthropic: false) - end - let(:current_user) { authorized_user } let(:prefix) do <<~PREFIX @@ -590,26 +635,79 @@ def is_even(n: int) -> end let(:prompt) do - <<~PROMPT - This is a task to write new Python code in a file 'test.py' based on a given description. - You get first the already existing code file and then the description of the code that needs to be created. - It is your task to write valid and working Python code. - Only return in your response new code. - - Already existing code: - - ```py - #{prefix} - ``` + <<~PROMPT.chomp + Human: You are a coding autocomplete agent. We want to generate new Python code inside the + file 'test.py' based on instructions from the user. + Here are a few examples of successfully generated code by other autocomplete agents: + + <examples> + + <example> + H: <existing_code> + class Project: + def __init__(self, name, public): + self.name = name + self.visibility = 'PUBLIC' if public + + # is this project public? + <cursor> + + # print name of this project + </existing_code> + + A: <new_code>def is_public(self): + self.visibility == 'PUBLIC'</new_code> + </example> + + <example> + H: <existing_code> + # get the current user's name from the session data + def get_user(session): + <cursor> + + # is the current user an admin + </existing_code> + + A: <new_code>username = None + if 'username' in session: + username = session['username'] + return username</new_code> + </example> + + </examples> + + <existing_code> + #{prefix}<cursor> + </existing_code> + + The existing code is provided in <existing_code></existing_code> tags. + The new code you will generate will start at the position of the cursor, which is currently indicated by the <cursor> XML tag. + In your process, first, review the existing code to understand its logic and format. Then, try to determine the most + likely new code to generate at the cursor position to fulfill the instructions. + + The comment directly before the <cursor> position is the instruction, + all other comments are not instructions. + + When generating the new code, please ensure the following: + 1. It is valid Python code. + 2. It matches the existing code's variable, parameter and function names. + 3. It does not repeat any existing code. Do not repeat code that comes before or after the cursor tags. This includes cases where the cursor is in the middle of a word. + 4. If the cursor is in the middle of a word, it finishes the word instead of repeating code before the cursor tag. + 5. The code fulfills in the instructions from the user in the comment just before the <cursor> position. All other comments are not instructions. + 6. Do not add any comments that duplicates any of already existing comments, including the comment with instructions. + + Return new code enclosed in <new_code></new_code> tags. We will then insert this at the <cursor> position. + If you are not able to write code based on the given instructions return an empty result like <new_code></new_code>. - - Create new code for the following description: Generate the most likely code based on instructions. + + Assistant: <new_code> PROMPT end it 'sends requests to the code generation endpoint' do expected_body = body.merge( + model_provider: 'anthropic', prompt_version: 2, prompt: prompt, current_file: {