Skip to content

Commit

Permalink
Merge pull request #159 from codestoryai/features/fix-how-prompt-gets…
Browse files Browse the repository at this point in the history
…-constructed

[sidecar] use proper calcluations for constructing the prompt
  • Loading branch information
theskcd authored Oct 19, 2023
2 parents 46bc1d8 + 649b433 commit c487481
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 31 deletions.
Binary file modified src/.DS_Store
Binary file not shown.
72 changes: 42 additions & 30 deletions src/agent/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,38 +804,50 @@ impl Agent {
match self.get_last_conversation_message_agent_state() {
&AgentState::Explain => {
if let Some(user_selected_context_slice) = user_selected_context {
prompt += "##### SELECTED CODE CONTEXT #####\n";
for user_selected_context in user_selected_context_slice.iter() {
let snippet = user_selected_context
.data
.lines()
.enumerate()
.map(|(i, line)| {
format!(
"{} {line}\n",
i + user_selected_context.start_line as usize + 1
let selected_code_context = "##### SELECTED CODE CONTEXT #####\n";
let selected_code_header_tokens =
bpe.encode_ordinary(&selected_code_context).len();
if selected_code_header_tokens
>= remaining_prompt_tokens - self.model.prompt_tokens_limit
{
info!("we can't set selected selection because of prompt limit");
} else {
prompt += "##### SELECTED CODE CONTEXT #####\n";
remaining_prompt_tokens -= selected_code_header_tokens;

for user_selected_context in user_selected_context_slice.iter() {
let snippet = user_selected_context
.data
.lines()
.enumerate()
.map(|(i, line)| {
format!(
"{} {line}\n",
i + user_selected_context.start_line as usize + 1
)
})
.collect::<String>();

let formatted_string = format!(
"### {} ###\n{snippet}\n\n",
self.get_absolute_path(
self.reporef(),
&user_selected_context.file_path
)
})
.collect::<String>();

let formatted_string = format!(
"### {} ###\n{snippet}\n\n",
self.get_absolute_path(
self.reporef(),
&user_selected_context.file_path
)
);

let snippet_tokens = bpe.encode_ordinary(&formatted_string).len();
if snippet_tokens
>= remaining_prompt_tokens - self.model.prompt_tokens_limit
{
info!("breaking at {} tokens", remaining_prompt_tokens);
break;
}
);

let snippet_tokens = bpe.encode_ordinary(&formatted_string).len();
if snippet_tokens
>= remaining_prompt_tokens - self.model.prompt_tokens_limit
{
info!("breaking at {} tokens", remaining_prompt_tokens);
break;
}
prompt += &formatted_string;

// Make sure we are always in the context limit
remaining_prompt_tokens -= snippet_tokens;
// Make sure we are always in the context limit
remaining_prompt_tokens -= snippet_tokens;
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/indexes/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl CodeSnippet {

let unique_hash = builder.add_text_field("unique_hash", STRING | STORED);

let repo_disk_path = dbg!(builder.add_text_field("repo_disk_path", STRING));
let repo_disk_path = builder.add_text_field("repo_disk_path", STRING);
let repo_ref = builder.add_text_field("repo_ref", STRING | STORED);
let repo_name = builder.add_text_field("repo_name", code_snippet_tokenizer.clone());
let relative_path = builder.add_text_field("relative_path", code_snippet_tokenizer.clone());
Expand Down

0 comments on commit c487481

Please sign in to comment.