mirror of
https://github.com/stackblitz-labs/bolt.diy
synced 2025-06-26 18:26:38 +00:00
Fix Bayer MGA provider model selection and improve error handling
- Enhanced BayerMGAProvider getModelInstance method with model validation - Added fallback mechanism when requested model is not available - Improved dynamic model filtering with better validation - Added UI model selection handling for unavailable models - Added README.md to ECR deploy workflow paths-ignore 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2127d113f0
commit
0ecb5af30e
1
.github/workflows/ecr-deploy.yaml
vendored
1
.github/workflows/ecr-deploy.yaml
vendored
@ -6,6 +6,7 @@ on:
|
|||||||
tags: ['v*', '*.*.*']
|
tags: ['v*', '*.*.*']
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- 'k8s/**'
|
- 'k8s/**'
|
||||||
|
- 'README.md'
|
||||||
workflow_dispatch: # Allows manual triggering
|
workflow_dispatch: # Allows manual triggering
|
||||||
inputs:
|
inputs:
|
||||||
create_deployment_pr:
|
create_deployment_pr:
|
||||||
|
@ -204,6 +204,20 @@ export const ModelSelector = ({
|
|||||||
}
|
}
|
||||||
}, [providerList, provider, setProvider, modelList, setModel]);
|
}, [providerList, provider, setProvider, modelList, setModel]);
|
||||||
|
|
||||||
|
// Handle case where selected model is no longer available after model list update
|
||||||
|
useEffect(() => {
|
||||||
|
if (model && provider && modelList.length > 0) {
|
||||||
|
const currentProviderModels = modelList.filter((m) => m.provider === provider.name);
|
||||||
|
const isModelStillAvailable = currentProviderModels.some((m) => m.name === model);
|
||||||
|
|
||||||
|
if (!isModelStillAvailable && currentProviderModels.length > 0 && setModel) {
|
||||||
|
// Selected model is no longer available, switch to first available model for this provider
|
||||||
|
const fallbackModel = currentProviderModels[0];
|
||||||
|
setModel(fallbackModel.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [modelList, model, provider, setModel]);
|
||||||
|
|
||||||
if (providerList.length === 0) {
|
if (providerList.length === 0) {
|
||||||
return (
|
return (
|
||||||
<div className="mb-2 p-4 rounded-lg border border-bolt-elements-borderColor bg-bolt-elements-prompt-background text-bolt-elements-textPrimary">
|
<div className="mb-2 p-4 rounded-lg border border-bolt-elements-borderColor bg-bolt-elements-prompt-background text-bolt-elements-textPrimary">
|
||||||
|
@ -85,15 +85,29 @@ export default class BayerMGAProvider extends BaseProvider {
|
|||||||
|
|
||||||
// Filter for available models and map to ModelInfo format
|
// Filter for available models and map to ModelInfo format
|
||||||
const models = res.data
|
const models = res.data
|
||||||
.filter((model: any) => model.model_status === 'available')
|
.filter((model: any) => {
|
||||||
|
// Only include models with 'available' status and valid model names
|
||||||
|
return model.model_status === 'available' &&
|
||||||
|
model.model &&
|
||||||
|
typeof model.model === 'string' &&
|
||||||
|
model.model.trim().length > 0;
|
||||||
|
})
|
||||||
.map((model: any) => ({
|
.map((model: any) => ({
|
||||||
name: model.model,
|
name: model.model.trim(),
|
||||||
label: model.name || model.model,
|
label: model.name || model.model,
|
||||||
provider: this.name,
|
provider: this.name,
|
||||||
maxTokenAllowed: model.context_window || 8000,
|
maxTokenAllowed: model.context_window || 8000,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
logger.info(`Found ${models.length} available models from Bayer MGA`);
|
logger.info(`Found ${models.length} available models from Bayer MGA`);
|
||||||
|
|
||||||
|
// Log model names for debugging
|
||||||
|
if (models.length > 0) {
|
||||||
|
logger.debug(`Available Bayer MGA models: ${models.map(m => m.name).join(', ')}`);
|
||||||
|
} else {
|
||||||
|
logger.warn('No available models returned from Bayer MGA API');
|
||||||
|
}
|
||||||
|
|
||||||
return models;
|
return models;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(`Error fetching Bayer MGA models: ${error instanceof Error ? error.message : String(error)}`);
|
logger.error(`Error fetching Bayer MGA models: ${error instanceof Error ? error.message : String(error)}`);
|
||||||
@ -128,13 +142,37 @@ export default class BayerMGAProvider extends BaseProvider {
|
|||||||
// Normalize base URL (remove trailing slash)
|
// Normalize base URL (remove trailing slash)
|
||||||
const normalizedBaseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
|
const normalizedBaseUrl = baseUrl.endsWith('/') ? baseUrl.slice(0, -1) : baseUrl;
|
||||||
|
|
||||||
logger.info(`Creating model instance for ${model} using Bayer MGA API at ${normalizedBaseUrl}`);
|
// Get cached models to validate model availability
|
||||||
|
const cachedModels = this.getModelsFromCache({
|
||||||
|
apiKeys,
|
||||||
|
providerSettings: providerSettings?.[this.name],
|
||||||
|
serverEnv: serverEnv as any,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check if the requested model is available (either in cache or static models)
|
||||||
|
const availableModels = [...this.staticModels, ...(cachedModels || [])];
|
||||||
|
const modelExists = availableModels.some(m => m.name === model);
|
||||||
|
|
||||||
|
let effectiveModel = model;
|
||||||
|
if (!modelExists) {
|
||||||
|
logger.warn(`Model ${model} not found in available models for Bayer MGA. Available models: ${availableModels.map(m => m.name).join(', ')}`);
|
||||||
|
// Fall back to first available model if the requested model is not found
|
||||||
|
const fallbackModel = availableModels[0];
|
||||||
|
if (fallbackModel) {
|
||||||
|
logger.info(`Using fallback model: ${fallbackModel.name}`);
|
||||||
|
effectiveModel = fallbackModel.name;
|
||||||
|
} else {
|
||||||
|
throw new Error(`No models available for ${this.name} provider. Please check your API key and try again.`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.info(`Creating model instance for ${effectiveModel} using Bayer MGA API at ${normalizedBaseUrl}`);
|
||||||
|
|
||||||
const openai = createOpenAI({
|
const openai = createOpenAI({
|
||||||
baseURL: normalizedBaseUrl,
|
baseURL: normalizedBaseUrl,
|
||||||
apiKey,
|
apiKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
return openai(model);
|
return openai(effectiveModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user