summaryrefslogtreecommitdiffstats
path: root/src/client/model.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2024-06-11 11:00:12 +0800
committerGitHub <noreply@github.com>2024-06-11 11:00:12 +0800
commitbb867c4fcbc6f42770471f0a0117cd8909f660d7 (patch)
tree6293f7f1108309160d1951f53f6429e9b004870d /src/client/model.rs
parent5635ca6a58fb4a590419335b098b7317285bfb82 (diff)
downloadaichat-bb867c4fcbc6f42770471f0a0117cd8909f660d7.tar.gz
feat: support bot (#579)
* feat: support bots * refactor with RoleLike * improve exiting session * make bot works with rag * refactor repl assert state * add bot banner * repl complete bots according bots.txt * fix on windows * remove threadpool executing function callings * adjust repl left_prompt * move bot config to global config.yaml * `.bot` throw err if funciton callings is not configured
Diffstat (limited to 'src/client/model.rs')
-rw-r--r--src/client/model.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/client/model.rs b/src/client/model.rs
index 22ad4d9..d555232 100644
--- a/src/client/model.rs
+++ b/src/client/model.rs
@@ -1,8 +1,10 @@
use super::{
+ list_chat_models,
message::{Message, MessageContent},
EmbeddingsData,
};
+use crate::config::Config;
use crate::utils::{estimate_token_length, format_option_value};
use anyhow::{bail, Result};
@@ -41,9 +43,16 @@ impl Model {
.collect()
}
- pub fn find(models: &[&Self], value: &str) -> Option<Self> {
+ pub fn retrieve(config: &Config, model_id: &str) -> Result<Self> {
+ match Self::find(&list_chat_models(config), model_id) {
+ Some(v) => Ok(v),
+ None => bail!("Invalid model '{model_id}'"),
+ }
+ }
+
+ pub fn find(models: &[&Self], model_id: &str) -> Option<Self> {
let mut model = None;
- let (client_name, model_name) = match value.split_once(':') {
+ let (client_name, model_name) = match model_id.split_once(':') {
Some((client_name, model_name)) => {
if model_name.is_empty() {
(client_name, None)
@@ -51,11 +60,11 @@ impl Model {
(client_name, Some(model_name))
}
}
- None => (value, None),
+ None => (model_id, None),
};
match model_name {
Some(model_name) => {
- if let Some(found) = models.iter().find(|v| v.id() == value) {
+ if let Some(found) = models.iter().find(|v| v.id() == model_id) {
model = Some((*found).clone());
} else if let Some(found) = models.iter().find(|v| v.client_name == client_name) {
let mut found = (*found).clone();
@@ -73,7 +82,11 @@ impl Model {
}
pub fn id(&self) -> String {
- format!("{}:{}", self.client_name, self.data.name)
+ if self.data.name.is_empty() {
+ self.client_name.to_string()
+ } else {
+ format!("{}:{}", self.client_name, self.data.name)
+ }
}
pub fn client_name(&self) -> &str {