use serde::{Deserialize, Serialize};
macro_rules! builtin_llm_codecs {
($( $(#[$meta:meta])* $variant:ident => $id:literal, )+) => {
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum BuiltinLlmCodec {
$(
$(#[$meta])*
#[serde(rename = $id)]
$variant,
)+
}
impl BuiltinLlmCodec {
pub const ALL: &'static [Self] = &[$(Self::$variant),+];
#[must_use]
pub const fn id(self) -> &'static str {
match self {
$(Self::$variant => $id),+
}
}
#[must_use]
pub fn from_id(id: &str) -> Option<Self> {
match id {
$($id => Some(Self::$variant),)+
_ => None,
}
}
}
};
}
builtin_llm_codecs! {
OpenAiChat => "openai_chat",
OpenAiResponses => "openai_responses",
AnthropicMessages => "anthropic_messages",
OCIGenAI => "oci_genai",
GeminiGenerateContent => "gemini_generate_content",
}
#[derive(Debug, Clone, PartialEq, Eq, Default, Serialize, Deserialize)]
#[serde(tag = "kind", content = "id", rename_all = "snake_case")]
pub enum LlmCodecIdentity {
#[default]
None,
#[serde(rename = "builtin")]
BuiltIn(BuiltinLlmCodec),
Runtime(String),
Opaque,
}