Skip to content

Commit

Permalink
Merge pull request #1640 from codestoryai/features/cleanup-and-emphas…
Browse files Browse the repository at this point in the history
…ize-absolute-paths

[sidecar] cleanup and emphasize absolute paths
  • Loading branch information
theskcd authored Dec 17, 2024
2 parents 59f4ea4 + ab15fe4 commit 44bf969
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 310 deletions.
5 changes: 0 additions & 5 deletions sidecar/src/agentic/symbol/events/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ impl SymbolToEdit {
}
}

pub fn set_should_stream_status(mut self, should_stream: bool) -> Self {
self.should_stream = should_stream;
self
}

pub fn should_stream(&self) -> bool {
self.should_stream
}
Expand Down
6 changes: 4 additions & 2 deletions sidecar/src/agentic/tool/code_edit/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ Edit a file. The tool is able to edit the file precisely based on instruction. I
fn tool_input_format(&self) -> String {
format!(
r#"Parameters:
- fs_file_path: (required) The absolute path of the file to write to, will be created if not already present
- fs_file_path: (required) The ABSOLUTE path of the file to write to, will be created if not already present
- instruction: (required) The edit instruction, if you are going to output code blocks make sure they are properly placed in ```{{language}} blocks so we can present them properly to the user. Only given instructions here which are concise and contain the relevant changes, do not be verbose.
Usage:
Expand All @@ -500,7 +500,9 @@ File path here
<instruction>
Edit instruction here
</instruction>
</code_edit_input>"#
</code_edit_input>
The fs_file_path here needs to be the ABSOLUTE and never the relative path."#
)
}

Expand Down
2 changes: 0 additions & 2 deletions sidecar/src/agentic/tool/session/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,6 @@ impl SessionService {
tool_type.clone(),
tool_input_partial,
tool_box.clone(),
false,
tool_agent.clone(),
user_message.to_owned(),
false,
Expand Down Expand Up @@ -630,7 +629,6 @@ impl SessionService {
tool_type.clone(),
tool_input_partial,
tool_box.clone(),
true,
tool_agent.clone(),
user_message.to_owned(),
false, // is not part of test genertaion
Expand Down
65 changes: 5 additions & 60 deletions sidecar/src/agentic/tool/session/session.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! We can create a new session over here and its composed of exchanges
//! The exchanges can be made by the human or the agent
use std::{collections::HashMap, path::Path, sync::Arc};
use std::{collections::HashMap, sync::Arc};

use futures::StreamExt;
use tokio::io::AsyncWriteExt;
Expand Down Expand Up @@ -2167,7 +2167,6 @@ The Github Issue we are trying to solve is:
tool_type: ToolType,
tool_input_partial: ToolInputPartial,
tool_box: Arc<ToolBox>,
should_stream_edits: bool,
tool_agent: ToolUseAgent,
original_user_message: String,
is_test_generation: bool,
Expand Down Expand Up @@ -2295,7 +2294,7 @@ The Github Issue we are trying to solve is:

// if the file is very very large then we chunk it up and use search and replace
// on individual chunks instead
let updated_code = if file_contents.lines().into_iter().collect::<Vec<_>>().len()
let _ = if file_contents.lines().into_iter().collect::<Vec<_>>().len()
>= 1300
// if we are not in swe_bench mode, never try to be extra, go with
// the standard search and replace flow
Expand Down Expand Up @@ -2351,8 +2350,7 @@ The Github Issue we are trying to solve is:
None,
vec![], // previous_user_queries
None,
)
.set_should_stream_status(should_stream_edits);
);

let symbol_identifier = SymbolIdentifier::new_symbol(&fs_file_path);

Expand Down Expand Up @@ -2388,8 +2386,7 @@ The Github Issue we are trying to solve is:
None,
vec![], // previous_user_queries
None,
)
.set_should_stream_status(should_stream_edits);
);

let symbol_identifier = SymbolIdentifier::new_symbol(&fs_file_path);

Expand Down Expand Up @@ -2434,8 +2431,7 @@ This is part of the file which might not contain the method in full, if thats th
None,
vec![], // previous_user_queries
None,
)
.set_should_stream_status(should_stream_edits);
);

let symbol_identifier = SymbolIdentifier::new_symbol(&fs_file_path);

Expand All @@ -2454,57 +2450,6 @@ This is part of the file which might not contain the method in full, if thats th
)
.await? // big expectations but can also fail, we should handle it properly
};
// This code-block only ever hits for the swe-bench run and nothing else
// in the future we should create a tool for this, but this will help unblock us
if !should_stream_edits {
// we want to update the whole file content with the new content over here
// first we check if the file really exists on the fs, if it does not we create it
if let Ok(false) = tokio::fs::try_exists(fs_file_path.to_owned()).await {
tokio::fs::create_dir_all(
Path::new(&fs_file_path).parent().expect("to exist"),
)
.await
.expect("creating parent directory to work");
tokio::fs::File::create(fs_file_path.to_owned())
.await
.expect("file creation to not fail");
}
let _ =
tokio::fs::write(fs_file_path.to_owned(), updated_code.to_owned()).await;

// we have the original file content and the updated code content
// we want to generate a git-diff between the 2 and pass that to the LLM implicitly
// since we do not have a recent-edits handle easily implemented in python mock editor
// This is really bad but we are interested in testing out things for now (DO NOT COMMIT)
let client = reqwest::Client::new();
let original_content = &file_contents;
let request_object = serde_json::json!({
"original_content": original_content,
"modified_content": updated_code,
"fs_file_path": fs_file_path,
});
let response = client
.post(message_properties.editor_url() + "/diff_generator")
.body(serde_json::to_string(&request_object).expect("to work"))
.send()
.await
.expect("to get a reply");
#[derive(serde::Deserialize)]
struct FileEditedResponseStruct {
generated_diff: String,
}
let response: FileEditedResponseStruct =
response.json().await.expect("to work");

self = self.tool_output(
&exchange_id,
tool_type.clone(),
format!(r#"I performed the edits which you asked for, here is the git diff for it:
{}"#, response.generated_diff),
UserContext::default()
);
return Ok(self);
}

// now that we have modified the file we can ask the editor for the git-diff of this file over here
// and we also have the previous state over here
Expand Down
Loading

0 comments on commit 44bf969

Please sign in to comment.