use derive_more::derive::Display; use derive_setters::Setters; use fake::Dummy; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; use strum_macros::EnumString; /// Represents input modalities that a model can accept #[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 input (all models support this) Text, /// Image input (vision-capable models) Image, } /// Default input modalities when not specified (text-only) fn default_input_modalities() -> Vec { vec![InputModality::Text] } #[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Setters, JsonSchema, Dummy)] #[setters(strip_option)] pub struct Model { pub id: ModelId, pub name: Option, pub description: Option, pub context_length: Option, // TODO: add provider information to the model pub tools_supported: Option, /// Whether the model supports parallel tool calls pub supports_parallel_tool_calls: Option, /// Whether the model supports reasoning pub supports_reasoning: Option, /// Input modalities supported by the model (defaults to text-only) #[serde(default = "default_input_modalities")] pub input_modalities: Vec, } #[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>(id: T) -> Self { Self(id.into()) } } impl Model { /// Creates a new `Model` with the given id and default values for all other /// fields. pub fn new(id: impl Into) -> 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 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 { Ok(ModelId(s.to_string())) } }