| use derive_more::derive::Display; |
| use derive_setters::Setters; |
| use fake::Dummy; |
| use schemars::JsonSchema; |
| use serde::{Deserialize, Serialize}; |
| use strum_macros::EnumString; |
|
|
| |
| #[derive( |
| Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, EnumString, JsonSchema, Dummy, |
| )] |
| #[serde(rename_all = "lowercase")] |
| #[strum(serialize_all = "lowercase", ascii_case_insensitive)] |
| pub enum InputModality { |
| |
| Text, |
| |
| Image, |
| } |
|
|
| |
| fn default_input_modalities() -> Vec<InputModality> { |
| vec![InputModality::Text] |
| } |
|
|
| #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Setters, JsonSchema, Dummy)] |
| #[setters(strip_option)] |
| pub struct Model { |
| pub id: ModelId, |
| pub name: Option<String>, |
| pub description: Option<String>, |
| pub context_length: Option<u64>, |
| |
| pub tools_supported: Option<bool>, |
| |
| pub supports_parallel_tool_calls: Option<bool>, |
| |
| pub supports_reasoning: Option<bool>, |
| |
| #[serde(default = "default_input_modalities")] |
| pub input_modalities: Vec<InputModality>, |
| } |
|
|
| #[derive(Default, Debug, Clone, Serialize, Deserialize)] |
| pub struct Parameters { |
| pub tool_supported: bool, |
| } |
|
|
| impl Parameters { |
| pub fn new(tool_supported: bool) -> Self { |
| Self { tool_supported } |
| } |
| } |
|
|
| #[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Hash, Eq, Display, JsonSchema, Dummy)] |
| #[serde(transparent)] |
| pub struct ModelId(String); |
|
|
| impl ModelId { |
| pub fn new<T: Into<String>>(id: T) -> Self { |
| Self(id.into()) |
| } |
| } |
|
|
| impl Model { |
| |
| |
| pub fn new(id: impl Into<ModelId>) -> Self { |
| Self { |
| id: id.into(), |
| name: None, |
| description: None, |
| context_length: None, |
| tools_supported: None, |
| supports_parallel_tool_calls: None, |
| supports_reasoning: None, |
| input_modalities: default_input_modalities(), |
| } |
| } |
| } |
|
|
| impl From<String> for ModelId { |
| fn from(value: String) -> Self { |
| ModelId(value) |
| } |
| } |
|
|
| impl From<&str> for ModelId { |
| fn from(value: &str) -> Self { |
| ModelId(value.to_string()) |
| } |
| } |
|
|
| impl ModelId { |
| pub fn as_str(&self) -> &str { |
| &self.0 |
| } |
| } |
|
|
| impl std::str::FromStr for ModelId { |
| type Err = std::convert::Infallible; |
|
|
| fn from_str(s: &str) -> Result<Self, Self::Err> { |
| Ok(ModelId(s.to_string())) |
| } |
| } |
|
|