summaryrefslogtreecommitdiffstats
path: root/src/client/model.rs
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2023-11-07 11:54:56 +0800
committerGitHub <noreply@github.com>2023-11-07 11:54:56 +0800
commitd40f104f667073f320a01d9c1a91aa88225ccaeb (patch)
treedf915b72efb7051a53a95439c2d8cc4627921c8e /src/client/model.rs
parent9a8b302432a3f9bfa1e467dde027fc92dacce3e2 (diff)
downloadaichat-d40f104f667073f320a01d9c1a91aa88225ccaeb.tar.gz
feat: allow the use of an unlisted model (#219)
Diffstat (limited to 'src/client/model.rs')
-rw-r--r--src/client/model.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/client/model.rs b/src/client/model.rs
index 82d47c9..16fe087 100644
--- a/src/client/model.rs
+++ b/src/client/model.rs
@@ -30,6 +30,37 @@ impl Model {
}
}
+ pub fn find(models: &[Self], value: &str) -> Option<Self> {
+ let mut model = None;
+ let (client_name, model_name) = match value.split_once(':') {
+ Some((client_name, model_name)) => {
+ if model_name.is_empty() {
+ (client_name, None)
+ } else {
+ (client_name, Some(model_name))
+ }
+ }
+ None => (value, None),
+ };
+ match model_name {
+ Some(model_name) => {
+ if let Some(found) = models.iter().find(|v| v.id() == value) {
+ model = Some(found.clone());
+ } else if let Some(found) = models.iter().find(|v| v.client_name == client_name) {
+ let mut found = found.clone();
+ found.name = model_name.to_string();
+ model = Some(found)
+ }
+ }
+ None => {
+ if let Some(found) = models.iter().find(|v| v.client_name == client_name) {
+ model = Some(found.clone());
+ }
+ }
+ }
+ model
+ }
+
pub fn id(&self) -> String {
format!("{}:{}", self.client_name, self.name)
}