fix: add skip_canonical_filtering to declarative providers (#8052)
Signed-off-by: Douwe Osinga <douwe@squareup.com> Co-authored-by: Douwe Osinga <douwe@squareup.com>
This commit is contained in:
@@ -61,6 +61,8 @@ pub struct DeclarativeProviderConfig {
|
|||||||
pub env_vars: Option<Vec<EnvVarConfig>>,
|
pub env_vars: Option<Vec<EnvVarConfig>>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub dynamic_models: Option<bool>,
|
pub dynamic_models: Option<bool>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub skip_canonical_filtering: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_requires_auth() -> bool {
|
fn default_requires_auth() -> bool {
|
||||||
@@ -215,6 +217,7 @@ pub fn create_custom_provider(
|
|||||||
base_path: params.base_path,
|
base_path: params.base_path,
|
||||||
env_vars: None,
|
env_vars: None,
|
||||||
dynamic_models: None,
|
dynamic_models: None,
|
||||||
|
skip_canonical_filtering: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
let custom_providers_dir = custom_providers_dir();
|
let custom_providers_dir = custom_providers_dir();
|
||||||
@@ -280,6 +283,7 @@ pub fn update_custom_provider(params: UpdateCustomProviderParams) -> Result<()>
|
|||||||
base_path: params.base_path,
|
base_path: params.base_path,
|
||||||
env_vars: existing_config.env_vars,
|
env_vars: existing_config.env_vars,
|
||||||
dynamic_models: existing_config.dynamic_models,
|
dynamic_models: existing_config.dynamic_models,
|
||||||
|
skip_canonical_filtering: existing_config.skip_canonical_filtering,
|
||||||
};
|
};
|
||||||
|
|
||||||
let file_path = custom_providers_dir().join(format!("{}.json", updated_config.name));
|
let file_path = custom_providers_dir().join(format!("{}.json", updated_config.name));
|
||||||
|
|||||||
@@ -534,10 +534,18 @@ pub trait Provider: Send + Sync {
|
|||||||
Ok(vec![])
|
Ok(vec![])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn skip_canonical_filtering(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
/// Fetch models filtered by canonical registry and usability
|
/// Fetch models filtered by canonical registry and usability
|
||||||
async fn fetch_recommended_models(&self) -> Result<Vec<String>, ProviderError> {
|
async fn fetch_recommended_models(&self) -> Result<Vec<String>, ProviderError> {
|
||||||
let all_models = self.fetch_supported_models().await?;
|
let all_models = self.fetch_supported_models().await?;
|
||||||
|
|
||||||
|
if self.skip_canonical_filtering() {
|
||||||
|
return Ok(all_models);
|
||||||
|
}
|
||||||
|
|
||||||
let registry = CanonicalModelRegistry::bundled().map_err(|e| {
|
let registry = CanonicalModelRegistry::bundled().map_err(|e| {
|
||||||
ProviderError::ExecutionError(format!("Failed to load canonical registry: {}", e))
|
ProviderError::ExecutionError(format!("Failed to load canonical registry: {}", e))
|
||||||
})?;
|
})?;
|
||||||
|
|||||||
@@ -7,5 +7,6 @@
|
|||||||
"base_url": "http://localhost:1234/v1/chat/completions",
|
"base_url": "http://localhost:1234/v1/chat/completions",
|
||||||
"models": [],
|
"models": [],
|
||||||
"supports_streaming": true,
|
"supports_streaming": true,
|
||||||
"requires_auth": false
|
"requires_auth": false,
|
||||||
|
"skip_canonical_filtering": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ pub struct OpenAiProvider {
|
|||||||
custom_headers: Option<HashMap<String, String>>,
|
custom_headers: Option<HashMap<String, String>>,
|
||||||
supports_streaming: bool,
|
supports_streaming: bool,
|
||||||
name: String,
|
name: String,
|
||||||
|
skip_canonical_filtering: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OpenAiProvider {
|
impl OpenAiProvider {
|
||||||
@@ -126,6 +127,7 @@ impl OpenAiProvider {
|
|||||||
custom_headers,
|
custom_headers,
|
||||||
supports_streaming: true,
|
supports_streaming: true,
|
||||||
name: OPEN_AI_PROVIDER_NAME.to_string(),
|
name: OPEN_AI_PROVIDER_NAME.to_string(),
|
||||||
|
skip_canonical_filtering: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,6 +142,7 @@ impl OpenAiProvider {
|
|||||||
custom_headers: None,
|
custom_headers: None,
|
||||||
supports_streaming: true,
|
supports_streaming: true,
|
||||||
name: OPEN_AI_PROVIDER_NAME.to_string(),
|
name: OPEN_AI_PROVIDER_NAME.to_string(),
|
||||||
|
skip_canonical_filtering: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,6 +211,7 @@ impl OpenAiProvider {
|
|||||||
custom_headers: config.headers,
|
custom_headers: config.headers,
|
||||||
supports_streaming: config.supports_streaming.unwrap_or(true),
|
supports_streaming: config.supports_streaming.unwrap_or(true),
|
||||||
name: config.name.clone(),
|
name: config.name.clone(),
|
||||||
|
skip_canonical_filtering: config.skip_canonical_filtering,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -361,6 +365,10 @@ impl Provider for OpenAiProvider {
|
|||||||
&self.name
|
&self.name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn skip_canonical_filtering(&self) -> bool {
|
||||||
|
self.skip_canonical_filtering
|
||||||
|
}
|
||||||
|
|
||||||
fn get_model_config(&self) -> ModelConfig {
|
fn get_model_config(&self) -> ModelConfig {
|
||||||
self.model.clone()
|
self.model.clone()
|
||||||
}
|
}
|
||||||
@@ -617,6 +625,7 @@ mod tests {
|
|||||||
custom_headers: None,
|
custom_headers: None,
|
||||||
supports_streaming: true,
|
supports_streaming: true,
|
||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
|
skip_canonical_filtering: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4653,6 +4653,9 @@
|
|||||||
"requires_auth": {
|
"requires_auth": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
},
|
},
|
||||||
|
"skip_canonical_filtering": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
"supports_streaming": {
|
"supports_streaming": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"nullable": true
|
"nullable": true
|
||||||
|
|||||||
@@ -217,6 +217,7 @@ export type DeclarativeProviderConfig = {
|
|||||||
models: Array<ModelInfo>;
|
models: Array<ModelInfo>;
|
||||||
name: string;
|
name: string;
|
||||||
requires_auth?: boolean;
|
requires_auth?: boolean;
|
||||||
|
skip_canonical_filtering?: boolean;
|
||||||
supports_streaming?: boolean | null;
|
supports_streaming?: boolean | null;
|
||||||
timeout_seconds?: number | null;
|
timeout_seconds?: number | null;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user