refactor: saved messages ignore embedding context (#659)

pull/660/head
sigoden 3 months ago committed by GitHub
parent 1ced451c27
commit 33a0049a81
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -134,6 +134,10 @@ impl Input {
}
}
pub fn clear_patch(&mut self) {
self.patched_text = None;
}
pub fn set_text(&mut self, text: String) {
self.text = text;
}
@ -318,13 +322,14 @@ impl Input {
}
pub fn render(&self) -> String {
let text = self.text();
if self.medias.is_empty() {
return self.text();
return text;
}
let text = if self.text.is_empty() {
let tail_text = if text.is_empty() {
String::new()
} else {
format!(" -- {}", self.text())
format!(" -- {text}")
};
let files: Vec<String> = self
.medias
@ -332,7 +337,7 @@ impl Input {
.cloned()
.map(|url| resolve_data_url(&self.data_urls, url))
.collect();
format!(".file {}{}", files.join(" "), text)
format!(".file {}{}", files.join(" "), tail_text)
}
pub fn message_content(&self) -> MessageContent {

@ -1267,7 +1267,7 @@ impl Config {
pub fn after_chat_completion(
&mut self,
input: &mut Input,
input: &Input,
output: &str,
tool_results: &[ToolResult],
) -> Result<()> {
@ -1280,9 +1280,11 @@ impl Config {
Ok(())
}
fn save_message(&mut self, input: &mut Input, output: &str) -> Result<()> {
fn save_message(&mut self, input: &Input, output: &str) -> Result<()> {
let mut input = input.clone();
input.clear_patch();
if let Some(session) = input.session_mut(&mut self.session) {
session.add_message(input, output)?;
session.add_message(&input, output)?;
return Ok(());
}

@ -298,9 +298,7 @@ impl Session {
if self.is_temp() {
self.name = Text::new("Session name:")
.with_validator(|input: &str| {
if input == TEMP_SESSION_NAME {
Ok(Validation::Invalid(format!("'{TEMP_SESSION_NAME}' is a reserved word and cannot be used as a session name").into()))
} else if input.trim().is_empty() {
if input.trim().is_empty() {
Ok(Validation::Invalid("This field is required".into()))
} else {
Ok(Validation::Valid)

@ -162,7 +162,7 @@ async fn main() -> Result<()> {
#[async_recursion]
async fn start_directive(
config: &GlobalConfig,
mut input: Input,
input: Input,
no_stream: bool,
code_mode: bool,
abort_signal: AbortSignal,
@ -196,7 +196,7 @@ async fn start_directive(
};
config
.write()
.after_chat_completion(&mut input, &output, &tool_results)?;
.after_chat_completion(&input, &output, &tool_results)?;
config.write().exit_session()?;
@ -237,7 +237,7 @@ async fn shell_execute(config: &GlobalConfig, shell: &Shell, mut input: Input) -
}
config
.write()
.after_chat_completion(&mut input, &eval_str, &[])?;
.after_chat_completion(&input, &eval_str, &[])?;
let render_options = config.read().render_options()?;
let mut markdown_render = MarkdownRender::init(render_options)?;
if config.read().dry_run {

@ -550,7 +550,7 @@ async fn ask(
chat_completion_streaming(&input, client.as_ref(), config, abort_signal.clone()).await?;
config
.write()
.after_chat_completion(&mut input, &output, &tool_results)?;
.after_chat_completion(&input, &output, &tool_results)?;
if need_send_tool_results(&tool_results) {
ask(
config,

Loading…
Cancel
Save