summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-06-27 08:21:49 +0800
committerGitHub <noreply@github.com>2024-06-27 08:21:49 +0800
commit33a0049a81103c1f6c5639b9cec43cb14a9ef367 (patch)
tree7402b251e2d75aaf5306487b70265f35c8d52b22 /src/config
parent1ced451c2723c36b7e0cb70e6c0755cdbad457c3 (diff)
downloadaichat-33a0049a81103c1f6c5639b9cec43cb14a9ef367.tar.gz
refactor: saved messages ignore embedding context (#659)
Diffstat (limited to 'src/config')
-rw-r--r--src/config/input.rs13
-rw-r--r--src/config/mod.rs8
-rw-r--r--src/config/session.rs4
3 files changed, 15 insertions, 10 deletions
diff --git a/src/config/input.rs b/src/config/input.rs
index 09dfa8f..a41b1c7 100644
--- a/src/config/input.rs
+++ b/src/config/input.rs
@@ -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 {
diff --git a/src/config/mod.rs b/src/config/mod.rs
index f82f36a..69609f4 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -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(());
}
diff --git a/src/config/session.rs b/src/config/session.rs
index 3057697..9aa4ca4 100644
--- a/src/config/session.rs
+++ b/src/config/session.rs
@@ -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)