summaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-11-27 15:39:55 +0800
committerGitHub <noreply@github.com>2023-11-27 15:39:55 +0800
commit2508d56598a37844e369ab623ceb5bc7b2c78d38 (patch)
tree744986163dcfe09aade1ef61ef63ad21279666cc /src/config
parent25e545474fcbd69dfb2a283981178491717cc6b5 (diff)
downloadaichat-2508d56598a37844e369ab623ceb5bc7b2c78d38.tar.gz
feat: state-aware completer (#251)
Diffstat (limited to 'src/config')
-rw-r--r--src/config/mod.rs27
-rw-r--r--src/config/session.rs2
2 files changed, 29 insertions, 0 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 08509be..1b3d802 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -283,6 +283,24 @@ impl Config {
Ok(())
}
+ pub fn get_state(&self) -> State {
+ if let Some(session) = &self.session {
+ if session.is_empty() {
+ if session.role.is_some() {
+ State::EmptySessionWithRole
+ } else {
+ State::EmptySession
+ }
+ } else {
+ State::Session
+ }
+ } else if self.role.is_some() {
+ State::Role
+ } else {
+ State::Normal
+ }
+ }
+
pub fn get_temperature(&self) -> Option<f64> {
self.temperature
}
@@ -806,6 +824,15 @@ impl Keybindings {
}
}
+#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
+pub enum State {
+ Normal,
+ Role,
+ EmptySession,
+ EmptySessionWithRole,
+ Session,
+}
+
fn create_config_file(config_path: &Path) -> Result<()> {
let ans = Confirm::new("No config file, create a new one?")
.with_default(true)
diff --git a/src/config/session.rs b/src/config/session.rs
index 644255f..e135c58 100644
--- a/src/config/session.rs
+++ b/src/config/session.rs
@@ -20,6 +20,7 @@ pub struct Session {
model_id: String,
temperature: Option<f64>,
messages: Vec<Message>,
+ #[serde(default)]
data_urls: HashMap<String, String>,
#[serde(skip)]
pub name: String,
@@ -248,6 +249,7 @@ impl Session {
role: MessageRole::Assistant,
content: MessageContent::Text(output.to_string()),
});
+ self.role = None;
self.dirty = true;
Ok(())
}