Use Canonical Models to set context window sizes (#6723)
This commit is contained in:
@@ -327,7 +327,7 @@ async fn handle_oauth_configuration(provider_name: &str, key_name: &str) -> anyh
|
||||
));
|
||||
|
||||
// Create a temporary provider instance to handle OAuth
|
||||
let temp_model = ModelConfig::new("temp")?;
|
||||
let temp_model = ModelConfig::new("temp")?.with_canonical_limits(provider_name);
|
||||
match create(provider_name, temp_model, Vec::new()).await {
|
||||
Ok(provider) => match provider.configure_oauth().await {
|
||||
Ok(_) => {
|
||||
@@ -682,7 +682,8 @@ pub async fn configure_provider_dialog() -> anyhow::Result<bool> {
|
||||
let spin = spinner();
|
||||
spin.start("Attempting to fetch supported models...");
|
||||
let models_res = {
|
||||
let temp_model_config = ModelConfig::new(&provider_meta.default_model)?;
|
||||
let temp_model_config =
|
||||
ModelConfig::new(&provider_meta.default_model)?.with_canonical_limits(provider_name);
|
||||
let temp_provider = create(provider_name, temp_model_config, Vec::new()).await?;
|
||||
retry_operation(&RetryConfig::default(), || async {
|
||||
temp_provider.fetch_recommended_models().await
|
||||
@@ -1442,7 +1443,7 @@ pub async fn configure_tool_permissions_dialog() -> anyhow::Result<()> {
|
||||
let model: String = config
|
||||
.get_goose_model()
|
||||
.expect("No model configured. Please set model first");
|
||||
let model_config = ModelConfig::new(&model)?;
|
||||
let model_config = ModelConfig::new(&model)?.with_canonical_limits(&provider_name);
|
||||
|
||||
let agent = Agent::new();
|
||||
|
||||
@@ -1662,7 +1663,7 @@ pub async fn handle_openrouter_auth() -> anyhow::Result<()> {
|
||||
println!("\nTesting configuration...");
|
||||
let configured_model: String = config.get_goose_model()?;
|
||||
let model_config = match goose::model::ModelConfig::new(&configured_model) {
|
||||
Ok(config) => config,
|
||||
Ok(config) => config.with_canonical_limits("openrouter"),
|
||||
Err(e) => {
|
||||
eprintln!("⚠️ Invalid model configuration: {}", e);
|
||||
eprintln!("Your settings have been saved. Please check your model configuration.");
|
||||
@@ -1742,7 +1743,7 @@ pub async fn handle_tetrate_auth() -> anyhow::Result<()> {
|
||||
println!("\nTesting configuration...");
|
||||
let configured_model: String = config.get_goose_model()?;
|
||||
let model_config = match goose::model::ModelConfig::new(&configured_model) {
|
||||
Ok(config) => config,
|
||||
Ok(config) => config.with_canonical_limits("tetrate"),
|
||||
Err(e) => {
|
||||
eprintln!("⚠️ Invalid model configuration: {}", e);
|
||||
eprintln!("Your settings have been saved. Please check your model configuration.");
|
||||
|
||||
@@ -291,7 +291,13 @@ pub async fn handle_term_info() -> Result<()> {
|
||||
let context_limit = config
|
||||
.get_goose_model()
|
||||
.ok()
|
||||
.and_then(|model_name| goose::model::ModelConfig::new(&model_name).ok())
|
||||
.and_then(|model_name| {
|
||||
config.get_goose_provider().ok().and_then(|provider_name| {
|
||||
goose::model::ModelConfig::new(&model_name)
|
||||
.ok()
|
||||
.map(|c| c.with_canonical_limits(&provider_name))
|
||||
})
|
||||
})
|
||||
.map(|mc| mc.context_limit())
|
||||
.unwrap_or(128_000);
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ fn get_provider_and_model() -> (String, String) {
|
||||
}
|
||||
|
||||
async fn create_agent(provider_name: &str, model: &str) -> Result<Agent> {
|
||||
let model_config = goose::model::ModelConfig::new(model)?;
|
||||
let model_config = goose::model::ModelConfig::new(model)?.with_canonical_limits(provider_name);
|
||||
|
||||
let agent = Agent::new();
|
||||
|
||||
|
||||
@@ -188,7 +188,7 @@ where
|
||||
|
||||
let inner_provider = create(
|
||||
&factory_name,
|
||||
ModelConfig::new(config.model_name)?,
|
||||
ModelConfig::new(config.model_name)?.with_canonical_limits(&factory_name),
|
||||
Vec::new(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
@@ -386,6 +386,7 @@ fn resolve_provider_and_model(
|
||||
output::render_error(&format!("Failed to create model configuration: {}", e));
|
||||
process::exit(1);
|
||||
})
|
||||
.with_canonical_limits(&provider_name)
|
||||
.with_temperature(temperature)
|
||||
};
|
||||
|
||||
|
||||
@@ -1847,7 +1847,7 @@ async fn get_reasoner() -> Result<Arc<dyn Provider>, anyhow::Error> {
|
||||
};
|
||||
|
||||
let model_config =
|
||||
ModelConfig::new_with_context_env(model, Some("GOOSE_PLANNER_CONTEXT_LIMIT"))?;
|
||||
ModelConfig::new_with_context_env(model, &provider, Some("GOOSE_PLANNER_CONTEXT_LIMIT"))?;
|
||||
let extensions = goose::config::extensions::get_enabled_extensions_with_config(config);
|
||||
let reasoner = create(&provider, model_config, extensions).await?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user