fix: ai deploy bug

This commit is contained in:
Liujian
2025-02-17 00:37:25 +08:00
parent 0dabe4d0e5
commit 7243684977
14 changed files with 227 additions and 44 deletions
+8
View File
@@ -23,6 +23,14 @@ type imlAPIService struct {
universally.IServiceDelete
}
func (i *imlAPIService) DeleteByService(ctx context.Context, serviceId string) error {
_, err := i.store.DeleteWhere(ctx, map[string]interface{}{"service": serviceId})
if err != nil {
return nil
}
return err
}
func (i *imlAPIService) CountMapByModel(ctx context.Context, keyword string, conditions map[string]interface{}) (map[string]int64, error) {
return i.store.CountByGroup(ctx, keyword, conditions, "model")
}
+1
View File
@@ -15,6 +15,7 @@ type IAPIService interface {
universally.IServiceDelete
CountMapByProvider(ctx context.Context, keyword string, conditions map[string]interface{}) (map[string]int64, error)
CountMapByModel(ctx context.Context, keyword string, conditions map[string]interface{}) (map[string]int64, error)
DeleteByService(ctx context.Context, serviceId string) error
}
type IAPIUseService interface {
+39
View File
@@ -1,8 +1,11 @@
package ai_local
import (
"context"
"time"
"github.com/eolinker/go-common/utils"
"github.com/APIParkLab/APIPark/service/universally"
"github.com/APIParkLab/APIPark/stores/ai"
)
@@ -187,3 +190,39 @@ func (i *imlLocalModelInstallStateService) updateHandler(e *ai.LocalModelInstall
}
e.UpdateAt = time.Now()
}
var _ ILocalModelCacheService = &imlLocalModelCacheService{}
type imlLocalModelCacheService struct {
store ai.ILocalModelCacheStore `autowired:""`
}
func (i *imlLocalModelCacheService) List(ctx context.Context, model string, typ CacheType) ([]*LocalModelCache, error) {
list, err := i.store.List(ctx, map[string]interface{}{"model": model, "type": typ.Int()})
if err != nil {
return nil, err
}
return utils.SliceToSlice(list, func(s *ai.LocalModelCache) *LocalModelCache {
return &LocalModelCache{
Model: s.Model,
Target: s.Target,
Type: CacheType(s.Type),
}
}), nil
}
func (i *imlLocalModelCacheService) Delete(ctx context.Context, model string) error {
_, err := i.store.DeleteWhere(ctx, map[string]interface{}{"model": model})
if err != nil {
return err
}
return nil
}
func (i *imlLocalModelCacheService) Save(ctx context.Context, model string, typ CacheType, target string) error {
return i.store.Insert(ctx, &ai.LocalModelCache{
Model: model,
Target: target,
Type: typ.Int(),
})
}
+34
View File
@@ -75,3 +75,37 @@ type EditLocalModelInstallState struct {
State *int
Msg *string
}
type LocalModelCache struct {
Model string
Target string
Type CacheType
}
type CacheType string
func (c CacheType) String() string {
return string(c)
}
func (c CacheType) Int() int {
switch c {
case CacheTypeService:
return 0
default:
return 0
}
}
func FromCacheType(s int) CacheType {
switch s {
case 0:
return CacheTypeService
default:
return CacheTypeService
}
}
const (
CacheTypeService CacheType = "service"
)
+11
View File
@@ -1,6 +1,7 @@
package ai_local
import (
"context"
"reflect"
"github.com/APIParkLab/APIPark/service/universally"
@@ -28,6 +29,12 @@ type ILocalModelInstallStateService interface {
universally.IServiceDelete
}
type ILocalModelCacheService interface {
List(ctx context.Context, model string, typ CacheType) ([]*LocalModelCache, error)
Delete(ctx context.Context, model string) error
Save(ctx context.Context, model string, typ CacheType, target string) error
}
func init() {
autowire.Auto[ILocalModelService](func() reflect.Value {
return reflect.ValueOf(new(imlLocalModelService))
@@ -39,4 +46,8 @@ func init() {
autowire.Auto[ILocalModelInstallStateService](func() reflect.Value {
return reflect.ValueOf(new(imlLocalModelInstallStateService))
})
autowire.Auto[ILocalModelCacheService](func() reflect.Value {
return reflect.ValueOf(new(imlLocalModelCacheService))
})
}
+7
View File
@@ -41,6 +41,13 @@ type imlAPIService struct {
universally.IServiceDelete
}
func (i *imlAPIService) DeleteByService(ctx context.Context, serviceId string) error {
_, err := i.store.DeleteWhere(ctx, map[string]interface{}{
"service": serviceId,
})
return err
}
func (i *imlAPIService) ListForServices(ctx context.Context, serviceIds ...string) ([]*API, error) {
w := map[string]interface{}{}
if len(serviceIds) > 0 {
+1
View File
@@ -43,6 +43,7 @@ type IAPIService interface {
Save(ctx context.Context, id string, model *Edit) error
Create(ctx context.Context, input *Create) (err error)
DeleteByService(ctx context.Context, serviceId string) error
}
var (