feat(gcp-vertex): add model list with org policy filtering (#6393)
Signed-off-by: rabi <ramishra@redhat.com>
This commit is contained in:
@@ -630,6 +630,10 @@ export type ProviderEngine = 'openai' | 'ollama' | 'anthropic';
|
||||
* Metadata about a provider's configuration requirements and capabilities
|
||||
*/
|
||||
export type ProviderMetadata = {
|
||||
/**
|
||||
* Whether this provider allows entering model names not in the fetched list
|
||||
*/
|
||||
allows_unlisted_models?: boolean;
|
||||
/**
|
||||
* Required configuration keys
|
||||
*/
|
||||
|
||||
@@ -119,12 +119,17 @@ export function LeadWorkerSettings({ isOpen, onClose }: LeadWorkerSettingsProps)
|
||||
});
|
||||
});
|
||||
}
|
||||
// Add custom model option for all non-Custom providers
|
||||
if (p.provider_type !== 'Custom') {
|
||||
options.push({
|
||||
value: `__custom__:${p.name}`,
|
||||
label: 'Enter a model not listed...',
|
||||
provider: p.name,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Append a simple "custom" option to enable free-text entry
|
||||
options.push({ value: '__custom__', label: 'Use custom model…', provider: '' });
|
||||
|
||||
setModelOptions(options);
|
||||
} catch (error) {
|
||||
console.error('Error loading configuration:', error);
|
||||
@@ -241,9 +246,10 @@ export function LeadWorkerSettings({ isOpen, onClose }: LeadWorkerSettingsProps)
|
||||
onChange={(newValue: unknown) => {
|
||||
const option = newValue as { value: string; provider: string } | null;
|
||||
if (option) {
|
||||
if (option.value === '__custom__') {
|
||||
if (option.value.startsWith('__custom__')) {
|
||||
setIsLeadCustomModel(true);
|
||||
setLeadModel('');
|
||||
setLeadProvider(option.provider);
|
||||
return;
|
||||
}
|
||||
setLeadModel(option.value);
|
||||
@@ -294,9 +300,10 @@ export function LeadWorkerSettings({ isOpen, onClose }: LeadWorkerSettingsProps)
|
||||
onChange={(newValue: unknown) => {
|
||||
const option = newValue as { value: string; provider: string } | null;
|
||||
if (option) {
|
||||
if (option.value === '__custom__') {
|
||||
if (option.value.startsWith('__custom__')) {
|
||||
setIsWorkerCustomModel(true);
|
||||
setWorkerModel('');
|
||||
setWorkerProvider(option.provider);
|
||||
return;
|
||||
}
|
||||
setWorkerModel(option.value);
|
||||
|
||||
@@ -213,29 +213,34 @@ export const SwitchModelModal = ({
|
||||
const errors: string[] = [];
|
||||
|
||||
results.forEach(({ provider: p, models, error }) => {
|
||||
const modelList = error
|
||||
? (p.metadata.known_models?.map(({ name }) => name) || [])
|
||||
: (models || []);
|
||||
|
||||
if (error) {
|
||||
errors.push(error);
|
||||
// Fallback to metadata known_models on error
|
||||
if (p.metadata.known_models && p.metadata.known_models.length > 0) {
|
||||
groupedOptions.push({
|
||||
options: p.metadata.known_models.map(({ name }) => ({
|
||||
value: name,
|
||||
label: name,
|
||||
providerType: p.provider_type,
|
||||
provider: p.name,
|
||||
})),
|
||||
});
|
||||
}
|
||||
} else if (models && models.length > 0) {
|
||||
groupedOptions.push({
|
||||
options: models.map((m) => ({
|
||||
value: m,
|
||||
label: m,
|
||||
provider: p.name,
|
||||
providerType: p.provider_type,
|
||||
})),
|
||||
}
|
||||
|
||||
const options: { value: string; label: string; provider: string; providerType: ProviderType }[] =
|
||||
modelList.map((m) => ({
|
||||
value: m,
|
||||
label: m,
|
||||
provider: p.name,
|
||||
providerType: p.provider_type,
|
||||
}));
|
||||
|
||||
if (p.metadata.allows_unlisted_models && p.provider_type !== 'Custom') {
|
||||
options.push({
|
||||
value: 'custom',
|
||||
label: 'Enter a model not listed...',
|
||||
provider: p.name,
|
||||
providerType: p.provider_type,
|
||||
});
|
||||
}
|
||||
|
||||
if (options.length > 0) {
|
||||
groupedOptions.push({ options });
|
||||
}
|
||||
});
|
||||
|
||||
// Log errors if any providers failed (don't show to user)
|
||||
@@ -243,20 +248,6 @@ export const SwitchModelModal = ({
|
||||
console.error('Provider model fetch errors:', errors);
|
||||
}
|
||||
|
||||
// Add the "Custom model" option to each provider group
|
||||
groupedOptions.forEach((group) => {
|
||||
const option = group.options[0];
|
||||
const providerName = option?.provider;
|
||||
if (providerName && option?.providerType !== 'Custom') {
|
||||
group.options.push({
|
||||
value: 'custom',
|
||||
label: 'Use custom model',
|
||||
provider: providerName,
|
||||
providerType: option?.providerType,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
setModelOptions(groupedOptions);
|
||||
setOriginalModelOptions(groupedOptions);
|
||||
} catch (error: unknown) {
|
||||
@@ -293,6 +284,7 @@ export const SwitchModelModal = ({
|
||||
if (selectedOption?.value === 'custom') {
|
||||
setIsCustomModel(true);
|
||||
setModel('');
|
||||
setProvider(selectedOption.provider);
|
||||
setUserClearedModel(false);
|
||||
} else if (selectedOption === null) {
|
||||
// User cleared the selection
|
||||
@@ -302,6 +294,7 @@ export const SwitchModelModal = ({
|
||||
} else {
|
||||
setIsCustomModel(false);
|
||||
setModel(selectedOption?.value || '');
|
||||
setProvider(selectedOption?.provider || '');
|
||||
setUserClearedModel(false);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user