Files
sub2api/backend/internal/service/openai_gateway_model_availability.go
T
shaw f93a6c50ce fix: repair CI build & lint regressions on main
- openai_gateway_model_availability.go: pass platform through to
  listSchedulableAccounts so OpenAI/Grok diagnosis scopes to the
  correct candidate pool (build break introduced by Grok subscription
  PR #3310).
- no_account_error.go: drop redundant context.Context type on
  ctx := context.Background() to satisfy staticcheck ST1023.
2026-06-26 16:06:01 +08:00

52 lines
1.8 KiB
Go

package service
import (
"context"
"strings"
)
// DiagnoseModelAvailabilityForPlatform reports whether the requested model
// is configured to be served by any OpenAI-compatible account in the group
// for the given platform (e.g. PlatformOpenAI, PlatformGrok). The platform
// scopes the candidate pool so distinct OpenAI-compatible platforms do not
// cross-contaminate diagnosis results.
//
// Safe to call on the error path: returns {true,true} on any internal
// failure or when the inputs preclude meaningful diagnosis (empty model,
// nil service), so callers stay on the 503 fallback branch.
func (s *OpenAIGatewayService) DiagnoseModelAvailabilityForPlatform(
ctx context.Context,
groupID *int64,
requestedModel string,
platform string,
) ModelAvailabilityDiagnosis {
if s == nil {
return ModelAvailabilityDiagnosis{HasAccountsInPool: true, HasModelSupport: true}
}
requestedModel = strings.TrimSpace(requestedModel)
if requestedModel == "" {
return ModelAvailabilityDiagnosis{HasAccountsInPool: true, HasModelSupport: true}
}
accounts, err := s.listSchedulableAccounts(ctx, groupID, platform)
if err != nil {
// Conservative fallback so the caller keeps returning 503; we do not
// want a transient lookup failure to flip into 404 model_not_found.
return ModelAvailabilityDiagnosis{HasAccountsInPool: true, HasModelSupport: true}
}
diag := ModelAvailabilityDiagnosis{}
for i := range accounts {
diag.HasAccountsInPool = true
// Mirrors the per-candidate filter used during account selection
// (openai_account_scheduler.isAccountRequestCompatible): empty
// model_mapping accepts everything; otherwise the explicit / wildcard
// mapping must match.
if accounts[i].IsModelSupported(requestedModel) {
diag.HasModelSupport = true
return diag
}
}
return diag
}