Merge pull request #409 from APIParkLab/feature/liujian-1.9

fix bug
This commit is contained in:
Dot.L
2025-10-26 22:28:24 +08:00
committed by GitHub
3 changed files with 65 additions and 49 deletions
+5 -1
View File
@@ -113,9 +113,13 @@ func (i *imlAPIController) Edit(ctx *gin.Context, serviceId string, apiId string
if input.AiModel.Type != "local" {
provider = input.AiModel.Provider
}
modelName := input.AiModel.Name
if modelName == "" {
modelName = input.AiModel.Id
}
proxy.Plugins["ai_formatter"] = api.PluginSetting{
Config: plugin_model.ConfigType{
"model": input.AiModel.Name,
"model": modelName,
"provider": provider,
"config": input.AiModel.Config,
},
+16 -10
View File
@@ -520,16 +520,21 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string,
modelId := ""
modelCfg := ""
modelType := "online"
if input.Model != nil {
modelId = *input.Model
}
if *input.Provider == ai_provider_local.ProviderLocal {
modelType = "local"
list, err := i.aiLocalModel.SimpleList(ctx)
if err != nil {
return nil, err
if modelId == "" {
list, err := i.aiLocalModel.SimpleList(ctx)
if err != nil {
return nil, err
}
if len(list) == 0 {
return nil, fmt.Errorf("no local model")
}
modelId = list[0].Id
}
if len(list) == 0 {
return nil, fmt.Errorf("no local model")
}
modelId = list[0].Id
modelCfg = ai_provider_local.LocalConfig
} else {
pv, err := i.providerModule.Provider(ctx, *input.Provider)
@@ -540,14 +545,15 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string,
if !has {
return nil, fmt.Errorf("provider not found")
}
m, has := p.GetModel(pv.DefaultLLM)
if modelId == "" {
modelId = pv.DefaultLLM
}
m, has := p.GetModel(modelId)
if !has {
return nil, fmt.Errorf("model %s not found", pv.DefaultLLM)
}
//modelId = m.ID()
modelId = m.Name()
modelCfg = m.DefaultConfig()
}
var info *service_dto.Service
+44 -38
View File
@@ -219,19 +219,19 @@ func (i *imlAuthorizationModule) initGateway(ctx context.Context, partitionId st
return clientDriver.Application().Online(ctx, applications...)
}
func (i *imlAuthorizationModule) online(ctx context.Context, s *service.Service) error {
clusters, err := i.clusterService.List(ctx)
if err != nil {
return err
}
if len(clusters) < 1 {
return nil
}
func (i *imlAuthorizationModule) getApplicationRelease(ctx context.Context, s *service.Service) (*gateway.ApplicationRelease, error) {
authorizations, err := i.authorizationService.ListByApp(ctx, s.Id)
if err != nil {
return err
return nil, err
}
app := &gateway.ApplicationRelease{
if len(authorizations) < 1 {
return &gateway.ApplicationRelease{
BasicItem: &gateway.BasicItem{
ID: s.Id,
},
}, nil
}
return &gateway.ApplicationRelease{
BasicItem: &gateway.BasicItem{
ID: s.Id,
Description: s.Description,
@@ -256,10 +256,40 @@ func (i *imlAuthorizationModule) online(ctx context.Context, s *service.Service)
},
}
}),
}, nil
}
func (i *imlAuthorizationModule) doOffline(ctx context.Context, clusterId string, app *gateway.ApplicationRelease) error {
client, err := i.clusterService.GatewayClient(ctx, clusterId)
if err != nil {
return err
}
defer func() {
_ = client.Close(ctx)
}()
return client.Application().Offline(ctx, app)
}
func (i *imlAuthorizationModule) online(ctx context.Context, s *service.Service) error {
clusters, err := i.clusterService.List(ctx)
if err != nil {
return err
}
if len(clusters) < 1 {
return nil
}
release, err := i.getApplicationRelease(ctx, s)
if err != nil {
return err
}
for _, c := range clusters {
err := i.doOnline(ctx, c.Uuid, app)
if len(release.Authorizations) < 1 {
err = i.doOffline(ctx, c.Uuid, release)
if err != nil {
log.Warnf("service authorization offline for cluster[%s] %v", c.Name, err)
}
continue
}
err = i.doOnline(ctx, c.Uuid, release)
if err != nil {
log.Warnf("service authorization online for cluster[%s] %v", c.Name, err)
}
@@ -375,7 +405,7 @@ func (i *imlAuthorizationModule) EditAuthorization(ctx context.Context, appId st
}
func (i *imlAuthorizationModule) DeleteAuthorization(ctx context.Context, pid string, aid string) error {
_, err := i.serviceService.Get(ctx, pid)
s, err := i.serviceService.Get(ctx, pid)
if err != nil {
return err
}
@@ -385,35 +415,11 @@ func (i *imlAuthorizationModule) DeleteAuthorization(ctx context.Context, pid st
if err != nil {
return err
}
clusters, err := i.clusterService.List(ctx)
if err != nil {
return err
}
app := &gateway.ApplicationRelease{
BasicItem: &gateway.BasicItem{
ID: pid,
},
}
for _, c := range clusters {
err := i.doOffline(ctx, c.Uuid, app)
if err != nil {
log.Warnf("service authorization offline for cluster[%s] %v", c.Name, err)
}
}
return nil
return i.online(ctx, s)
})
}
func (i *imlAuthorizationModule) doOffline(ctx context.Context, clusterId string, app *gateway.ApplicationRelease) error {
client, err := i.clusterService.GatewayClient(ctx, clusterId)
if err != nil {
return err
}
defer func() {
_ = client.Close(ctx)
}()
return client.Application().Offline(ctx, app)
}
func (i *imlAuthorizationModule) Authorizations(ctx context.Context, pid string) ([]*application_authorization_dto.AuthorizationItem, error) {
_, err := i.serviceService.Get(ctx, pid)
if err != nil {