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:
@@ -7,7 +7,16 @@ use crate::providers::openai::OpenAiProvider;
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use include_dir::{include_dir, Dir};
|
use include_dir::{include_dir, Dir};
|
||||||
use once_cell::sync::Lazy;
|
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::collections::HashMap;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
@@ -66,6 +75,8 @@ pub struct DeclarativeProviderConfig {
|
|||||||
pub dynamic_models: Option<bool>,
|
pub dynamic_models: Option<bool>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub skip_canonical_filtering: bool,
|
pub skip_canonical_filtering: bool,
|
||||||
|
#[serde(default, deserialize_with = "deserialize_non_empty_string")]
|
||||||
|
pub fast_model: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn default_requires_auth() -> bool {
|
fn default_requires_auth() -> bool {
|
||||||
@@ -221,6 +232,7 @@ pub fn create_custom_provider(
|
|||||||
env_vars: None,
|
env_vars: None,
|
||||||
dynamic_models: None,
|
dynamic_models: None,
|
||||||
skip_canonical_filtering: false,
|
skip_canonical_filtering: false,
|
||||||
|
fast_model: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let custom_providers_dir = custom_providers_dir();
|
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,
|
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,
|
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));
|
let file_path = custom_providers_dir().join(format!("{}.json", updated_config.name));
|
||||||
|
|||||||
@@ -127,6 +127,12 @@ impl AnthropicProvider {
|
|||||||
None
|
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 {
|
Ok(Self {
|
||||||
api_client,
|
api_client,
|
||||||
model,
|
model,
|
||||||
|
|||||||
@@ -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 {
|
Ok(Self {
|
||||||
api_client,
|
api_client,
|
||||||
model,
|
model,
|
||||||
|
|||||||
@@ -221,6 +221,12 @@ impl OpenAiProvider {
|
|||||||
None
|
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 {
|
Ok(Self {
|
||||||
api_client,
|
api_client,
|
||||||
base_path,
|
base_path,
|
||||||
|
|||||||
@@ -4618,6 +4618,10 @@
|
|||||||
},
|
},
|
||||||
"nullable": true
|
"nullable": true
|
||||||
},
|
},
|
||||||
|
"fast_model": {
|
||||||
|
"type": "string",
|
||||||
|
"nullable": true
|
||||||
|
},
|
||||||
"headers": {
|
"headers": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"additionalProperties": {
|
"additionalProperties": {
|
||||||
|
|||||||
@@ -216,6 +216,7 @@ export type DeclarativeProviderConfig = {
|
|||||||
dynamic_models?: boolean | null;
|
dynamic_models?: boolean | null;
|
||||||
engine: ProviderEngine;
|
engine: ProviderEngine;
|
||||||
env_vars?: Array<EnvVarConfig> | null;
|
env_vars?: Array<EnvVarConfig> | null;
|
||||||
|
fast_model?: string | null;
|
||||||
headers?: {
|
headers?: {
|
||||||
[key: string]: string;
|
[key: string]: string;
|
||||||
} | null;
|
} | null;
|
||||||
|
|||||||
Reference in New Issue
Block a user