Skip to content
Snippets Groups Projects
Unverified Commit 3c528e0a authored by Max Woolf's avatar Max Woolf Committed by GitLab
Browse files

Merge branch 'sq/rename-codesuggestions-terminology' into 'master'

Renames CodeSuggestions namespace terminologies and updates test coverage

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



Merged-by: default avatarMax Woolf <mwoolf@gitlab.com>
Approved-by: default avatarNwanna Isong <nisong@gitlab.com>
Approved-by: default avatarMeir Benayoun <mbenayoun@gitlab.com>
Approved-by: default avatarMax Woolf <mwoolf@gitlab.com>
Reviewed-by: default avatarMeir Benayoun <mbenayoun@gitlab.com>
Reviewed-by: default avatarDuo Code Reviewer <duo-code-review-bot@gitlab.com>
Reviewed-by: default avatarNwanna Isong <nisong@gitlab.com>
Co-authored-by: default avatarsholaq <squadri@gitlab.com>
parents c52ca961 ec4b0f30
No related branches found
No related tags found
No related merge requests found
Showing
with 203 additions and 144 deletions
Loading
Loading
@@ -11,7 +11,7 @@ class InstructionsExtractor
# It searches for the last instance of a match by looking for the end
# of a text block and an optional line break.
FIRST_COMMENT_REGEX = "(?<comment>%{comment_format})[ \\t]*(?<instruction>[^\\r\\n]{10,})\\s*\\Z"
ALWAYS_GENERATE_PREFIX = %r{.*?}
ALWAYS_GENERATE_CONTENT_ABOVE_CURSOR = %r{.*?}
 
EMPTY_LINES_LIMIT = 1
 
Loading
Loading
@@ -71,7 +71,7 @@ def instruction_type
end
 
def first_line_regex
return ALWAYS_GENERATE_PREFIX if intent == INTENT_GENERATION
return ALWAYS_GENERATE_CONTENT_ABOVE_CURSOR if intent == INTENT_GENERATION
 
comment_format = language.single_line_comment_format
Regexp.new(
Loading
Loading
Loading
Loading
@@ -216,13 +216,14 @@ def generation_examples(type: nil)
examples.select { |example| example['trigger_type'] == type }
end
 
def cursor_inside_empty_function?(content, suffix)
return false unless content
def cursor_inside_empty_function?(content_above_cursor, content_below_cursor)
return false unless content_above_cursor
 
return false unless LANGUAGE_METHOD_PATTERNS.has_key?(@name)
 
LANGUAGE_METHOD_PATTERNS[@name]['empty_function'].match?(content.strip.lines.last) &&
(suffix.blank? || LANGUAGE_METHOD_PATTERNS[@name]['function'].match?(suffix.strip.lines.first))
LANGUAGE_METHOD_PATTERNS[@name]['empty_function'].match?(content_above_cursor.strip.lines.last) &&
(content_below_cursor.blank? || LANGUAGE_METHOD_PATTERNS[@name]['function'].match?(content_below_cursor
.strip.lines.first))
end
 
private
Loading
Loading
Loading
Loading
@@ -31,11 +31,11 @@ def language
end
strong_memoize_attr :language
 
def prefix
def content_above_cursor
params.dig(:current_file, :content_above_cursor)
end
 
def suffix
def content_below_cursor
params.dig(:current_file, :content_below_cursor)
end
end
Loading
Loading
Loading
Loading
@@ -45,12 +45,12 @@ def prompt
 
private
 
def pick_prefix
prefix.last(500)
def pick_content_above_cursor
content_above_cursor.last(500)
end
 
def pick_suffix
suffix.first(500)
def pick_content_below_cursor
content_below_cursor.first(500)
end
end
end
Loading
Loading
Loading
Loading
@@ -20,8 +20,8 @@ def request_params
type: PROMPT_COMPONENT_TYPE,
payload: {
file_name: file_name,
content_above_cursor: prefix,
content_below_cursor: suffix,
content_above_cursor: content_above_cursor,
content_below_cursor: content_below_cursor,
language_identifier: language.name,
prompt_id: PROMPT_ID,
stream: params.fetch(:stream, false),
Loading
Loading
@@ -53,12 +53,13 @@ def examples_section_params
end
 
def existing_code_block_params
trimmed_prefix = prefix.to_s.last(MAX_INPUT_CHARS)
trimmed_suffix = suffix.to_s.first(MAX_INPUT_CHARS - trimmed_prefix.size)
trimmed_content_above_cursor = content_above_cursor.to_s.last(MAX_INPUT_CHARS)
trimmed_content_below_cursor = content_below_cursor.to_s.first(MAX_INPUT_CHARS -
trimmed_content_above_cursor.size)
 
{
trimmed_prefix: trimmed_prefix,
trimmed_suffix: trimmed_suffix
trimmed_content_above_cursor: trimmed_content_above_cursor,
trimmed_content_below_cursor: trimmed_content_below_cursor
}
end
 
Loading
Loading
Loading
Loading
@@ -42,12 +42,12 @@ def prompt
params[:instruction]&.instruction.presence || ""
end
 
def pick_prefix
prefix.last(500)
def pick_content_above_cursor
content_above_cursor.last(500)
end
 
def pick_suffix
suffix.first(500)
def pick_content_below_cursor
content_below_cursor.first(500)
end
end
end
Loading
Loading
Loading
Loading
@@ -69,7 +69,7 @@ def prompt_enhancement
end
 
def existing_code_instruction
return unless params[:prefix].present?
return unless params[:content_above_cursor].present?
 
"The existing code is provided in <existing_code></existing_code> tags."
end
Loading
Loading
@@ -117,14 +117,15 @@ def instructions
end
 
def existing_code_block
return unless params[:prefix].present?
return unless params[:content_above_cursor].present?
 
trimmed_prefix = prefix.to_s.last(MAX_INPUT_CHARS)
trimmed_suffix = suffix.to_s.first(MAX_INPUT_CHARS - trimmed_prefix.size)
trimmed_content_above_cursor = content_above_cursor.to_s.last(MAX_INPUT_CHARS)
trimmed_content_below_cursor = content_below_cursor.to_s.first(MAX_INPUT_CHARS -
trimmed_content_above_cursor.size)
 
<<~CODE
<existing_code>
#{trimmed_prefix}{{cursor}}#{trimmed_suffix}
#{trimmed_content_above_cursor}{{cursor}}#{trimmed_content_below_cursor}
</existing_code>
CODE
end
Loading
Loading
Loading
Loading
@@ -10,15 +10,16 @@ def initialize(current_user, params:, unsafe_passthrough_params: {})
@params = params.except(:user_instruction, :context) if Feature.disabled?(:code_suggestions_context, current_user)
@unsafe_passthrough_params = unsafe_passthrough_params
 
@prefix = params.dig(:current_file, :content_above_cursor)
@suffix = params.dig(:current_file, :content_below_cursor)
@content_above_cursor = params.dig(:current_file, :content_above_cursor)
@content_below_cursor = params.dig(:current_file, :content_below_cursor)
@intent = params[:intent]
end
 
def task
trim_context!
 
instruction = extract_instruction(CodeSuggestions::FileContent.new(language, prefix, suffix))
instruction = extract_instruction(CodeSuggestions::FileContent.new(language, content_above_cursor,
content_below_cursor))
 
return code_completion_task unless instruction
 
Loading
Loading
@@ -27,7 +28,8 @@ def task
 
private
 
attr_reader :current_user, :params, :unsafe_passthrough_params, :prefix, :suffix, :intent
attr_reader :current_user, :params, :unsafe_passthrough_params, :content_above_cursor, :content_below_cursor,
:intent
 
def extract_instruction(file_content)
CodeSuggestions::InstructionsExtractor
Loading
Loading
@@ -58,7 +60,7 @@ def language
 
def code_generation_params(instruction)
params.merge(
prefix: prefix,
content_above_cursor: content_above_cursor,
instruction: instruction,
project: project,
current_user: current_user
Loading
Loading
Loading
Loading
@@ -12,8 +12,8 @@ def payload(content)
{
instances: [
{
prefix: content[:prefix],
suffix: content[:suffix]
content_above_cursor: content[:content_above_cursor],
content_below_cursor: content[:content_below_cursor]
}
],
parameters: Configuration.payload_parameters(maxOutputTokens: MAX_OUTPUT_TOKENS)
Loading
Loading
Loading
Loading
@@ -9,8 +9,8 @@
let(:api_path) { "/code_suggestions/completions" }
let(:url) { capybara_url(api(api_path)) }
 
let(:prefix) do
<<~PREFIX
let(:content_above_cursor) do
<<~CONTENT_ABOVE_CURSOR
def add(x, y):
return x + y
 
Loading
Loading
@@ -24,14 +24,14 @@ def divide(x, y):
return x / y
 
def is_even(n: int) ->
PREFIX
CONTENT_ABOVE_CURSOR
end
 
let(:body) do
{
current_file: {
file_name: 'test.py',
content_above_cursor: prefix,
content_above_cursor: content_above_cursor,
content_below_cursor: ''
},
stream: false
Loading
Loading
Loading
Loading
@@ -22,8 +22,8 @@
PROMPT
end
 
let(:suffix) { '' }
let(:file_content) { CodeSuggestions::FileContent.new(language, content, suffix) }
let(:content_below_cursor) { '' }
let(:file_content) { CodeSuggestions::FileContent.new(language, content_above_cursor, content_below_cursor) }
let(:intent) { nil }
let(:generation_type) { nil }
let(:user_instruction) { nil }
Loading
Loading
@@ -32,8 +32,8 @@
described_class.new(file_content, intent, generation_type, user_instruction).extract
end
 
context 'when content is nil' do
let(:content) { nil }
context 'when content_above_cursor is nil' do
let(:content_above_cursor) { nil }
 
it_behaves_like 'extracted instruction' do
let(:trigger_type) { 'small_file' }
Loading
Loading
@@ -42,7 +42,7 @@
 
context 'when language is not supported' do
let(:language) { CodeSuggestions::ProgrammingLanguage.new('foo') }
let(:content) do
let(:content_above_cursor) do
<<~CODE
full_name()
address()
Loading
Loading
@@ -56,7 +56,7 @@
CODE
end
 
context 'when content uses generic prefix sign' do
context 'when content_above_cursor uses generic prefix sign' do
let(:comment_sign) { '#' }
 
it_behaves_like 'extracted instruction' do
Loading
Loading
@@ -65,7 +65,7 @@
end
end
 
context 'when content uses special prefix sign' do
context 'when content_above_cursor uses special prefix sign' do
let(:comment_sign) { '!' }
 
it { is_expected.to be_nil }
Loading
Loading
@@ -73,7 +73,7 @@
end
 
context 'when there is instruction' do
let(:content) do
let(:content_above_cursor) do
<<~CODE
# Generate me a function
CODE
Loading
Loading
@@ -92,7 +92,7 @@
end
 
context 'when there is no instruction' do
let(:content) do
let(:content_above_cursor) do
<<~CODE
full_name()
address()
Loading
Loading
@@ -125,7 +125,7 @@
end
 
context 'when there is a user instruction' do
let(:content) { '' }
let(:content_above_cursor) { '' }
let(:user_instruction) { 'Generate me a hello world function' }
 
it_behaves_like 'extracted instruction' do
Loading
Loading
@@ -136,7 +136,7 @@
 
shared_examples_for 'detects comments correctly' do
context 'when there is only one comment line' do
let(:content) do
let(:content_above_cursor) do
<<~CODE
#{comment_sign}Generate me a function
CODE
Loading
Loading
@@ -149,7 +149,7 @@
end
 
context 'when the comment is too short' do
let(:content) do
let(:content_above_cursor) do
<<~CODE
#{comment_sign}Generate
CODE
Loading
Loading
@@ -161,7 +161,7 @@
end
 
context 'when the last line is not a comment but code is less than 5 lines' do
let(:content) do
let(:content_above_cursor) do
<<~CODE
#{comment_sign}A function that outputs the first 20 fibonacci numbers
 
Loading
Loading
@@ -176,7 +176,7 @@ def fibonacci(x)
end
 
context 'when there are some lines above the comment' do
let(:content) do
let(:content_above_cursor) do
<<~CODE
full_name()
address()
Loading
Loading
@@ -192,7 +192,7 @@ def fibonacci(x)
end
 
context 'when there are several comment in a row' do
let(:content) do
let(:content_above_cursor) do
<<~CODE
full_name()
address()
Loading
Loading
@@ -210,7 +210,7 @@ def fibonacci(x)
end
 
context 'when there are several comments in a row followed by empty line' do
let(:content) do
let(:content_above_cursor) do
# rubocop:disable Layout/TrailingWhitespace
<<~CODE
full_name()
Loading
Loading
@@ -230,7 +230,7 @@ def fibonacci(x)
end
 
context 'when there are several comments in a row followed by empty lines' do
let(:content) do
let(:content_above_cursor) do
<<~CODE
full_name()
address()
Loading
Loading
@@ -251,7 +251,7 @@ def fibonacci(x)
end
 
context 'when there are several comments in a row followed by other code' do
let(:content) do
let(:content_above_cursor) do
<<~CODE
full_name()
address()
Loading
Loading
@@ -271,7 +271,7 @@ def fibonacci(x)
end
 
context 'when the first line of multiline comment does not meet requirements' do
let(:content) do
let(:content_above_cursor) do
<<~CODE
full_name()
address()
Loading
Loading
@@ -287,7 +287,7 @@ def fibonacci(x)
CODE
end
 
let(:expected_prefix) do
let(:expected_content_above_cursor) do
<<~CODE
full_name()
address()
Loading
Loading
@@ -303,8 +303,8 @@ def fibonacci(x)
end
end
 
context 'when there is content between comment lines' do
let(:content) do
context 'when there is content_above_cursor between comment lines' do
let(:content_above_cursor) do
<<~CODE
full_name()
address()
Loading
Loading
@@ -327,13 +327,13 @@ def fibonacci(x)
end
end
 
context 'when content is a supported language' do
include_context 'with comment prefixes'
context 'when content_above_cursor is a supported language' do
include_context 'with comment contents_above_cursor'
 
languages_with_single_line_comment_prefix.each do |lang, pref|
context "when using language #{lang} and prefix #{pref}" do
languages_with_single_line_comment_content_above_cursor.each do |lang, content_above_cursor|
context "when using language #{lang} and content_above_cursor #{content_above_cursor}" do
let(:language) { CodeSuggestions::ProgrammingLanguage.new(lang) }
let(:comment_sign) { pref }
let(:comment_sign) { content_above_cursor }
 
it_behaves_like 'detects comments correctly'
end
Loading
Loading
@@ -352,8 +352,8 @@ def fibonacci(x)
INSTRUCTION
end
 
let(:content) do
<<~CONTENT
let(:content_above_cursor) do
<<~CONTENT_ABOVE_CURSOR
def func0():
return 0
 
Loading
Loading
@@ -365,11 +365,11 @@ def func1():
 
def index(arg1, arg2):
 
CONTENT
CONTENT_ABOVE_CURSOR
end
 
context 'when it is at the end of the file' do
let(:suffix) { '' }
let(:content_below_cursor) { '' }
 
it_behaves_like 'extracted instruction' do
let(:trigger_type) { 'empty_function' }
Loading
Loading
@@ -377,7 +377,7 @@ def index(arg1, arg2):
end
 
context 'when cursor is inside an empty method but middle of the file' do
let(:suffix) do
let(:content_below_cursor) do
<<~SUFFIX
def index2():
return 0
Loading
Loading
@@ -393,7 +393,7 @@ def index3(arg1):
end
 
context 'when cursor in inside a non-empty method' do
let(:suffix) do
let(:content_below_cursor) do
<<~SUFFIX
return 0
 
Loading
Loading
Loading
Loading
@@ -64,20 +64,20 @@
context 'when single_regexp is specified' do
let(:language) { described_class.new('VBScript') }
 
it 'will prefer regexp to string' do
it 'prefers regexp to string' do
is_expected.to be_a(Regexp)
end
end
end
 
describe '#single_line_comment?' do
include_context 'with comment prefixes'
include_context 'with comment contents_above_cursor'
 
subject { described_class.new(language).single_line_comment?(content) }
 
shared_examples 'single line comment for supported language' do
context "when it is a comment" do
let(:content) { "#{prefix} this is a comment " }
let(:content) { "#{content_above_cursor} this is a comment " }
 
it { is_expected.to be_truthy }
end
Loading
Loading
@@ -89,29 +89,29 @@
end
 
context "when line doesn't start with comment" do
let(:content) { "def something() { #{prefix} this is a comment " }
let(:content) { "def something() { #{content_above_cursor} this is a comment " }
 
it { is_expected.to be_falsey }
end
 
context "when there is whitespace before the comment" do
let(:content) { " #{prefix} this is a comment " }
let(:content) { " #{content_above_cursor} this is a comment " }
 
it { is_expected.to be_truthy }
end
 
context "when it is a comment for different language" do
let(:non_comment_prefix) { prefix == '#' ? '//' : '#' }
let(:content) { "#{non_comment_prefix} this is a comment " }
let(:non_comment_content_above_cursor) { content_above_cursor == '#' ? '//' : '#' }
let(:content) { "#{non_comment_content_above_cursor} this is a comment " }
 
it { is_expected.to be_falsey }
end
end
 
languages_with_single_line_comment_prefix.each do |lang, pref|
context "with language #{lang} and prefix #{pref}" do
languages_with_single_line_comment_content_above_cursor.each do |lang, content_above_cursor|
context "with language #{lang} and content_above_cursor #{content_above_cursor}" do
let(:language) { lang }
let(:prefix) { pref }
let(:content_above_cursor) { content_above_cursor }
 
it_behaves_like 'single line comment for supported language'
end
Loading
Loading
@@ -132,13 +132,13 @@
context "when the language is not supported" do
let(:language) { 'foo' }
 
context "when a common comment prefix is used" do
context "when a common comment content_above_cursor is used" do
let(:content) { "// this is a comment " }
 
it { is_expected.to be_truthy }
end
 
context "when a special comment prefix is used" do
context "when a special comment content_above_cursor is used" do
let(:content) { "; this is a comment" }
 
it { is_expected.to be_falsey }
Loading
Loading
Loading
Loading
@@ -23,8 +23,8 @@ def prompt
let(:current_file) do
{
'file_name' => 'test.py',
'content_above_cursor' => 'some prefix',
'content_below_cursor' => 'some suffix'
'content_above_cursor' => "some content_above_cursor that ends in lots of #{'a' * 1000}",
'content_below_cursor' => "#{'b' * 1000} is the letter that leads some content_below_cursor"
}.with_indifferent_access
end
 
Loading
Loading
@@ -62,4 +62,16 @@ def prompt
).prompt).to be_nil
end
end
describe '#pick_content_above_cursor' do
it 'returns the last 500 characters of the content' do
expect(dummy_message.send(:pick_content_above_cursor)).to eq('a' * 500)
end
end
describe '#pick_content_below_cursor' do
it 'returns the first 500 characters of the content' do
expect(dummy_message.send(:pick_content_below_cursor)).to eq('b' * 500)
end
end
end
Loading
Loading
@@ -21,8 +21,8 @@ def expected_request_params
stream: expected_stream,
prompt_enhancer: {
examples_array: expected_examples_array,
trimmed_prefix: expected_trimmed_prefix,
trimmed_suffix: expected_trimmed_suffix,
trimmed_content_above_cursor: expected_trimmed_content_above_cursor,
trimmed_content_below_cursor: expected_trimmed_content_below_cursor,
related_files: expected_related_files,
related_snippets: expected_related_snippets,
libraries: expected_libraries,
Loading
Loading
Loading
Loading
@@ -7,11 +7,18 @@
 
let(:prompt_version) { 2 }
 
let(:suffix) do
<<~SUFFIX
let(:content_above_cursor) do
<<~CONTENT_ABOVE_CURSOR
"binary search desc that ends in lots of random #{'a' * 1000}"
CONTENT_ABOVE_CURSOR
end
let(:content_below_cursor) do
<<~CONTENT_BELOW_CURSOR
def use_binary_search
// this is a random comment with lots of random letter #{'b' * 1000}
end
SUFFIX
CONTENT_BELOW_CURSOR
end
 
let(:comment) { 'Generate a binary search method.' }
Loading
Loading
@@ -52,4 +59,39 @@ def use_binary_search
end
end
end
describe '#pick_content_above_cursor' do
let(:params) do
{
current_file: {
content_above_cursor: content_above_cursor
}
}
end
it 'returns the last 500 characters of the content' do
expected_output = "#{'a' * 498}\"\n"
expect(prompt.send(:pick_content_above_cursor)).to eq(expected_output)
end
end
describe '#pick_content_below_cursor' do
let(:params) do
{
current_file: {
content_below_cursor: content_below_cursor
}
}
end
it 'returns the first 500 characters of the content' do
expected_output = <<~EXPECTED.chomp
def use_binary_search
// this is a random comment with lots of random letter #{'b' * 421}
EXPECTED
expect(prompt.send(:pick_content_below_cursor)).to eq(expected_output)
end
end
end
Loading
Loading
@@ -12,14 +12,14 @@
]
end
 
let(:prefix) do
<<~PREFIX
let(:content_above_cursor) do
<<~CONTENT_ABOVE_CURSOR
package main
 
import "fmt"
 
func main() {
PREFIX
CONTENT_ABOVE_CURSOR
end
 
let(:file_name) { 'main.go' }
Loading
Loading
@@ -32,7 +32,7 @@
{
'current_file' => {
'file_name' => file_name,
'content_above_cursor' => prefix
'content_above_cursor' => content_above_cursor
},
'telemetry' => [{ 'model_engine' => 'anthropic' }]
}
Loading
Loading
@@ -40,7 +40,7 @@
 
let(:params) do
{
prefix: prefix,
content_above_cursor: content_above_cursor,
instruction: instruction,
current_file: unsafe_params['current_file'].with_indifferent_access,
context: context
Loading
Loading
@@ -124,7 +124,7 @@
end
end
 
context 'when prefix is present' do
context 'when content_above_cursor is present' do
let(:system_prompt) do
<<~PROMPT.chomp
You are a tremendously accurate and skilled coding autocomplete agent. We want to generate new Go code inside the
Loading
Loading
@@ -206,7 +206,7 @@
{
project: xray.project,
current_user: current_user,
prefix: prefix,
content_above_cursor: content_above_cursor,
instruction: instruction,
current_file: unsafe_params['current_file'].with_indifferent_access
}
Loading
Loading
@@ -426,9 +426,9 @@
end
end
 
context 'when prefix is blank' do
context 'when content_above_cursor is blank' do
let(:examples) { [] }
let(:prefix) { '' }
let(:content_above_cursor) { '' }
let(:system_prompt) do
<<~PROMPT.chomp
You are a tremendously accurate and skilled coding autocomplete agent. We want to generate new Go code inside the
Loading
Loading
@@ -467,7 +467,7 @@
end
end
 
context 'when prefix is bigger than prompt limit' do
context 'when content_above_cursor is bigger than prompt limit' do
let(:examples) { [] }
let(:system_prompt) do
<<~PROMPT.chomp
Loading
Loading
@@ -684,8 +684,8 @@
let(:expected_content_below_cursor) { content_below_cursor }
let(:expected_language_identifier) { 'Go' }
let(:expected_examples_array) { examples }
let(:expected_trimmed_prefix) { content_above_cursor }
let(:expected_trimmed_suffix) { content_below_cursor }
let(:expected_trimmed_content_above_cursor) { content_above_cursor }
let(:expected_trimmed_content_below_cursor) { content_below_cursor }
let(:expected_libraries) { ['zlib (1.2.3)', 'boost (2.0.0)'] }
let(:expected_user_instruction) { comment }
let(:expected_stream) { true }
Loading
Loading
@@ -725,10 +725,10 @@
subject.request_params
end
 
context 'when the prefix length exceeds the prompt limit' do
context 'when the content_above_cursor length exceeds the prompt limit' do
let(:limit) { 10 }
let(:expected_trimmed_prefix) { content_above_cursor.last(limit) }
let(:expected_trimmed_suffix) { '' }
let(:expected_trimmed_content_above_cursor) { content_above_cursor.last(limit) }
let(:expected_trimmed_content_below_cursor) { '' }
 
before do
stub_const('CodeSuggestions::Prompts::CodeGeneration::AiGatewayMessages::MAX_INPUT_CHARS', limit)
Loading
Loading
@@ -738,10 +738,10 @@
expect(subject.request_params).to eq(expected_request_params)
end
 
context 'when the combined prefix and suffix length exceeds the prompt limit' do
context 'when the combined content_above_cursor and content_below_cursor length exceeds the prompt limit' do
let(:limit) { content_above_cursor.size + 5 }
let(:expected_trimmed_prefix) { content_above_cursor }
let(:expected_trimmed_suffix) { content_below_cursor.first(5) }
let(:expected_trimmed_content_above_cursor) { content_above_cursor }
let(:expected_trimmed_content_below_cursor) { content_below_cursor.first(5) }
 
it 'returns expected request params' do
expect(subject.request_params).to eq(expected_request_params)
Loading
Loading
@@ -761,8 +761,8 @@
let(:expected_content_below_cursor) { nil }
let(:expected_language_identifier) { '' }
let(:expected_examples_array) { [] }
let(:expected_trimmed_prefix) { '' }
let(:expected_trimmed_suffix) { '' }
let(:expected_trimmed_content_above_cursor) { '' }
let(:expected_trimmed_content_below_cursor) { '' }
let(:expected_libraries) { [] }
let(:expected_user_instruction) { 'Generate the best possible code based on instructions.' }
let(:expected_related_files) { [] }
Loading
Loading
Loading
Loading
@@ -8,8 +8,8 @@
describe '.task' do
let_it_be(:current_user) { create(:user) }
let(:file_name) { 'python.py' }
let(:prefix) { 'some prefix' }
let(:suffix) { 'some suffix' }
let(:content_above_cursor) { 'some content_above_cursor' }
let(:content_below_cursor) { 'some content_below_cursor' }
let(:user_instruction) { nil }
let(:expected_project) { nil }
 
Loading
Loading
@@ -21,8 +21,8 @@
{
current_file: {
file_name: file_name,
content_above_cursor: prefix,
content_below_cursor: suffix
content_above_cursor: content_above_cursor,
content_below_cursor: content_below_cursor
},
generation_type: 'empty_function',
user_instruction: user_instruction,
Loading
Loading
@@ -30,7 +30,7 @@
{ type: 'file', name: 'main.go', content: 'package main' }
],
instruction: instruction,
prefix: prefix,
content_above_cursor: content_above_cursor,
project: expected_project,
current_user: current_user
}
Loading
Loading
@@ -123,8 +123,8 @@
{
current_file: {
file_name: file_name,
content_above_cursor: prefix,
content_below_cursor: suffix
content_above_cursor: content_above_cursor,
content_below_cursor: content_below_cursor
},
project_path: expected_project.full_path
}
Loading
Loading
@@ -176,7 +176,7 @@
current_user: current_user,
params: params.except(:user_instruction, :context).merge(
instruction: instruction,
prefix: prefix,
content_above_cursor: content_above_cursor,
project: expected_project,
current_user: current_user
),
Loading
Loading
Loading
Loading
@@ -8,13 +8,13 @@
let(:current_file) do
{
'file_name' => 'test.py',
'content_above_cursor' => 'some prefix',
'content_below_cursor' => 'some suffix'
'content_above_cursor' => 'some content_above_cursor',
'content_below_cursor' => 'some content_below_cursor'
}.with_indifferent_access
end
 
let(:expected_current_file) do
{ current_file: { file_name: 'test.py', content_above_cursor: 'fix', content_below_cursor: 'som' } }
{ current_file: { file_name: 'test.py', content_above_cursor: 'sor', content_below_cursor: 'som' } }
end
 
before do
Loading
Loading
@@ -54,7 +54,7 @@
{
"current_file" => {
"file_name" => "test.py",
"content_above_cursor" => "fix",
"content_above_cursor" => "sor",
"content_below_cursor" => "som"
},
"telemetry" => [{ "model_engine" => "vertex-ai" }],
Loading
Loading
@@ -78,7 +78,7 @@
"model_provider" => "vertex-ai",
"current_file" => {
"file_name" => "test.py",
"content_above_cursor" => "fix",
"content_above_cursor" => "sor",
"content_below_cursor" => "som"
},
"telemetry" => [{ "model_engine" => "vertex-ai" }],
Loading
Loading
@@ -130,7 +130,7 @@
{
"current_file" => {
"file_name" => "test.py",
"content_above_cursor" => "fix",
"content_above_cursor" => "sor",
"content_below_cursor" => "som"
},
"telemetry" => [],
Loading
Loading
Loading
Loading
@@ -3,19 +3,19 @@
require 'spec_helper'
 
RSpec.describe CodeSuggestions::Tasks::CodeGeneration, feature_category: :code_suggestions do
let(:prefix) { 'some prefix' }
let(:suffix) { 'some suffix' }
let(:content_above_cursor) { 'some content_above_cursor' }
let(:content_below_cursor) { 'some content_below_cursor' }
let(:instruction) { CodeSuggestions::Instruction.from_trigger_type('comment') }
let(:current_file) do
{
'file_name' => 'test.py',
'content_above_cursor' => prefix,
'content_below_cursor' => suffix
'content_above_cursor' => content_above_cursor,
'content_below_cursor' => content_below_cursor
}.with_indifferent_access
end
 
let(:expected_current_file) do
{ current_file: { file_name: 'test.py', content_above_cursor: 'fix', content_below_cursor: 'som' } }
{ current_file: { file_name: 'test.py', content_above_cursor: 'sor', content_below_cursor: 'som' } }
end
 
context 'when using saas anthropic model' do
Loading
Loading
@@ -35,7 +35,7 @@
let(:params) do
{
code_generation_model_family: :anthropic,
prefix: prefix,
content_above_cursor: content_above_cursor,
instruction: instruction,
current_file: current_file,
model_name: 'claude-3-5-sonnet-20240620'
Loading
Loading
@@ -49,8 +49,8 @@
'type' => 'code_editor_generation',
'payload' => {
'file_name' => 'test.py',
'content_above_cursor' => 'some prefix',
'content_below_cursor' => 'some suffix',
'content_above_cursor' => 'some content_above_cursor',
'content_below_cursor' => 'some content_below_cursor',
'language_identifier' => 'Python',
'prompt_id' => 'code_suggestions/generations',
'prompt_enhancer' => {
Loading
Loading
@@ -66,8 +66,8 @@
'trigger_type' => 'comment'
}
],
'trimmed_prefix' => 'some prefix',
'trimmed_suffix' => 'some suffix',
'trimmed_content_above_cursor' => 'some content_above_cursor',
'trimmed_content_below_cursor' => 'some content_below_cursor',
'related_files' => '',
'related_snippets' => '',
'libraries' => '',
Loading
Loading
@@ -99,15 +99,15 @@
let(:expected_body) do
{
'current_file' => {
'content_above_cursor' => 'fix',
'content_above_cursor' => 'sor',
'content_below_cursor' => 'som',
'file_name' => 'test.py'
},
'prompt_components' => [
{
'payload' => {
'content_above_cursor' => 'some prefix',
'content_below_cursor' => 'some suffix',
'content_above_cursor' => 'some content_above_cursor',
'content_below_cursor' => 'some content_below_cursor',
'file_name' => 'test.py',
'language_identifier' => 'Python',
'prompt_enhancer' => {
Loading
Loading
@@ -123,8 +123,8 @@
'trigger_type' => 'comment'
}
],
'trimmed_prefix' => 'some prefix',
'trimmed_suffix' => 'some suffix',
'trimmed_content_above_cursor' => 'some content_above_cursor',
'trimmed_content_below_cursor' => 'some content_below_cursor',
'related_files' => '',
'related_snippets' => '',
'libraries' => '',
Loading
Loading
@@ -170,7 +170,7 @@
{
"current_file" => {
"file_name" => "test.py",
"content_above_cursor" => "fix",
"content_above_cursor" => "sor",
"content_below_cursor" => "som"
},
"telemetry" => [{ "model_engine" => "anthropic" }],
Loading
Loading
@@ -213,8 +213,8 @@
"telemetry" => [],
"prompt_id" => "code_suggestions/generations",
"current_file" => {
"content_above_cursor" => "some prefix",
"content_below_cursor" => "some suffix",
"content_above_cursor" => "some content_above_cursor",
"content_below_cursor" => "some content_below_cursor",
"file_name" => "test.py"
},
"model_api_key" => "token",
Loading
Loading
Loading
Loading
@@ -297,8 +297,8 @@
{
file_name: 'test.py',
selected_text: selected_text,
cotent_above_cursor: 'prefix',
content_below_cursor: 'suffix'
cotent_above_cursor: 'content_above_cursor',
content_below_cursor: 'content_below_cursor'
}
end
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment