macro_rules! string_id {
(
$(#[$meta:meta])*
$name:ident { $( $ctor:ident => $value:literal ),* $(,)? }
) => {
$(#[$meta])*
#[derive(
Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord,
serde::Serialize, serde::Deserialize,
)]
#[serde(transparent)]
pub struct $name(String);
impl $name {
$(
#[doc = concat!("The well-known `", $value, "` value.")]
pub fn $ctor() -> Self {
Self(String::from($value))
}
)*
pub fn as_str(&self) -> &str {
&self.0
}
}
impl AsRef<str> for $name {
fn as_ref(&self) -> &str {
&self.0
}
}
impl From<&str> for $name {
fn from(value: &str) -> Self {
Self(value.to_owned())
}
}
impl From<String> for $name {
fn from(value: String) -> Self {
Self(value)
}
}
impl From<$name> for String {
fn from(value: $name) -> Self {
value.0
}
}
impl std::fmt::Display for $name {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(&self.0)
}
}
};
}
string_id! {
Modality {
unknown => "unknown",
text => "text",
image => "image",
speech => "speech",
audio => "audio",
video => "video",
vision => "vision",
embedding => "embedding",
}
}
string_id! {
Capability {
chat => "chat",
complete => "complete",
embed => "embed",
see => "see",
image => "image",
speak => "speak",
transcribe => "transcribe",
tools => "tools",
}
}
string_id! {
SourceKind {
ollama => "ollama",
huggingface_cache => "huggingface-cache",
lm_studio => "lm-studio",
builtin => "builtin",
endpoint => "endpoint",
file => "file",
folder => "folder",
}
}
string_id! {
RuntimeId {
llama_cpp => "llama-cpp",
whisper_cpp => "whisper-cpp",
ollama => "ollama",
mlx_swift => "mlx-swift",
apple_foundation => "apple-foundation",
openai_endpoint => "generic:openai-server",
mflux => "python:mflux",
diffusers => "python:diffusers",
mlx_lm => "python:mlx-lm",
mlx_audio => "python:mlx-audio",
mlx_vlm => "python:mlx-vlm",
embeddings => "python:embeddings",
comfy_ui => "comfyui",
a1111 => "a1111",
}
}
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize,
)]
#[serde(rename_all = "lowercase")]
pub enum ExecutionMode {
Stream,
Job,
#[default]
Sync,
}
impl ExecutionMode {
pub fn as_str(&self) -> &'static str {
match self {
ExecutionMode::Stream => "stream",
ExecutionMode::Job => "job",
ExecutionMode::Sync => "sync",
}
}
}
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize,
)]
#[serde(rename_all = "kebab-case")]
pub enum RunTier {
Native,
Managed,
Remote,
#[default]
RecipeNeeded,
}
#[derive(
Debug, Clone, Copy, PartialEq, Eq, Hash, Default, serde::Serialize, serde::Deserialize,
)]
#[serde(rename_all = "lowercase")]
pub enum ModelState {
Ready,
#[default]
Unresolved,
Missing,
}
impl ModelState {
pub fn as_str(&self) -> &'static str {
match self {
ModelState::Ready => "ready",
ModelState::Unresolved => "unresolved",
ModelState::Missing => "missing",
}
}
}
pub struct BidPreference;
impl BidPreference {
pub const LLAMA_CPP: i64 = 10;
pub const WHISPER_CPP: i64 = 10;
pub const ENDPOINT: i64 = 10;
pub const MLX_VLM: i64 = 14;
pub const MLX_SWIFT: i64 = 15;
pub const APPLE_FOUNDATION: i64 = 15;
pub const OLLAMA: i64 = 20;
pub const MFLUX: i64 = 25;
pub const DIFFUSERS: i64 = 26;
pub const COMFY_UI: i64 = 27;
pub const A1111: i64 = 28;
pub const MLX_AUDIO: i64 = 30;
pub const EMBEDDINGS: i64 = 32;
pub const MLX_LM: i64 = 40;
pub const MANIFEST: i64 = 100;
}