Allow attaching text threads as context (#29947)
Release Notes: - N/A --------- Co-authored-by: Michael Sloan <mgsloan@gmail.com>
This commit is contained in:
parent
7f868a2eff
commit
dd79c29af9
24 changed files with 784 additions and 245 deletions
|
@ -32,7 +32,7 @@ use serde::{Deserialize, Serialize};
|
|||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
cmp::{Ordering, max},
|
||||
fmt::Debug,
|
||||
fmt::{Debug, Write as _},
|
||||
iter, mem,
|
||||
ops::Range,
|
||||
path::Path,
|
||||
|
@ -2539,6 +2539,26 @@ impl AssistantContext {
|
|||
Some(user_message)
|
||||
}
|
||||
|
||||
pub fn to_xml(&self, cx: &App) -> String {
|
||||
let mut output = String::new();
|
||||
let buffer = self.buffer.read(cx);
|
||||
for message in self.messages(cx) {
|
||||
if message.status != MessageStatus::Done {
|
||||
continue;
|
||||
}
|
||||
|
||||
writeln!(&mut output, "<{}>", message.role).unwrap();
|
||||
for chunk in buffer.text_for_range(message.offset_range) {
|
||||
output.push_str(chunk);
|
||||
}
|
||||
if !output.ends_with('\n') {
|
||||
output.push('\n');
|
||||
}
|
||||
writeln!(&mut output, "</{}>", message.role).unwrap();
|
||||
}
|
||||
output
|
||||
}
|
||||
|
||||
pub fn to_completion_request(
|
||||
&self,
|
||||
request_type: RequestType,
|
||||
|
|
|
@ -339,7 +339,11 @@ impl ContextStore {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn contexts(&self) -> Vec<SavedContextMetadata> {
|
||||
pub fn unordered_contexts(&self) -> impl Iterator<Item = &SavedContextMetadata> {
|
||||
self.contexts_metadata.iter()
|
||||
}
|
||||
|
||||
pub fn reverse_chronological_contexts(&self) -> Vec<SavedContextMetadata> {
|
||||
let mut contexts = self.contexts_metadata.iter().cloned().collect::<Vec<_>>();
|
||||
contexts.sort_unstable_by_key(|thread| std::cmp::Reverse(thread.mtime));
|
||||
contexts
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue