mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-19 16:17:56 +00:00
Manage free Fast through group lifecycle
This commit is contained in:
@@ -303,6 +303,7 @@ func sanitizeGroupOpenAIFast(group *Group) {
|
||||
if group == nil || !groupSupportsOpenAIFast(group.Platform) {
|
||||
if group != nil {
|
||||
group.ForceOpenAIFast = false
|
||||
group.FreeOpenAIFast = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -513,6 +514,7 @@ func (s *adminServiceImpl) CreateGroup(ctx context.Context, input *CreateGroupIn
|
||||
AllowMessagesDispatch: input.AllowMessagesDispatch,
|
||||
AllowLive: input.AllowLive,
|
||||
ForceOpenAIFast: input.ForceOpenAIFast,
|
||||
FreeOpenAIFast: input.FreeOpenAIFast,
|
||||
RequireOAuthOnly: input.RequireOAuthOnly,
|
||||
RequirePrivacySet: input.RequirePrivacySet,
|
||||
DefaultMappedModel: input.DefaultMappedModel,
|
||||
@@ -879,6 +881,9 @@ func (s *adminServiceImpl) UpdateGroup(ctx context.Context, id int64, input *Upd
|
||||
if input.ForceOpenAIFast != nil {
|
||||
group.ForceOpenAIFast = *input.ForceOpenAIFast
|
||||
}
|
||||
if input.FreeOpenAIFast != nil {
|
||||
group.FreeOpenAIFast = *input.FreeOpenAIFast
|
||||
}
|
||||
if input.RequireOAuthOnly != nil {
|
||||
group.RequireOAuthOnly = *input.RequireOAuthOnly
|
||||
}
|
||||
|
||||
@@ -267,6 +267,7 @@ type CreateGroupInput struct {
|
||||
AllowMessagesDispatch bool
|
||||
AllowLive bool
|
||||
ForceOpenAIFast bool
|
||||
FreeOpenAIFast bool
|
||||
DefaultMappedModel string
|
||||
RequireOAuthOnly bool
|
||||
RequirePrivacySet bool
|
||||
@@ -343,6 +344,7 @@ type UpdateGroupInput struct {
|
||||
AllowMessagesDispatch *bool
|
||||
AllowLive *bool
|
||||
ForceOpenAIFast *bool
|
||||
FreeOpenAIFast *bool
|
||||
DefaultMappedModel *string
|
||||
RequireOAuthOnly *bool
|
||||
RequirePrivacySet *bool
|
||||
|
||||
@@ -1097,19 +1097,20 @@ func TestAdminService_CreateGroup_NormalizesForceOpenAIFastByPlatform(t *testing
|
||||
svc := &adminServiceImpl{groupRepo: repo}
|
||||
|
||||
group, err := svc.CreateGroup(context.Background(), &CreateGroupInput{
|
||||
Name: "fast-" + tt.name, Platform: tt.platform, RateMultiplier: 1, ForceOpenAIFast: true,
|
||||
Name: "fast-" + tt.name, Platform: tt.platform, RateMultiplier: 1, ForceOpenAIFast: true, FreeOpenAIFast: true,
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, group)
|
||||
require.Equal(t, tt.want, repo.created.ForceOpenAIFast)
|
||||
require.Equal(t, tt.want, repo.created.FreeOpenAIFast)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdminService_UpdateGroup_ClearsForceOpenAIFastWhenPlatformChanges(t *testing.T) {
|
||||
existingGroup := &Group{
|
||||
ID: 1, Name: "existing-fast", Platform: PlatformOpenAI, Status: StatusActive, ForceOpenAIFast: true,
|
||||
ID: 1, Name: "existing-fast", Platform: PlatformOpenAI, Status: StatusActive, ForceOpenAIFast: true, FreeOpenAIFast: true,
|
||||
}
|
||||
repo := &groupRepoStubForAdmin{getByID: existingGroup}
|
||||
svc := &adminServiceImpl{groupRepo: repo}
|
||||
@@ -1121,6 +1122,7 @@ func TestAdminService_UpdateGroup_ClearsForceOpenAIFastWhenPlatformChanges(t *te
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, group)
|
||||
require.False(t, repo.updated.ForceOpenAIFast)
|
||||
require.False(t, repo.updated.FreeOpenAIFast)
|
||||
}
|
||||
|
||||
func TestAdminService_UpdateGroup_ForceOpenAIFastInvalidatesAuthCache(t *testing.T) {
|
||||
@@ -1134,11 +1136,13 @@ func TestAdminService_UpdateGroup_ForceOpenAIFastInvalidatesAuthCache(t *testing
|
||||
|
||||
group, err := svc.UpdateGroup(context.Background(), existingGroup.ID, &UpdateGroupInput{
|
||||
ForceOpenAIFast: &enabled,
|
||||
FreeOpenAIFast: &enabled,
|
||||
})
|
||||
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, group)
|
||||
require.True(t, repo.updated.ForceOpenAIFast)
|
||||
require.True(t, repo.updated.FreeOpenAIFast)
|
||||
require.Equal(t, []int64{existingGroup.ID}, invalidator.groupIDs)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user