Files
Atlas/internal/domain/provider_compat.go
T
renjue 8eacbb2b3e
CI / docker (push) Successful in 3m7s
实现 Atlas AI 平台一期能力并完成品牌化改造。
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-29 23:01:52 +08:00

72 lines
1.7 KiB
Go

package domain
import "fmt"
var protocolServiceTypes = map[string][]ServiceType{
"openai": {ServiceChat},
"replicate": {ServiceImageGeneration},
}
var serviceTypeProtocol = map[ServiceType]string{
ServiceChat: "openai",
ServiceImageGeneration: "replicate",
}
func DefaultProtocol(serviceType ServiceType) string {
if p, ok := serviceTypeProtocol[serviceType]; ok {
return p
}
return "openai"
}
func DefaultServiceType(protocol string) ServiceType {
types := ServiceTypesForProtocol(protocol)
if len(types) == 0 {
return ServiceChat
}
return types[0]
}
func ServiceTypesForProtocol(protocol string) []ServiceType {
return append([]ServiceType(nil), protocolServiceTypes[protocol]...)
}
func ProtocolForServiceType(serviceType ServiceType) string {
return DefaultProtocol(serviceType)
}
func ValidateProviderBinding(protocol, serviceType string) error {
types := ServiceTypesForProtocol(protocol)
if len(types) == 0 {
return fmt.Errorf("unsupported protocol: %s", protocol)
}
st := ServiceType(serviceType)
for _, allowed := range types {
if allowed == st {
return nil
}
}
// Allow legacy provider rows until migrated.
if protocol == "replicate" && (st == ServiceTextToImage || st == ServiceImageToImage) {
return nil
}
return fmt.Errorf("protocol %s does not support service_type %s", protocol, serviceType)
}
func ImageProviderServiceTypes() []string {
return []string{
string(ServiceImageGeneration),
string(ServiceTextToImage),
string(ServiceImageToImage),
}
}
func IsImageProviderServiceType(serviceType string) bool {
switch ServiceType(serviceType) {
case ServiceImageGeneration, ServiceTextToImage, ServiceImageToImage:
return true
default:
return false
}
}