mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-11-16 22:57:53 +08:00
516 lines
19 KiB
Go
516 lines
19 KiB
Go
package auth
|
|
|
|
import (
|
|
"maps"
|
|
"strings"
|
|
|
|
"github.com/MoeForge/moego/json"
|
|
internalconfig "github.com/router-for-me/CLIProxyAPI/v8/internal/config"
|
|
"github.com/router-for-me/CLIProxyAPI/v8/internal/modelconfig"
|
|
"github.com/router-for-me/CLIProxyAPI/v8/internal/registry"
|
|
"github.com/router-for-me/CLIProxyAPI/v8/internal/thinking"
|
|
cliproxyexecutor "github.com/router-for-me/CLIProxyAPI/v8/sdk/cliproxy/executor"
|
|
)
|
|
|
|
const (
|
|
resolvedAPIKeyModelInfoMetadataKey = "cliproxy.resolved_api_key_model_info"
|
|
resolvedCodexOAuthModelInfoMetadataKey = "cliproxy.resolved_codex_oauth_model_info"
|
|
resolvedHomeModelInfoMetadataKey = "cliproxy.resolved_home_model_info"
|
|
resolvedHomeModelOptionsMetadataKey = "cliproxy.resolved_home_model_options"
|
|
)
|
|
|
|
type apiKeyModelCapabilityRoute struct {
|
|
upstreamModel string
|
|
modelInfo *registry.ModelInfo
|
|
}
|
|
|
|
type apiKeyModelCapabilityTable map[string]map[string][]apiKeyModelCapabilityRoute
|
|
|
|
type apiKeyModelRoutingSnapshot struct {
|
|
config *internalconfig.Config
|
|
aliases apiKeyModelAliasTable
|
|
capabilities apiKeyModelCapabilityTable
|
|
}
|
|
|
|
func isConfiguredModelRoutingAuth(auth *Auth) bool {
|
|
if auth != nil && auth.AuthKind() == AuthKindAPIKey {
|
|
return true
|
|
}
|
|
if auth == nil || auth.AuthSourceKind() != AuthSourceConfig || auth.Attributes == nil {
|
|
return false
|
|
}
|
|
return strings.TrimSpace(auth.Attributes["compat_name"]) != ""
|
|
}
|
|
|
|
func (m *Manager) loadAPIKeyModelRouting() *apiKeyModelRoutingSnapshot {
|
|
if m == nil {
|
|
return &apiKeyModelRoutingSnapshot{config: &internalconfig.Config{}}
|
|
}
|
|
snapshot, _ := m.apiKeyModelRouting.Load().(*apiKeyModelRoutingSnapshot)
|
|
if snapshot == nil {
|
|
return &apiKeyModelRoutingSnapshot{config: &internalconfig.Config{}}
|
|
}
|
|
return snapshot
|
|
}
|
|
|
|
// ResolvedAPIKeyModelInfo returns the exact configured model definition bound to
|
|
// this API-key execution attempt.
|
|
func ResolvedAPIKeyModelInfo(req cliproxyexecutor.Request) (*registry.ModelInfo, bool) {
|
|
modelInfo, ok := req.Metadata[resolvedAPIKeyModelInfoMetadataKey].(*registry.ModelInfo)
|
|
if !ok || modelInfo == nil {
|
|
return nil, false
|
|
}
|
|
return modelInfo, true
|
|
}
|
|
|
|
// ResolvedModelInfo returns the authoritative model capabilities bound to this execution attempt.
|
|
func ResolvedModelInfo(req cliproxyexecutor.Request) (*registry.ModelInfo, bool) {
|
|
if modelInfo, ok := req.Metadata[resolvedHomeModelInfoMetadataKey].(*registry.ModelInfo); ok && modelInfo != nil {
|
|
return modelInfo, true
|
|
}
|
|
if modelInfo, ok := req.Metadata[resolvedCodexOAuthModelInfoMetadataKey].(*registry.ModelInfo); ok && modelInfo != nil {
|
|
return modelInfo, true
|
|
}
|
|
return ResolvedAPIKeyModelInfo(req)
|
|
}
|
|
|
|
// ResolvedHomeModelOptions returns the credential model options selected for this attempt.
|
|
// A present but unmatched or empty models list yields zero-value options.
|
|
func ResolvedHomeModelOptions(req cliproxyexecutor.Request) (internalconfig.OpenAICompatibilityModel, bool) {
|
|
options, ok := req.Metadata[resolvedHomeModelOptionsMetadataKey].(internalconfig.OpenAICompatibilityModel)
|
|
return options, ok
|
|
}
|
|
|
|
// CodexAPIKeyModelIsCompat reports whether the selected codex-api-key model has
|
|
// is-compat enabled. When true, Codex MultiAgentV2 agent_message items are converted
|
|
// into portable Responses message/user input for third-party Responses-compatible endpoints.
|
|
func CodexAPIKeyModelIsCompat(cfg *internalconfig.Config, auth *Auth, model string) bool {
|
|
if cfg == nil || auth == nil || !strings.EqualFold(strings.TrimSpace(auth.Provider), "codex") {
|
|
return false
|
|
}
|
|
entry := resolveCodexAPIKeyConfig(cfg, auth)
|
|
if cfg.Home.Enabled {
|
|
if options, configured := homeAPIKeyModelOptions(auth, model, model); configured {
|
|
return options.IsCompat
|
|
}
|
|
}
|
|
if entry == nil || len(entry.Models) == 0 {
|
|
return false
|
|
}
|
|
requested := strings.TrimSpace(model)
|
|
if requested == "" {
|
|
return false
|
|
}
|
|
baseModel := strings.TrimSpace(thinking.ParseSuffix(requested).ModelName)
|
|
if baseModel == "" {
|
|
baseModel = requested
|
|
}
|
|
for i := range entry.Models {
|
|
name := strings.TrimSpace(entry.Models[i].Name)
|
|
alias := strings.TrimSpace(entry.Models[i].Alias)
|
|
if name == "" {
|
|
name = alias
|
|
}
|
|
if alias == "" {
|
|
alias = name
|
|
}
|
|
if name == "" {
|
|
continue
|
|
}
|
|
if strings.EqualFold(name, requested) || strings.EqualFold(name, baseModel) ||
|
|
strings.EqualFold(alias, requested) || strings.EqualFold(alias, baseModel) {
|
|
return entry.Models[i].IsCompat
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// homeAPIKeyModelOptions reads the selected credential's model configuration.
|
|
// A present models list is authoritative, including empty lists and false defaults.
|
|
func homeAPIKeyModelOptions(auth *Auth, model, routeModel string) (internalconfig.OpenAICompatibilityModel, bool) {
|
|
var empty internalconfig.OpenAICompatibilityModel
|
|
if auth == nil {
|
|
return empty, false
|
|
}
|
|
raw, exists := auth.Metadata["credential_options"]
|
|
if !exists {
|
|
return empty, false
|
|
}
|
|
data, errMarshal := json.Marshal(raw)
|
|
if errMarshal != nil {
|
|
return empty, false
|
|
}
|
|
var options struct {
|
|
Models json.RawMessage `json:"models"`
|
|
}
|
|
if errDecode := json.Unmarshal(data, &options); errDecode != nil || len(options.Models) == 0 {
|
|
return empty, false
|
|
}
|
|
var models []internalconfig.OpenAICompatibilityModel
|
|
if errDecode := json.Unmarshal(options.Models, &models); errDecode != nil {
|
|
return empty, false
|
|
}
|
|
requested := strings.TrimSpace(model)
|
|
if requested == "" {
|
|
return empty, true
|
|
}
|
|
baseModel := strings.TrimSpace(thinking.ParseSuffix(requested).ModelName)
|
|
_, routeCandidates := modelAliasLookupCandidates(rewriteModelForAuth(strings.TrimSpace(routeModel), auth))
|
|
for _, route := range routeCandidates {
|
|
for _, candidate := range []string{requested, baseModel} {
|
|
for _, configured := range models {
|
|
name := strings.TrimSpace(configured.Name)
|
|
alias := strings.TrimSpace(configured.Alias)
|
|
if name == "" {
|
|
name = alias
|
|
}
|
|
if strings.EqualFold(name, candidate) && (strings.EqualFold(alias, route) || strings.EqualFold(name, route)) {
|
|
return configured, true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
// Prefer upstream names over aliases and exact suffixes over base fallbacks.
|
|
for _, useAlias := range []bool{false, true} {
|
|
for _, candidate := range []string{requested, baseModel} {
|
|
if candidate == "" {
|
|
continue
|
|
}
|
|
for _, configured := range models {
|
|
name := strings.TrimSpace(configured.Name)
|
|
if useAlias || name == "" {
|
|
name = strings.TrimSpace(configured.Alias)
|
|
}
|
|
if strings.EqualFold(name, candidate) {
|
|
return configured, true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return empty, true
|
|
}
|
|
|
|
func (m *Manager) attachResolvedAPIKeyModelInfo(req cliproxyexecutor.Request, auth *Auth, routeModel, upstreamModel string) cliproxyexecutor.Request {
|
|
return attachResolvedAPIKeyModelInfo(m.loadAPIKeyModelRouting(), req, auth, routeModel, upstreamModel)
|
|
}
|
|
|
|
func attachResolvedExecutionModelInfo(routing *apiKeyModelRoutingSnapshot, req cliproxyexecutor.Request, auth *Auth, routeModel, upstreamModel string, restoreExecutionModel bool) cliproxyexecutor.Request {
|
|
if restoreExecutionModel {
|
|
if auth == nil || !strings.EqualFold(strings.TrimSpace(auth.Provider), "codex") {
|
|
return req
|
|
}
|
|
routeModel, upstreamModel = req.Model, req.Model
|
|
}
|
|
return attachResolvedAPIKeyModelInfo(routing, req, auth, routeModel, upstreamModel)
|
|
}
|
|
|
|
func attachResolvedAPIKeyModelInfo(routing *apiKeyModelRoutingSnapshot, req cliproxyexecutor.Request, auth *Auth, routeModel, upstreamModel string) cliproxyexecutor.Request {
|
|
modelInfo, ok := lookupAPIKeyModelCapability(routing, auth, routeModel, upstreamModel)
|
|
if !ok {
|
|
modelInfo, ok = lookupUnlistedCodexAPIKeyModelCapability(routing, auth, upstreamModel)
|
|
}
|
|
metadataKey := resolvedAPIKeyModelInfoMetadataKey
|
|
if !ok {
|
|
modelInfo, ok = lookupCodexOAuthModelCapability(auth, upstreamModel)
|
|
metadataKey = resolvedCodexOAuthModelInfoMetadataKey
|
|
}
|
|
if !ok {
|
|
_, hadAPIKey := req.Metadata[resolvedAPIKeyModelInfoMetadataKey]
|
|
_, hadOAuth := req.Metadata[resolvedCodexOAuthModelInfoMetadataKey]
|
|
if !hadAPIKey && !hadOAuth {
|
|
return req
|
|
}
|
|
}
|
|
metadata := make(map[string]any, len(req.Metadata)+1)
|
|
maps.Copy(metadata, req.Metadata)
|
|
delete(metadata, resolvedAPIKeyModelInfoMetadataKey)
|
|
delete(metadata, resolvedCodexOAuthModelInfoMetadataKey)
|
|
if ok {
|
|
metadata[metadataKey] = modelInfo
|
|
}
|
|
req.Metadata = metadata
|
|
return req
|
|
}
|
|
|
|
func lookupUnlistedCodexAPIKeyModelCapability(routing *apiKeyModelRoutingSnapshot, auth *Auth, upstreamModel string) (*registry.ModelInfo, bool) {
|
|
if routing == nil || auth == nil || auth.AuthKind() != AuthKindAPIKey || !strings.EqualFold(strings.TrimSpace(auth.Provider), "codex") || strings.TrimSpace(upstreamModel) == "" {
|
|
return nil, false
|
|
}
|
|
entry := resolveCodexAPIKeyConfig(routing.config, auth)
|
|
if entry == nil || auth.Attributes == nil {
|
|
return nil, false
|
|
}
|
|
key := strings.TrimSpace(auth.Attributes[AttributeAPIKey])
|
|
baseURL := strings.TrimSpace(auth.Attributes["base_url"])
|
|
if (key == "" && baseURL == "") || !strings.EqualFold(key, strings.TrimSpace(entry.APIKey)) ||
|
|
(strings.TrimSpace(entry.BaseURL) != "" && !strings.EqualFold(baseURL, strings.TrimSpace(entry.BaseURL))) {
|
|
return nil, false
|
|
}
|
|
for _, configured := range entry.Models {
|
|
if strings.EqualFold(strings.TrimSpace(configured.Name), strings.TrimSpace(upstreamModel)) || configuredUpstreamFallbackMatches(configured.Name, upstreamModel) {
|
|
info := modelconfig.ResolveModelInfo(upstreamModel, "codex", configured.Thinking)
|
|
info.SupportConfigurationUpdate = configured.SupportConfigurationUpdate
|
|
info.IsCompat = configured.IsCompat
|
|
return info, true
|
|
}
|
|
}
|
|
info := modelconfig.ResolveModelInfo(upstreamModel, "codex", nil)
|
|
info.SupportConfigurationUpdate = false
|
|
return info, true
|
|
}
|
|
|
|
func lookupCodexOAuthModelCapability(auth *Auth, upstreamModel string) (*registry.ModelInfo, bool) {
|
|
if auth == nil || auth.AuthKind() != AuthKindOAuth || !strings.EqualFold(strings.TrimSpace(auth.Provider), "codex") {
|
|
return nil, false
|
|
}
|
|
var models []*registry.ModelInfo
|
|
switch strings.ToLower(strings.TrimSpace(auth.Attributes["plan_type"])) {
|
|
case "plus":
|
|
models = registry.GetCodexPlusModels()
|
|
case "team", "business", "go":
|
|
models = registry.GetCodexTeamModels()
|
|
case "free":
|
|
models = registry.GetCodexFreeModels()
|
|
default:
|
|
models = registry.GetCodexProModels()
|
|
}
|
|
selected := strings.TrimSpace(thinking.ParseSuffix(strings.TrimSpace(upstreamModel)).ModelName)
|
|
for _, model := range models {
|
|
if model != nil && strings.EqualFold(model.ID, selected) {
|
|
return model, true
|
|
}
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
func attachResolvedHomeModelInfo(req cliproxyexecutor.Request, auth *Auth, routeModel string, modelInfo *registry.ModelInfo, support *bool) cliproxyexecutor.Request {
|
|
upstreamModel := req.Model
|
|
if modelInfo != nil {
|
|
upstreamModel = modelInfo.ID
|
|
}
|
|
if auth != nil {
|
|
if dispatched := strings.TrimSpace(auth.Attributes[homeUpstreamModelAttributeKey]); dispatched != "" {
|
|
upstreamModel = dispatched
|
|
}
|
|
}
|
|
options, configured := homeAPIKeyModelOptions(auth, upstreamModel, routeModel)
|
|
if modelInfo == nil && !configured {
|
|
return req
|
|
}
|
|
metadata := make(map[string]any, len(req.Metadata)+2)
|
|
maps.Copy(metadata, req.Metadata)
|
|
delete(metadata, resolvedHomeModelOptionsMetadataKey)
|
|
if configured {
|
|
metadata[resolvedHomeModelOptionsMetadataKey] = options
|
|
}
|
|
req.Metadata = metadata
|
|
if modelInfo == nil {
|
|
return req
|
|
}
|
|
selected := *modelInfo
|
|
|
|
local, ok := ResolvedAPIKeyModelInfo(req)
|
|
if !ok {
|
|
local, ok = req.Metadata[resolvedCodexOAuthModelInfoMetadataKey].(*registry.ModelInfo)
|
|
}
|
|
sameModel := ok && local != nil && strings.EqualFold(strings.TrimSpace(thinking.ParseSuffix(local.ID).ModelName), strings.TrimSpace(thinking.ParseSuffix(selected.ID).ModelName))
|
|
if support != nil {
|
|
selected.SupportConfigurationUpdate = *support
|
|
} else {
|
|
selected.SupportConfigurationUpdate = sameModel && local.SupportConfigurationUpdate
|
|
}
|
|
if configured {
|
|
selected.IsCompat = options.IsCompat
|
|
}
|
|
|
|
metadata[resolvedHomeModelInfoMetadataKey] = &selected
|
|
return req
|
|
}
|
|
|
|
func lookupAPIKeyModelCapability(routing *apiKeyModelRoutingSnapshot, auth *Auth, routeModel, upstreamModel string) (*registry.ModelInfo, bool) {
|
|
if !isConfiguredModelRoutingAuth(auth) || routing == nil {
|
|
return nil, false
|
|
}
|
|
byRoute := routing.capabilities[strings.TrimSpace(auth.ID)]
|
|
if len(byRoute) == 0 {
|
|
return nil, false
|
|
}
|
|
requestedModel := rewriteModelForAuth(strings.TrimSpace(routeModel), auth)
|
|
_, candidates := modelAliasLookupCandidates(requestedModel)
|
|
routes := make([]apiKeyModelCapabilityRoute, 0)
|
|
for _, candidate := range candidates {
|
|
routes = append(routes, byRoute[strings.ToLower(strings.TrimSpace(candidate))]...)
|
|
}
|
|
selected := strings.TrimSpace(upstreamModel)
|
|
for _, route := range routes {
|
|
if strings.EqualFold(strings.TrimSpace(route.upstreamModel), selected) {
|
|
return route.modelInfo, route.modelInfo != nil
|
|
}
|
|
}
|
|
for _, route := range routes {
|
|
if configuredUpstreamFallbackMatches(route.upstreamModel, selected) {
|
|
return route.modelInfo, route.modelInfo != nil
|
|
}
|
|
}
|
|
return nil, false
|
|
}
|
|
|
|
func configuredUpstreamFallbackMatches(configured, selected string) bool {
|
|
configuredResult := thinking.ParseSuffix(strings.TrimSpace(configured))
|
|
if configuredResult.HasSuffix {
|
|
return false
|
|
}
|
|
selectedResult := thinking.ParseSuffix(strings.TrimSpace(selected))
|
|
return strings.EqualFold(strings.TrimSpace(configuredResult.ModelName), strings.TrimSpace(selectedResult.ModelName))
|
|
}
|
|
|
|
func compileAPIKeyModelCapabilitiesForAuth(cfg *internalconfig.Config, auth *Auth) map[string][]apiKeyModelCapabilityRoute {
|
|
if cfg == nil || !isConfiguredModelRoutingAuth(auth) {
|
|
return nil
|
|
}
|
|
out := make(map[string][]apiKeyModelCapabilityRoute)
|
|
switch strings.ToLower(strings.TrimSpace(auth.Provider)) {
|
|
case "gemini":
|
|
if entry := resolveGeminiAPIKeyConfig(cfg, auth); entry != nil {
|
|
compileConfiguredModelCapabilities(out, entry.Models, "gemini")
|
|
}
|
|
case "gemini-interactions":
|
|
if entry := resolveInteractionsAPIKeyConfig(cfg, auth); entry != nil {
|
|
compileConfiguredModelCapabilities(out, entry.Models, "interactions")
|
|
}
|
|
case "claude":
|
|
if entry := resolveClaudeAPIKeyConfig(cfg, auth); entry != nil {
|
|
compileConfiguredModelCapabilities(out, entry.Models, "claude")
|
|
}
|
|
case "codex":
|
|
if entry := resolveCodexAPIKeyConfig(cfg, auth); entry != nil {
|
|
for i := range entry.Models {
|
|
configured := entry.Models[i]
|
|
info := addConfiguredModelCapability(out, configured.Name, configured.Alias, "codex", configured.Thinking, configured.IsCompat)
|
|
if info != nil {
|
|
info.SupportConfigurationUpdate = configured.SupportConfigurationUpdate
|
|
}
|
|
}
|
|
}
|
|
case "xai":
|
|
if entry := resolveXAIAPIKeyConfig(cfg, auth); entry != nil {
|
|
compileConfiguredModelCapabilities(out, entry.Models, "xai")
|
|
}
|
|
case "vertex":
|
|
if entry := resolveVertexAPIKeyConfig(cfg, auth); entry != nil {
|
|
for _, configured := range entry.Models {
|
|
support := configured.Thinking
|
|
openAPI := isVertexOpenAPIConfigModel(configured.Name)
|
|
if configured.OpenAPI != nil {
|
|
openAPI = *configured.OpenAPI
|
|
} else if entry.OpenAPI != nil {
|
|
openAPI = *entry.OpenAPI
|
|
}
|
|
if support == nil && openAPI && modelconfig.ResolveModelInfo(configured.Name, "gemini", nil).Thinking == nil {
|
|
support = ®istry.ThinkingSupport{Levels: []string{"low", "medium", "high"}}
|
|
}
|
|
addConfiguredModelCapability(out, configured.Name, configured.Alias, "gemini", support, false)
|
|
}
|
|
}
|
|
case "meta":
|
|
if entry := resolveMetaAPIKeyConfig(cfg, auth); entry != nil {
|
|
compileConfiguredModelCapabilities(out, entry.Models, "meta")
|
|
}
|
|
default:
|
|
providerKey, compatName := "", ""
|
|
if auth.Attributes != nil {
|
|
providerKey = strings.TrimSpace(auth.Attributes["provider_key"])
|
|
compatName = strings.TrimSpace(auth.Attributes["compat_name"])
|
|
}
|
|
if entry := resolveOpenAICompatConfigForAuth(cfg, auth, providerKey, compatName); entry != nil {
|
|
compileOpenAICompatibleModelCapabilities(out, entry.Models)
|
|
}
|
|
}
|
|
if len(out) == 0 {
|
|
return nil
|
|
}
|
|
return out
|
|
}
|
|
|
|
func compileConfiguredModelCapabilities[T interface {
|
|
GetName() string
|
|
GetAlias() string
|
|
GetThinking() *registry.ThinkingSupport
|
|
}](out map[string][]apiKeyModelCapabilityRoute, models []T, modelType string) {
|
|
for i := range models {
|
|
isCompat := false
|
|
if compatModel, okCompat := any(models[i]).(interface{ GetIsCompat() bool }); okCompat {
|
|
isCompat = compatModel.GetIsCompat()
|
|
}
|
|
addConfiguredModelCapability(out, models[i].GetName(), models[i].GetAlias(), modelType, models[i].GetThinking(), isCompat)
|
|
}
|
|
}
|
|
|
|
func compileOpenAICompatibleModelCapabilities(out map[string][]apiKeyModelCapabilityRoute, models []internalconfig.OpenAICompatibilityModel) {
|
|
for i := range models {
|
|
support := models[i].Thinking
|
|
if support == nil && !models[i].Image {
|
|
support = ®istry.ThinkingSupport{Levels: []string{"low", "medium", "high"}}
|
|
}
|
|
addConfiguredModelCapability(out, models[i].Name, models[i].Alias, "openai-compatibility", support, models[i].IsCompat)
|
|
}
|
|
}
|
|
|
|
func addConfiguredModelCapability(out map[string][]apiKeyModelCapabilityRoute, name, alias, modelType string, support *registry.ThinkingSupport, isCompat bool) *registry.ModelInfo {
|
|
name = strings.TrimSpace(name)
|
|
alias = strings.TrimSpace(alias)
|
|
if name == "" {
|
|
name = alias
|
|
}
|
|
if alias == "" {
|
|
alias = name
|
|
}
|
|
if name == "" {
|
|
return nil
|
|
}
|
|
modelInfo := modelconfig.ResolveModelInfo(name, modelType, support)
|
|
modelInfo.IsCompat = isCompat
|
|
route := apiKeyModelCapabilityRoute{upstreamModel: name, modelInfo: modelInfo}
|
|
seenKeys := make(map[string]struct{})
|
|
for _, routeModel := range []string{alias, name} {
|
|
_, candidates := modelAliasLookupCandidates(routeModel)
|
|
for _, candidate := range candidates {
|
|
key := strings.ToLower(strings.TrimSpace(candidate))
|
|
if key == "" {
|
|
continue
|
|
}
|
|
if _, exists := seenKeys[key]; exists {
|
|
continue
|
|
}
|
|
seenKeys[key] = struct{}{}
|
|
duplicate := false
|
|
for _, existing := range out[key] {
|
|
if strings.EqualFold(existing.upstreamModel, route.upstreamModel) {
|
|
duplicate = true
|
|
break
|
|
}
|
|
}
|
|
if !duplicate {
|
|
out[key] = append(out[key], route)
|
|
}
|
|
}
|
|
}
|
|
return modelInfo
|
|
}
|
|
|
|
// isVertexOpenAPIConfigModel recognizes partner models without depending on executors.
|
|
func isVertexOpenAPIConfigModel(model string) bool {
|
|
base := strings.TrimSpace(thinking.ParseSuffix(model).ModelName)
|
|
if strings.HasPrefix(strings.ToLower(base), "publishers/") {
|
|
publisher, tail, ok := strings.Cut(base[len("publishers/"):], "/")
|
|
if !ok || !strings.HasPrefix(strings.ToLower(tail), "models/") {
|
|
return false
|
|
}
|
|
base = strings.TrimSpace(publisher) + "/" + strings.TrimSpace(tail[len("models/"):])
|
|
}
|
|
publisher, name, ok := strings.Cut(base, "/")
|
|
publisher, name = strings.TrimSpace(publisher), strings.TrimSpace(name)
|
|
return ok && publisher != "" && name != "" && !strings.Contains(name, "/") &&
|
|
!strings.EqualFold(publisher, "google") && !strings.EqualFold(publisher, "models") && !strings.EqualFold(publisher, "publishers")
|
|
}
|