micro--go-micro
9d69029dfe
Run Tests / Unit Tests (push) Has been cancelled
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Has been cancelled
Harness (E2E) / Harnesses (mock LLM) (push) Has been cancelled
Lint / golangci-lint (push) Has been cancelled
Run Tests / Etcd Integration Tests (push) Has been cancelled
94 行
2.4 KiB
Go
94 行
2.4 KiB
Go
package ai
|
|
|
|
import "sort"
|
|
|
|
// Capabilities describes the AI interfaces a provider has registered.
|
|
// It is intentionally based on package registration rather than external
|
|
// provider marketing claims, so it reflects what this build can actually use.
|
|
type Capabilities struct {
|
|
// Model reports whether ai.New can construct a chat/text model provider.
|
|
Model bool
|
|
// Image reports whether ai.NewImage can construct an image model provider.
|
|
Image bool
|
|
// Video reports whether ai.NewVideo can construct a video model provider.
|
|
Video bool
|
|
}
|
|
|
|
// ProviderCapabilities reports the capabilities registered for provider.
|
|
func ProviderCapabilities(provider string) Capabilities {
|
|
_, hasModel := providers[provider]
|
|
_, hasImage := imageProviders[provider]
|
|
_, hasVideo := videoProviders[provider]
|
|
|
|
return Capabilities{
|
|
Model: hasModel,
|
|
Image: hasImage,
|
|
Video: hasVideo,
|
|
}
|
|
}
|
|
|
|
// CapabilityMatrix returns a stable snapshot of all registered AI providers and
|
|
// the interfaces they support. The returned map is a copy and can be modified by
|
|
// callers without mutating the registry.
|
|
func CapabilityMatrix() map[string]Capabilities {
|
|
names := map[string]struct{}{}
|
|
for name := range providers {
|
|
names[name] = struct{}{}
|
|
}
|
|
for name := range imageProviders {
|
|
names[name] = struct{}{}
|
|
}
|
|
for name := range videoProviders {
|
|
names[name] = struct{}{}
|
|
}
|
|
|
|
matrix := make(map[string]Capabilities, len(names))
|
|
for name := range names {
|
|
matrix[name] = ProviderCapabilities(name)
|
|
}
|
|
return matrix
|
|
}
|
|
|
|
// RegisteredProviders returns the registered provider names in sorted order.
|
|
// kind may be "model", "image", "video", or empty for the union of all
|
|
// provider registries.
|
|
func RegisteredProviders(kind string) []string {
|
|
names := map[string]struct{}{}
|
|
add := func(registry any) {
|
|
switch r := registry.(type) {
|
|
case map[string]NewFunc:
|
|
for name := range r {
|
|
names[name] = struct{}{}
|
|
}
|
|
case map[string]NewImageFunc:
|
|
for name := range r {
|
|
names[name] = struct{}{}
|
|
}
|
|
case map[string]NewVideoFunc:
|
|
for name := range r {
|
|
names[name] = struct{}{}
|
|
}
|
|
}
|
|
}
|
|
|
|
switch kind {
|
|
case "model":
|
|
add(providers)
|
|
case "image":
|
|
add(imageProviders)
|
|
case "video":
|
|
add(videoProviders)
|
|
default:
|
|
add(providers)
|
|
add(imageProviders)
|
|
add(videoProviders)
|
|
}
|
|
|
|
out := make([]string, 0, len(names))
|
|
for name := range names {
|
|
out = append(out, name)
|
|
}
|
|
sort.Strings(out)
|
|
return out
|
|
}
|