Merge pull request #2 from vvr3ddy/fix/provider-creation-fallback
fix(providers): add fallback support at provider creation time
This commit is contained in:
commit
e8e89a8e02
1 changed files with 40 additions and 16 deletions
|
|
@ -28,10 +28,20 @@ func CreateProvider(cfg *config.Config) (LLMProvider, string, error) {
|
||||||
return nil, "", fmt.Errorf("no providers configured. Please add entries to model_list in your config")
|
return nil, "", fmt.Errorf("no providers configured. Please add entries to model_list in your config")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Collect models to try: primary first, then fallbacks
|
||||||
|
modelsToTry := []string{model}
|
||||||
|
modelsToTry = append(modelsToTry, cfg.Agents.Defaults.ModelFallbacks...)
|
||||||
|
|
||||||
|
var lastErr error
|
||||||
|
for i, modelName := range modelsToTry {
|
||||||
// Get model config from model_list
|
// Get model config from model_list
|
||||||
modelCfg, err := cfg.GetModelConfig(model)
|
modelCfg, err := cfg.GetModelConfig(modelName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", fmt.Errorf("model %q not found in model_list: %w", model, err)
|
lastErr = fmt.Errorf("model %q not found in model_list: %w", modelName, err)
|
||||||
|
if i == len(modelsToTry)-1 {
|
||||||
|
return nil, "", lastErr
|
||||||
|
}
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inject global workspace if not set in model config
|
// Inject global workspace if not set in model config
|
||||||
|
|
@ -42,8 +52,22 @@ func CreateProvider(cfg *config.Config) (LLMProvider, string, error) {
|
||||||
// Use factory to create provider
|
// Use factory to create provider
|
||||||
provider, modelID, err := CreateProviderFromConfig(modelCfg)
|
provider, modelID, err := CreateProviderFromConfig(modelCfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, "", fmt.Errorf("failed to create provider for model %q: %w", model, err)
|
lastErr = fmt.Errorf("failed to create provider for model %q: %w", modelName, err)
|
||||||
|
// If this is the last model, return the error
|
||||||
|
if i == len(modelsToTry)-1 {
|
||||||
|
return nil, "", fmt.Errorf("all provider creation attempts failed. Last error: %w", lastErr)
|
||||||
|
}
|
||||||
|
// Otherwise, try the next fallback model
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Success! Return the provider
|
||||||
|
if modelName != model {
|
||||||
|
// Log that we're using a fallback model
|
||||||
return provider, modelID, nil
|
return provider, modelID, nil
|
||||||
}
|
}
|
||||||
|
return provider, modelID, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, "", lastErr
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue