diff options
| author | sigoden <sigoden@gmail.com> | 2024-09-13 18:23:44 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-09-13 18:23:44 +0800 |
| commit | 632d7cdfa32534f55a48aa31fb2512a221040e60 (patch) | |
| tree | 176f2560ddca292aa95e1c7845e583827d9f5bf2 /src/config | |
| parent | c821652ed98819f09e0ae29269fd5410e256813e (diff) | |
| download | aichat-632d7cdfa32534f55a48aa31fb2512a221040e60.tar.gz | |
refactor: improve repl completeion (#865)
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/mod.rs | 72 |
1 files changed, 34 insertions, 38 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index d58f4f1..3fdba3c 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1441,27 +1441,16 @@ impl Config { let mut filter = ""; if args.len() == 1 { values = match cmd { - ".role" => Self::list_roles(true) - .into_iter() - .map(|v| (v, None)) - .collect(), + ".role" => map_completion_values(Self::list_roles(true)), ".model" => list_chat_models(self) .into_iter() .map(|v| (v.id(), Some(v.description()))) .collect(), - ".session" => self - .list_sessions() - .into_iter() - .map(|v| (v, None)) - .collect(), - ".rag" => Self::list_rags().into_iter().map(|v| (v, None)).collect(), - ".agent" => list_agents().into_iter().map(|v| (v, None)).collect(), + ".session" => map_completion_values(self.list_sessions()), + ".rag" => map_completion_values(Self::list_rags()), + ".agent" => map_completion_values(list_agents()), ".starter" => match &self.agent { - Some(agent) => agent - .conversation_staters() - .iter() - .map(|v| (v.clone(), None)) - .collect(), + Some(agent) => map_completion_values(agent.conversation_staters().to_vec()), None => vec![], }, ".variable" => match &self.agent { @@ -1472,28 +1461,31 @@ impl Config { .collect(), None => vec![], }, - ".set" => vec![ - "max_output_tokens", - "temperature", - "top_p", - "dry_run", - "stream", - "save", - "save_session", - "compress_threshold", - "function_calling", - "use_tools", - "rag_reranker_model", - "rag_top_k", - "highlight", - ] - .into_iter() - .map(|v| (format!("{v} "), None)) - .collect(), - ".delete" => vec!["roles", "sessions", "rags", "agents-config"] - .into_iter() - .map(|v| (v.to_string(), None)) - .collect(), + ".set" => { + let mut values = vec![ + "max_output_tokens", + "temperature", + "top_p", + "dry_run", + "stream", + "save", + "save_session", + "compress_threshold", + "function_calling", + "use_tools", + "rag_reranker_model", + "rag_top_k", + "highlight", + ]; + values.sort_unstable(); + values + .into_iter() + .map(|v| (format!("{v} "), None)) + .collect() + } + ".delete" => { + map_completion_values(vec!["roles", "sessions", "rags", "agents-config"]) + } _ => vec![], }; filter = args[0] @@ -2129,6 +2121,10 @@ fn complete_option_bool(value: Option<bool>) -> Vec<String> { } } +fn map_completion_values<T: ToString>(value: Vec<T>) -> Vec<(String, Option<String>)> { + value.into_iter().map(|v| (v.to_string(), None)).collect() +} + fn update_rag<F>(config: &GlobalConfig, f: F) -> Result<()> where F: FnOnce(&mut Rag) -> Result<()>, |
