Compare commits

...

1 Commits

Author SHA1 Message Date
Max Brunsfeld
2e72b64547 Remove assistant2 SubmitMode 2024-05-09 20:50:25 -07:00
3 changed files with 32 additions and 31 deletions

View File

@@ -48,18 +48,7 @@ pub use assistant_settings::AssistantSettings;
const MAX_COMPLETION_CALLS_PER_SUBMISSION: usize = 5;
#[derive(Eq, PartialEq, Copy, Clone, Deserialize)]
pub struct Submit(SubmitMode);
/// There are multiple different ways to submit a model request, represented by this enum.
#[derive(Eq, PartialEq, Copy, Clone, Deserialize)]
pub enum SubmitMode {
/// Only include the conversation.
Simple,
/// Send the current file as context.
CurrentFile,
/// Search the codebase and send relevant excerpts.
Codebase,
}
pub struct Submit;
gpui::actions!(assistant2, [Cancel, ToggleFocus, DebugProjectIndex,]);
gpui::impl_actions!(assistant2, [Submit]);
@@ -391,7 +380,7 @@ impl AssistantChat {
cx.propagate();
}
fn submit(&mut self, Submit(mode): &Submit, cx: &mut ViewContext<Self>) {
fn submit(&mut self, _: &Submit, cx: &mut ViewContext<Self>) {
if let Some(focused_message_id) = self.focused_message_id(cx) {
self.truncate_messages(focused_message_id, cx);
self.pending_completion.take();
@@ -429,7 +418,6 @@ impl AssistantChat {
return;
}
let mode = *mode;
self.pending_completion = Some(cx.spawn(move |this, mut cx| async move {
let attachments_task = this.update(&mut cx, |this, cx| {
let attachment_registry = this.attachment_registry.clone();
@@ -454,14 +442,9 @@ impl AssistantChat {
})
.log_err();
Self::request_completion(
this.clone(),
mode,
MAX_COMPLETION_CALLS_PER_SUBMISSION,
&mut cx,
)
.await
.log_err();
Self::request_completion(this.clone(), MAX_COMPLETION_CALLS_PER_SUBMISSION, &mut cx)
.await
.log_err();
this.update(&mut cx, |this, _cx| {
this.pending_completion = None;
@@ -473,7 +456,6 @@ impl AssistantChat {
async fn request_completion(
this: WeakView<Self>,
mode: SubmitMode,
limit: usize,
cx: &mut AsyncWindowContext,
) -> Result<()> {
@@ -483,9 +465,7 @@ impl AssistantChat {
let (tool_definitions, model_name, messages) = this.update(cx, |this, cx| {
this.push_new_assistant_message(cx);
let definitions = if call_count < limit
&& matches!(mode, SubmitMode::Codebase | SubmitMode::Simple)
{
let definitions = if call_count < limit {
this.tool_registry.definitions()
} else {
Vec::new()
@@ -887,6 +867,21 @@ impl AssistantChat {
let mut project_context = ProjectContext::new(project, fs);
let mut completion_messages = Vec::new();
completion_messages.push(CompletionMessage::System {
content: r#"
You are the assistant for the Zed code editor.
Your job is to help the user understand and modify their own code.
Use tools to retrieve the information needed to give answers that are
specific to the user's codebase. Do NOT give generic answers that are
not specific to the user's codebase.
Whenever possible, use tools to display code in the editor.
"#
.lines()
.map(|line| line.trim_start())
.filter(|line| !line.is_empty())
.collect(),
});
for message in &self.messages {
match message {
ChatMessage::User(UserMessage {

View File

@@ -45,7 +45,7 @@ struct Excerpt {
path: String,
/// A short, distinctive string that appears in the file, used to define a location in the file.
text_passage: String,
/// Text to display above the code excerpt
/// Text to display above the code excerpt. All explanation of code should be included here.
annotation: String,
}
@@ -53,11 +53,17 @@ impl LanguageModelTool for AnnotationTool {
type View = AnnotationResultView;
fn name(&self) -> String {
"annotate_code".to_string()
"show_code_file_excerpts".to_string()
}
fn description(&self) -> String {
"Dynamically annotate symbols in the current codebase. Opens a buffer in a panel in their editor, to the side of the conversation. The annotations are shown in the editor as a block decoration.".to_string()
"
Show and explain code from the current project
Opens a buffer in a separate pane/tab, to the side of the conversation.
The annotations are shown in the editor as block decorations.
Many related excerpts can be shown at once.
"
.to_string()
}
fn view(&self, cx: &mut WindowContext) -> View<Self::View> {

View File

@@ -35,11 +35,11 @@ impl LanguageModelTool for CreateBufferTool {
type View = CreateBufferView;
fn name(&self) -> String {
"create_buffer".to_string()
"create_new_source_file".to_string()
}
fn description(&self) -> String {
"Create a new buffer in the current codebase".to_string()
"Create a new file in the current codebase. Only use this when generating new code, NOT when showing existing code from the project.".to_string()
}
fn view(&self, cx: &mut WindowContext) -> View<Self::View> {