Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/models/image_embedding.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Display;
use std::{fmt::Display, str::FromStr};

use super::model_info::ModelInfo;

Expand Down Expand Up @@ -79,3 +79,23 @@ impl Display for ImageEmbeddingModel {
write!(f, "{}", model_info.model_code)
}
}

impl FromStr for ImageEmbeddingModel {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
models_list()
.into_iter()
.find(|m| m.model_code.eq_ignore_ascii_case(s))
.map(|m| m.model)
.ok_or_else(|| format!("Unknown embedding model: {s}"))
}
}

impl TryFrom<String> for ImageEmbeddingModel {
type Error = String;

fn try_from(value: String) -> Result<Self, Self::Error> {
value.parse()
}
}
22 changes: 21 additions & 1 deletion src/models/reranking.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Display;
use std::{fmt::Display, str::FromStr};

use crate::RerankerModelInfo;

Expand Down Expand Up @@ -57,3 +57,23 @@ impl Display for RerankerModel {
write!(f, "{}", model_info.model_code)
}
}

impl FromStr for RerankerModel {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
reranker_model_list()
.into_iter()
.find(|m| m.model_code.eq_ignore_ascii_case(s))
.map(|m| m.model)
.ok_or_else(|| format!("Unknown reranker model: {s}"))
}
}

impl TryFrom<String> for RerankerModel {
type Error = String;

fn try_from(value: String) -> Result<Self, Self::Error> {
value.parse()
}
}
22 changes: 21 additions & 1 deletion src/models/sparse.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::fmt::Display;
use std::{fmt::Display, str::FromStr};

use crate::ModelInfo;

Expand Down Expand Up @@ -28,3 +28,23 @@ impl Display for SparseModel {
write!(f, "{}", model_info.model_code)
}
}

impl FromStr for SparseModel {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
models_list()
.into_iter()
.find(|m| m.model_code.eq_ignore_ascii_case(s))
.map(|m| m.model)
.ok_or_else(|| format!("Unknown sparse model: {s}"))
}
}

impl TryFrom<String> for SparseModel {
type Error = String;

fn try_from(value: String) -> Result<Self, Self::Error> {
value.parse()
}
}
22 changes: 21 additions & 1 deletion src/models/text_embedding.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::HashMap, fmt::Display, sync::OnceLock};
use std::{collections::HashMap, convert::TryFrom, fmt::Display, str::FromStr, sync::OnceLock};

use super::model_info::ModelInfo;

Expand Down Expand Up @@ -360,3 +360,23 @@ impl Display for EmbeddingModel {
write!(f, "{}", model_info.model_code)
}
}

impl FromStr for EmbeddingModel {
type Err = String;

fn from_str(s: &str) -> Result<Self, Self::Err> {
models_list()
.into_iter()
.find(|m| m.model_code.eq_ignore_ascii_case(s))
.map(|m| m.model)
.ok_or_else(|| format!("Unknown embedding model: {s}"))
}
}

impl TryFrom<String> for EmbeddingModel {
type Error = String;

fn try_from(value: String) -> Result<Self, Self::Error> {
value.parse()
}
}