macro_rules! dispatch_stream_fn {
(
match $value:expr ;
$enum:ident ( $bind:ident ) => $model:expr ,
tools = $tools:expr ,
timeout = $timeout:expr ,
provider = $provider:expr ,
model_name = $model_name:expr ,
filter = $filter:expr $(,)?
) => {{
use $crate::agent::agent_loop::rig_stream_fn_from_model_with_filter as __stream_fn;
match $value {
$enum::OpenRouter($bind) => {
__stream_fn($model, $tools, $timeout, $provider, $model_name, $filter)
}
$enum::OpenAI($bind) => __stream_fn(
$model,
$tools,
$timeout,
Some("openai".to_string()),
$model_name,
$filter,
),
$enum::ChatGptOpenAI($bind) => __stream_fn(
$model,
$tools,
$timeout,
Some("openai".to_string()),
$model_name,
$filter,
),
$enum::OpenAICodex($bind) => __stream_fn(
$model,
$tools,
$timeout,
Some("openai".to_string()),
$model_name,
$filter,
),
$enum::Anthropic($bind) => {
__stream_fn(
$crate::provider::stream_dispatch::automatic_caching!($model),
$tools,
$timeout,
$provider,
$model_name,
$filter,
)
}
$enum::AnthropicOauth($bind) => {
__stream_fn(
$crate::provider::stream_dispatch::automatic_caching!($model),
$tools,
$timeout,
$provider,
$model_name,
$filter,
)
}
$enum::Gemini($bind) => {
__stream_fn($model, $tools, $timeout, $provider, $model_name, $filter)
}
$enum::DeepSeek($bind) => {
__stream_fn($model, $tools, $timeout, $provider, $model_name, $filter)
}
$enum::Glm($bind) => {
__stream_fn($model, $tools, $timeout, $provider, $model_name, $filter)
}
$enum::Cerebras($bind) => __stream_fn(
$model,
$tools,
$timeout,
Some("cerebras".to_string()),
$model_name,
$filter,
),
$enum::OpenCode($bind) => {
__stream_fn($model, $tools, $timeout, $provider, $model_name, $filter)
}
$enum::Kimi($bind) => {
__stream_fn($model, $tools, $timeout, $provider, $model_name, $filter)
}
$enum::Ollama($bind) => {
__stream_fn($model, $tools, $timeout, $provider, $model_name, $filter)
}
$enum::Custom($bind) => {
__stream_fn($model, $tools, $timeout, $provider, $model_name, $filter)
}
}
}};
}
pub(crate) use dispatch_stream_fn;
macro_rules! automatic_caching {
($model:expr) => {
match $crate::prompt_cache::ttl() {
$crate::prompt_cache::CacheTtl::OneHour => $model.with_automatic_caching_1h(),
$crate::prompt_cache::CacheTtl::FiveMinutes => $model.with_automatic_caching(),
}
};
}
pub(crate) use automatic_caching;