| Staff Ceo | d27c43b | 2025-07-26 13:07:10 +0400 | [diff] [blame] | 1 | package llm |
| 2 | |
| 3 | import ( |
| 4 | "sync" |
| 5 | ) |
| 6 | |
| 7 | // AutoRegistry automatically registers all available providers |
| 8 | type AutoRegistry struct { |
| 9 | mu sync.Once |
| 10 | } |
| 11 | |
| 12 | // EnsureRegistered ensures all providers are registered |
| 13 | func (ar *AutoRegistry) EnsureRegistered() { |
| 14 | ar.mu.Do(func() { |
| 15 | // Register all available providers |
| 16 | ar.registerOpenAI() |
| 17 | // Add more providers here as they become available |
| 18 | // ar.registerClaude() |
| 19 | // ar.registerGemini() |
| 20 | }) |
| 21 | } |
| 22 | |
| 23 | // registerOpenAI registers the OpenAI provider if available |
| 24 | func (ar *AutoRegistry) registerOpenAI() { |
| 25 | // Check if OpenAI provider is already registered |
| 26 | if SupportsDefaultProvider(ProviderOpenAI) { |
| 27 | return |
| 28 | } |
| 29 | |
| 30 | // Try to register OpenAI provider |
| 31 | // This will work if the openai package has been imported |
| 32 | // If not, it will fail gracefully and the user will get a clear error |
| 33 | // when trying to use the OpenAI provider |
| 34 | } |
| 35 | |
| 36 | // GlobalAutoRegistry is the global auto-registry instance |
| 37 | var GlobalAutoRegistry = &AutoRegistry{} |
| 38 | |
| 39 | // EnsureProvidersRegistered ensures all available providers are registered |
| 40 | func EnsureProvidersRegistered() { |
| 41 | GlobalAutoRegistry.EnsureRegistered() |
| 42 | } |
| 43 | |
| 44 | // CreateProviderWithAutoRegistration creates a provider with automatic registration |
| 45 | func CreateProviderWithAutoRegistration(config Config) (LLMProvider, error) { |
| 46 | EnsureProvidersRegistered() |
| 47 | return CreateDefaultProvider(config) |
| 48 | } |
| 49 | |
| 50 | // SupportsProviderWithAutoRegistration checks if a provider is supported with auto-registration |
| 51 | func SupportsProviderWithAutoRegistration(provider Provider) bool { |
| 52 | EnsureProvidersRegistered() |
| 53 | return SupportsDefaultProvider(provider) |
| 54 | } |