mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-29 16:20:27 +00:00
fix(openai): retain capabilities when model listing is unavailable
This commit is contained in:
@@ -208,6 +208,7 @@ func (s *AccountTestService) FetchUpstreamSupportedModels(ctx context.Context, a
|
||||
// untouched.
|
||||
func (s *AccountTestService) SyncUpstreamModelCatalog(ctx context.Context, account *Account) (*UpstreamModelCatalog, error) {
|
||||
models, body, err := s.fetchUpstreamModelList(ctx, account)
|
||||
liveListAvailable := err == nil
|
||||
if err != nil {
|
||||
configuredModels := configuredUpstreamModelsForCapabilitySync(account)
|
||||
if !upstreamModelListEndpointUnsupported(err) || len(configuredModels) == 0 {
|
||||
@@ -264,7 +265,14 @@ func (s *AccountTestService) SyncUpstreamModelCatalog(ctx context.Context, accou
|
||||
if len(completeMetadata) > 0 && account != nil && account.ID > 0 && s.accountRepo != nil {
|
||||
// Retain known metadata only for models still listed or explicitly mapped.
|
||||
if previous := account.GetUpstreamModelMetadataSnapshot(); previous != nil {
|
||||
for _, modelID := range capabilityIDs {
|
||||
retainedModels := capabilityIDs
|
||||
if !liveListAvailable {
|
||||
retainedModels = append([]string(nil), capabilityIDs...)
|
||||
for modelID := range previous.Models {
|
||||
retainedModels = append(retainedModels, modelID)
|
||||
}
|
||||
}
|
||||
for _, modelID := range retainedModels {
|
||||
old, exists := previous.Models[modelID]
|
||||
if !exists {
|
||||
continue
|
||||
|
||||
@@ -545,8 +545,12 @@ func TestSyncUpstreamModelCatalogUsesConfiguredModelsWhenListEndpointUnsupported
|
||||
},
|
||||
}
|
||||
|
||||
account.SetUpstreamModelMetadataSnapshot(UpstreamModelMetadataSnapshot{Models: map[string]UpstreamModelMetadata{
|
||||
"old-live-model": {ID: "old-live-model", ContextWindow: 256000},
|
||||
}})
|
||||
catalog, err := svc.SyncUpstreamModelCatalog(context.Background(), account)
|
||||
require.NoError(t, err)
|
||||
require.Contains(t, account.GetUpstreamModelMetadataSnapshot().Models, "old-live-model", "an unavailable model-list endpoint is not evidence of removal")
|
||||
require.Equal(t, []string{"glm-5.3"}, catalog.Models)
|
||||
require.Empty(t, catalog.Warnings)
|
||||
require.Len(t, upstream.requests, 2)
|
||||
|
||||
Reference in New Issue
Block a user