Don't use the summary as the filename if it's not done yet

This commit is contained in:
Antonio Scandurra 2023-06-20 19:19:02 +02:00
parent f904698457
commit c416551318

View file

@ -464,12 +464,18 @@ struct SavedConversationPath {
had_summary: bool, had_summary: bool,
} }
#[derive(Default)]
struct Summary {
text: String,
done: bool,
}
struct Assistant { struct Assistant {
buffer: ModelHandle<Buffer>, buffer: ModelHandle<Buffer>,
message_anchors: Vec<MessageAnchor>, message_anchors: Vec<MessageAnchor>,
messages_metadata: HashMap<MessageId, MessageMetadata>, messages_metadata: HashMap<MessageId, MessageMetadata>,
next_message_id: MessageId, next_message_id: MessageId,
summary: Option<String>, summary: Option<Summary>,
pending_summary: Task<Option<()>>, pending_summary: Task<Option<()>>,
completion_count: usize, completion_count: usize,
pending_completions: Vec<PendingCompletion>, pending_completions: Vec<PendingCompletion>,
@ -954,12 +960,22 @@ impl Assistant {
if let Some(choice) = message.choices.pop() { if let Some(choice) = message.choices.pop() {
let text = choice.delta.content.unwrap_or_default(); let text = choice.delta.content.unwrap_or_default();
this.update(&mut cx, |this, cx| { this.update(&mut cx, |this, cx| {
this.summary.get_or_insert(String::new()).push_str(&text); this.summary
.get_or_insert(Default::default())
.text
.push_str(&text);
cx.emit(AssistantEvent::SummaryChanged); cx.emit(AssistantEvent::SummaryChanged);
}); });
} }
} }
this.update(&mut cx, |this, cx| {
if let Some(summary) = this.summary.as_mut() {
summary.done = true;
cx.emit(AssistantEvent::SummaryChanged);
}
});
anyhow::Ok(()) anyhow::Ok(())
} }
.log_err() .log_err()
@ -1056,8 +1072,19 @@ impl Assistant {
}), }),
}; };
let (old_path, summary) = let (old_path, summary) = this.read_with(&cx, |this, _| {
this.read_with(&cx, |this, _| (this.path.clone(), this.summary.clone())); let path = this.path.clone();
let summary = if let Some(summary) = this.summary.as_ref() {
if summary.done {
Some(summary.text.clone())
} else {
None
}
} else {
None
};
(path, summary)
});
let mut new_path = None; let mut new_path = None;
if let Some(old_path) = old_path.as_ref() { if let Some(old_path) = old_path.as_ref() {
if old_path.had_summary || summary.is_none() { if old_path.had_summary || summary.is_none() {
@ -1555,7 +1582,8 @@ impl AssistantEditor {
self.assistant self.assistant
.read(cx) .read(cx)
.summary .summary
.clone() .as_ref()
.map(|summary| summary.text.clone())
.unwrap_or_else(|| "New Context".into()) .unwrap_or_else(|| "New Context".into())
} }
} }