feat(gcp-vertex): add model list with org policy filtering (#6393)
Signed-off-by: rabi <ramishra@redhat.com>
This commit is contained in:
@@ -436,12 +436,12 @@ fn select_model_from_list(
|
||||
provider_meta: &goose::providers::base::ProviderMetadata,
|
||||
) -> anyhow::Result<String> {
|
||||
const MAX_MODELS: usize = 10;
|
||||
const UNLISTED_MODEL_KEY: &str = "__unlisted__";
|
||||
|
||||
// Smart model selection:
|
||||
// If we have more than MAX_MODELS models, show the recommended models with additional search option.
|
||||
// Otherwise, show all models without search.
|
||||
|
||||
if models.len() > MAX_MODELS {
|
||||
// Get recommended models from provider metadata
|
||||
let recommended_models: Vec<String> = provider_meta
|
||||
.known_models
|
||||
.iter()
|
||||
@@ -464,12 +464,22 @@ fn select_model_from_list(
|
||||
),
|
||||
);
|
||||
|
||||
if provider_meta.allows_unlisted_models {
|
||||
model_items.push((
|
||||
UNLISTED_MODEL_KEY.to_string(),
|
||||
"Enter a model not listed...".to_string(),
|
||||
"",
|
||||
));
|
||||
}
|
||||
|
||||
let selection = cliclack::select("Select a model:")
|
||||
.items(&model_items)
|
||||
.interact()?;
|
||||
|
||||
if selection == "search_all" {
|
||||
Ok(interactive_model_search(models)?)
|
||||
} else if selection == UNLISTED_MODEL_KEY {
|
||||
prompt_unlisted_model(provider_meta)
|
||||
} else {
|
||||
Ok(selection)
|
||||
}
|
||||
@@ -477,19 +487,45 @@ fn select_model_from_list(
|
||||
Ok(interactive_model_search(models)?)
|
||||
}
|
||||
} else {
|
||||
// just a few models, show all without search for better UX
|
||||
Ok(cliclack::select("Select a model:")
|
||||
.items(
|
||||
&models
|
||||
.iter()
|
||||
.map(|m| (m, m.as_str(), ""))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.interact()?
|
||||
.to_string())
|
||||
let mut model_items: Vec<(String, String, &str)> =
|
||||
models.iter().map(|m| (m.clone(), m.clone(), "")).collect();
|
||||
|
||||
if provider_meta.allows_unlisted_models {
|
||||
model_items.push((
|
||||
UNLISTED_MODEL_KEY.to_string(),
|
||||
"Enter a model not listed...".to_string(),
|
||||
"",
|
||||
));
|
||||
}
|
||||
|
||||
let selection = cliclack::select("Select a model:")
|
||||
.items(&model_items)
|
||||
.interact()?;
|
||||
|
||||
if selection == UNLISTED_MODEL_KEY {
|
||||
prompt_unlisted_model(provider_meta)
|
||||
} else {
|
||||
Ok(selection)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn prompt_unlisted_model(
|
||||
provider_meta: &goose::providers::base::ProviderMetadata,
|
||||
) -> anyhow::Result<String> {
|
||||
let model: String = cliclack::input("Enter the model name:")
|
||||
.placeholder(&provider_meta.default_model)
|
||||
.validate(|input: &String| {
|
||||
if input.trim().is_empty() {
|
||||
Err("Please enter a model name")
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
})
|
||||
.interact()?;
|
||||
Ok(model.trim().to_string())
|
||||
}
|
||||
|
||||
fn try_store_secret(config: &Config, key_name: &str, value: String) -> anyhow::Result<bool> {
|
||||
match config.set_secret(key_name, &value) {
|
||||
Ok(_) => Ok(true),
|
||||
|
||||
Reference in New Issue
Block a user