diff --git a/module/ai/iml.go b/module/ai/iml.go index 85074453..5d639c32 100644 --- a/module/ai/iml.go +++ b/module/ai/iml.go @@ -69,12 +69,11 @@ func (i *imlProviderModule) Providers(ctx context.Context) ([]*ai_dto.ProviderIt DefaultLLM: v.Info().DefaultLLM, } if info, has := providerMap[v.Info().Id]; has { - //item.Enable = info.Status err = v.GlobalConfig().CheckConfig(info.Config) if err == nil { item.Configured = true } - + item.DefaultLLM = info.DefaultLLM } items = append(items, item) } @@ -126,10 +125,20 @@ func (i *imlProviderModule) LLMs(ctx context.Context, driver string) ([]*ai_dto. } info, err := i.providerService.Get(ctx, driver) if err != nil { - return items, nil, err + if !errors.Is(err, gorm.ErrRecordNotFound) { + return nil, nil, err + } + + return items, &ai_dto.ProviderItem{ + Id: p.Info().Id, + Name: p.Info().Name, + DefaultLLM: p.Info().DefaultLLM, + Logo: p.Info().Logo, + Configured: false, + }, err } - return items, &ai_dto.ProviderItem{Id: info.Id, Name: info.Name, Logo: p.Info().Logo, Configured: true}, nil + return items, &ai_dto.ProviderItem{Id: info.Id, Name: info.Name, DefaultLLM: info.DefaultLLM, Logo: p.Info().Logo, Configured: true}, nil } func (i *imlProviderModule) UpdateProviderStatus(ctx context.Context, id string, enable bool) error { diff --git a/plugins/core/service.go b/plugins/core/service.go index 85541d42..2d460486 100644 --- a/plugins/core/service.go +++ b/plugins/core/service.go @@ -21,9 +21,9 @@ func (p *plugin) ServiceApis() []pm3.Api { // AI服务 pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/ai-services", []string{"context", "query:service", "query:keyword"}, []string{"service"}, p.serviceController.SearchAIServices), - pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/team/ai-service", []string{"context", "query:service", "body"}, []string{"service"}, p.serviceController.Create), + pm3.CreateApiWidthDoc(http.MethodPost, "/api/v1/team/ai-service", []string{"context", "query:team", "body"}, []string{"service"}, p.serviceController.CreateAIService), pm3.CreateApiWidthDoc(http.MethodPut, "/api/v1/ai-service/info", []string{"context", "query:service", "body"}, []string{"service"}, p.serviceController.Edit), - pm3.CreateApiWidthDoc(http.MethodDelete, "/api/v1/ai-service", []string{"context", "query:service"}, nil, p.serviceController.Delete), + pm3.CreateApiWidthDoc(http.MethodDelete, "/api/v1/ai-service", []string{"context", "query:service"}, nil, p.serviceController.DeleteAIService), pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/my_ai_services", []string{"context", "query:team", "query:keyword"}, []string{"services"}, p.serviceController.SearchMyAIServices), pm3.CreateApiWidthDoc(http.MethodGet, "/api/v1/ai-service/info", []string{"context", "query:service"}, []string{"services"}, p.serviceController.Get), diff --git a/service/ai/iml.go b/service/ai/iml.go index 6312e3c6..2eea283f 100644 --- a/service/ai/iml.go +++ b/service/ai/iml.go @@ -27,15 +27,19 @@ func (i *imlProviderService) Save(ctx context.Context, id string, cfg *SetProvid if !errors.Is(err, gorm.ErrRecordNotFound) { return err } - if cfg.Name == nil || cfg.Config == nil || cfg.DefaultLLM == nil || cfg.Status == nil { + if cfg.Name == nil || cfg.Config == nil || cfg.DefaultLLM == nil { return errors.New("invalid params") } + status := false + if cfg.Status != nil { + status = *cfg.Status + } info = &ai.Provider{ UUID: id, Name: *cfg.Name, DefaultLLM: *cfg.DefaultLLM, Config: base64.RawStdEncoding.EncodeToString([]byte(*cfg.Config)), - Status: *cfg.Status, + Status: status, Creator: userId, Updater: userId, CreateAt: now, diff --git a/service/service/iml.go b/service/service/iml.go index 70e8eaf7..41470885 100644 --- a/service/service/iml.go +++ b/service/service/iml.go @@ -146,22 +146,24 @@ func uniquestHandler(i *Create) []map[string]interface{} { return []map[string]interface{}{{"uuid": i.Id}} } func createEntityHandler(i *Create) *service.Service { + cfg, _ := json.Marshal(i.AdditionalConfig) now := time.Now() return &service.Service{ - Id: 0, - UUID: i.Id, - Name: i.Name, - CreateAt: now, - UpdateAt: now, - Description: i.Description, - Logo: i.Logo, - Prefix: i.Prefix, - Team: i.Team, - ServiceType: i.ServiceType.Int(), - Kind: i.Kind.Int(), - Catalogue: i.Catalogue, - AsServer: i.AsServer, - AsApp: i.AsApp, + Id: 0, + UUID: i.Id, + Name: i.Name, + CreateAt: now, + UpdateAt: now, + Description: i.Description, + Logo: i.Logo, + Prefix: i.Prefix, + Team: i.Team, + ServiceType: i.ServiceType.Int(), + Kind: i.Kind.Int(), + AdditionalConfig: string(cfg), + Catalogue: i.Catalogue, + AsServer: i.AsServer, + AsApp: i.AsApp, } } func updateHandler(e *service.Service, i *Edit) {