#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
use std::path::PathBuf;
use foundation_errstacks::ErrorTrace;
use crate::agentic::AgenticError;
use crate::backends::anthropic_messages_provider::AnthropicMessagesProvider;
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
use crate::backends::huggingface_gguf_provider::{HuggingFaceGGUFConfig, HuggingFaceGGUFProvider};
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
use crate::backends::llamacpp::SpeculativeConfig;
use crate::backends::openai_provider::OpenAIProvider;
use crate::backends::openai_responses_provider::ResponsesProvider;
pub const Q3_K_M: &str = "Q3_K_M";
pub const Q4_K_M: &str = "Q4_K_M";
pub const Q5_K_M: &str = "Q5_K_M";
pub const Q8_0: &str = "Q8_0";
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
pub fn gguf_provider(
config: Option<HuggingFaceGGUFConfig>,
) -> Result<HuggingFaceGGUFProvider, ErrorTrace<AgenticError>> {
let config = config.unwrap_or_default();
let cache_dir = config.cache_dir.clone();
HuggingFaceGGUFProvider::new(config).map_err(|e| {
ErrorTrace::new(AgenticError::Provider(format!(
"failed to create GGUF provider (cache dir {}): {e}",
cache_dir.display()
)))
})
}
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
fn create_provider(
quantization: &str,
config: Option<HuggingFaceGGUFConfig>,
) -> Result<HuggingFaceGGUFProvider, ErrorTrace<AgenticError>> {
let mut config = config.unwrap_or_default();
config.default_quantization = Some(quantization.to_string());
gguf_provider(Some(config))
}
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
#[must_use]
pub fn with_mtp(
base: Option<HuggingFaceGGUFConfig>,
n_max: u32,
mtp_model: Option<PathBuf>,
) -> HuggingFaceGGUFConfig {
let mut config = base.unwrap_or_default();
config.llama_config.speculative = Some(SpeculativeConfig::mtp(mtp_model, n_max));
config
}
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
macro_rules! gguf_model {
($ty:ident, $model_id:literal, mtp = $mtp:literal, $mtp_doc:literal) => {
impl $ty {
pub const MODEL_ID: &str = $model_id;
#[doc = $mtp_doc]
pub const SUPPORTS_MTP: bool = $mtp;
pub fn q3_k_m(
config: Option<HuggingFaceGGUFConfig>,
) -> Result<HuggingFaceGGUFProvider, ErrorTrace<AgenticError>> {
create_provider(Q3_K_M, config)
}
pub fn q4_k_m(
config: Option<HuggingFaceGGUFConfig>,
) -> Result<HuggingFaceGGUFProvider, ErrorTrace<AgenticError>> {
create_provider(Q4_K_M, config)
}
pub fn q5_k_m(
config: Option<HuggingFaceGGUFConfig>,
) -> Result<HuggingFaceGGUFProvider, ErrorTrace<AgenticError>> {
create_provider(Q5_K_M, config)
}
pub fn q8_0(
config: Option<HuggingFaceGGUFConfig>,
) -> Result<HuggingFaceGGUFProvider, ErrorTrace<AgenticError>> {
create_provider(Q8_0, config)
}
}
};
}
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
pub struct Glm52;
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
gguf_model!(
Glm52,
"unsloth/GLM-5.2-GGUF",
mtp = true,
"GLM 5.2 ships an MTP head — MTP speculative decoding is supported."
);
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
pub struct Qwen36;
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
gguf_model!(
Qwen36,
"unsloth/Qwen3.6-35B-A3B-GGUF",
mtp = true,
"Qwen 3.6 ships an MTP head — MTP speculative decoding is supported."
);
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
pub struct Ornith10;
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
gguf_model!(
Ornith10,
"LordNeel/Ornith-1.0-35B-GGUF-llamacpp-tp1",
mtp = false,
"Ornith 1.0 does not ship an MTP head."
);
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
pub struct Gemma4E4b;
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
gguf_model!(
Gemma4E4b,
"unsloth/gemma-4-E4B-it-GGUF",
mtp = true,
"Gemma 4 ships an MTP head — MTP speculative decoding is supported."
);
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
pub struct Gemma4_26b;
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
gguf_model!(
Gemma4_26b,
"unsloth/gemma-4-26B-A4B-it-GGUF",
mtp = true,
"Gemma 4 ships an MTP head — MTP speculative decoding is supported."
);
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
pub struct Gemma4E2b;
#[cfg(all(feature = "llamacpp", not(target_family = "wasm")))]
gguf_model!(
Gemma4E2b,
"unsloth/gemma-4-E2B-it-GGUF",
mtp = true,
"Gemma 4 ships an MTP head — MTP speculative decoding is supported."
);
pub const CLAUDE_OPUS: &str = "claude-opus-4-8";
pub const CLAUDE_SONNET: &str = "claude-sonnet-4-6";
pub const OPENAI_GPT4O: &str = "gpt-4o";
pub const OPENAI_GPT4O_MINI: &str = "gpt-4o-mini";
pub struct CloudPresets;
impl CloudPresets {
pub fn claude_opus(
api_key: &str,
) -> Result<AnthropicMessagesProvider, ErrorTrace<AgenticError>> {
Ok(AnthropicMessagesProvider::api_key(api_key))
}
pub fn claude_sonnet(
api_key: &str,
) -> Result<AnthropicMessagesProvider, ErrorTrace<AgenticError>> {
Ok(AnthropicMessagesProvider::api_key(api_key))
}
pub fn openai_gpt4(api_key: &str) -> Result<OpenAIProvider, ErrorTrace<AgenticError>> {
Ok(OpenAIProvider::api_key(api_key))
}
pub fn openai_gpt4o(api_key: &str) -> Result<OpenAIProvider, ErrorTrace<AgenticError>> {
Ok(OpenAIProvider::api_key(api_key))
}
pub fn openai_responses(api_key: &str) -> Result<ResponsesProvider, ErrorTrace<AgenticError>> {
Ok(ResponsesProvider::api_key(api_key))
}
}