mirror of
https://github.com/sipeed/picoclaw.git
synced 2026-06-12 18:08:54 +00:00
712f5a8300
The configuration field for specifying the model has been renamed from "model" to "model_name" for better clarity and consistency with the model_list configuration. A GetModelName() accessor method has been added to maintain backward compatibility. Existing configurations using the old "model" field will continue to work correctly. This change affects: - Configuration structure (AgentDefaults struct) - All references across the codebase - Documentation in all language variants - Example configuration files
50 lines
1.5 KiB
Go
50 lines
1.5 KiB
Go
// PicoClaw - Ultra-lightweight personal AI agent
|
|
// License: MIT
|
|
//
|
|
// Copyright (c) 2026 PicoClaw contributors
|
|
|
|
package providers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/sipeed/picoclaw/pkg/config"
|
|
)
|
|
|
|
// CreateProvider creates a provider based on the configuration.
|
|
// It uses the model_list configuration (new format) to create providers.
|
|
// The old providers config is automatically converted to model_list during config loading.
|
|
// Returns the provider, the model ID to use, and any error.
|
|
func CreateProvider(cfg *config.Config) (LLMProvider, string, error) {
|
|
model := cfg.Agents.Defaults.GetModelName()
|
|
|
|
// Ensure model_list is populated (should be done by LoadConfig, but handle edge cases)
|
|
if len(cfg.ModelList) == 0 && cfg.HasProvidersConfig() {
|
|
cfg.ModelList = config.ConvertProvidersToModelList(cfg)
|
|
}
|
|
|
|
// Must have model_list at this point
|
|
if len(cfg.ModelList) == 0 {
|
|
return nil, "", fmt.Errorf("no providers configured. Please add entries to model_list in your config")
|
|
}
|
|
|
|
// Get model config from model_list
|
|
modelCfg, err := cfg.GetModelConfig(model)
|
|
if err != nil {
|
|
return nil, "", fmt.Errorf("model %q not found in model_list: %w", model, err)
|
|
}
|
|
|
|
// Inject global workspace if not set in model config
|
|
if modelCfg.Workspace == "" {
|
|
modelCfg.Workspace = cfg.WorkspacePath()
|
|
}
|
|
|
|
// Use factory to create provider
|
|
provider, modelID, err := CreateProviderFromConfig(modelCfg)
|
|
if err != nil {
|
|
return nil, "", fmt.Errorf("failed to create provider for model %q: %w", model, err)
|
|
}
|
|
|
|
return provider, modelID, nil
|
|
}
|