feat: add configurable fast_model for declarative providers (#8194)

Signed-off-by: rdondeti <ravitez.dondeti@gmail.com>
Signed-off-by: Douwe Osinga <douwe@squareup.com>
Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
Ravitez Dondeti
2026-04-02 08:54:11 -05:00
committed by GitHub
parent 01a3d14a50
commit 8d4835f070
6 changed files with 37 additions and 1 deletions
@@ -7,7 +7,16 @@ use crate::providers::openai::OpenAiProvider;
use anyhow::Result;
use include_dir::{include_dir, Dir};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use serde::{Deserialize, Deserializer, Serialize};
/// Deserialize an optional string, treating empty/whitespace-only values as None.
fn deserialize_non_empty_string<'de, D>(deserializer: D) -> Result<Option<String>, D::Error>
where
D: Deserializer<'de>,
{
let opt: Option<String> = Option::deserialize(deserializer)?;
Ok(opt.filter(|s| !s.trim().is_empty()))
}
use std::collections::HashMap;
use std::path::Path;
use std::sync::Mutex;
@@ -66,6 +75,8 @@ pub struct DeclarativeProviderConfig {
pub dynamic_models: Option<bool>,
#[serde(default)]
pub skip_canonical_filtering: bool,
#[serde(default, deserialize_with = "deserialize_non_empty_string")]
pub fast_model: Option<String>,
}
fn default_requires_auth() -> bool {
@@ -221,6 +232,7 @@ pub fn create_custom_provider(
env_vars: None,
dynamic_models: None,
skip_canonical_filtering: false,
fast_model: None,
};
let custom_providers_dir = custom_providers_dir();
@@ -287,6 +299,7 @@ pub fn update_custom_provider(params: UpdateCustomProviderParams) -> Result<()>
env_vars: existing_config.env_vars,
dynamic_models: existing_config.dynamic_models,
skip_canonical_filtering: existing_config.skip_canonical_filtering,
fast_model: existing_config.fast_model.clone(),
};
let file_path = custom_providers_dir().join(format!("{}.json", updated_config.name));
+6
View File
@@ -127,6 +127,12 @@ impl AnthropicProvider {
None
};
let model = if let Some(ref fast_model_name) = config.fast_model {
model.with_fast(fast_model_name, &config.name)?
} else {
model
};
Ok(Self {
api_client,
model,
+6
View File
@@ -182,6 +182,12 @@ impl OllamaProvider {
));
}
let model = if let Some(ref fast_model_name) = config.fast_model {
model.with_fast(fast_model_name, &config.name)?
} else {
model
};
Ok(Self {
api_client,
model,
+6
View File
@@ -221,6 +221,12 @@ impl OpenAiProvider {
None
};
let model = if let Some(ref fast_model_name) = config.fast_model {
model.with_fast(fast_model_name, &config.name)?
} else {
model
};
Ok(Self {
api_client,
base_path,
+4
View File
@@ -4618,6 +4618,10 @@
},
"nullable": true
},
"fast_model": {
"type": "string",
"nullable": true
},
"headers": {
"type": "object",
"additionalProperties": {
+1
View File
@@ -216,6 +216,7 @@ export type DeclarativeProviderConfig = {
dynamic_models?: boolean | null;
engine: ProviderEngine;
env_vars?: Array<EnvVarConfig> | null;
fast_model?: string | null;
headers?: {
[key: string]: string;
} | null;