From 070882655db3623152b5766ba853c3532f503fce Mon Sep 17 00:00:00 2001 From: Liujian <824010343@qq.com> Date: Mon, 20 Jan 2025 13:54:58 +0800 Subject: [PATCH] update ai bug --- module/ai/iml.go | 67 ++++++++++++++--------------- stores/api/model.go | 2 +- stores/universally/commit/commit.go | 2 +- 3 files changed, 35 insertions(+), 36 deletions(-) diff --git a/module/ai/iml.go b/module/ai/iml.go index 0e4b9a50..427155b1 100644 --- a/module/ai/iml.go +++ b/module/ai/iml.go @@ -7,17 +7,17 @@ import ( "net/http" "sort" "time" - + "github.com/APIParkLab/APIPark/service/service" - + ai_key_dto "github.com/APIParkLab/APIPark/module/ai-key/dto" - + ai_key "github.com/APIParkLab/APIPark/service/ai-key" - + "github.com/eolinker/go-common/auto" - + ai_api "github.com/APIParkLab/APIPark/service/ai-api" - + model_runtime "github.com/APIParkLab/APIPark/ai-provider/model-runtime" "github.com/APIParkLab/APIPark/gateway" ai_dto "github.com/APIParkLab/APIPark/module/ai/dto" @@ -30,7 +30,7 @@ import ( ) func newKey(key *ai_key.Key) *gateway.DynamicRelease { - + return &gateway.DynamicRelease{ BasicItem: &gateway.BasicItem{ ID: fmt.Sprintf("%s-%s", key.Provider, key.ID), @@ -91,7 +91,7 @@ func (i *imlProviderModule) Sort(ctx context.Context, input *ai_dto.Sort) error if !has { continue } - + l, has := providerMap[id] if !has { continue @@ -139,7 +139,7 @@ func (i *imlProviderModule) Sort(ctx context.Context, input *ai_dto.Sort) error return err } return i.syncGateway(ctx, cluster.DefaultClusterID, offlineReleases, false) - + }) } @@ -176,7 +176,7 @@ func (i *imlProviderModule) ConfiguredProviders(ctx context.Context) ([]*ai_dto. return nil, nil, fmt.Errorf("create default key error:%v", err) } } - + p, has := model_runtime.GetProvider(l.Id) if !has { continue @@ -185,7 +185,7 @@ func (i *imlProviderModule) ConfiguredProviders(ctx context.Context) ([]*ai_dto. if err != nil { return nil, nil, fmt.Errorf("get provider keys error:%v", err) } - + keysStatus := make([]*ai_dto.KeyStatus, 0, len(keys)) for _, k := range keys { status := ai_key_dto.ToKeyStatus(k.Status) @@ -204,7 +204,7 @@ func (i *imlProviderModule) ConfiguredProviders(ctx context.Context) ([]*ai_dto. sort.Slice(keysStatus, func(i, j int) bool { return keysStatus[i].Priority < keysStatus[j].Priority }) - + providers = append(providers, &ai_dto.ConfiguredProviderItem{ Id: l.Id, Name: l.Name, @@ -248,7 +248,7 @@ func (i *imlProviderModule) SimpleProviders(ctx context.Context) ([]*ai_dto.Simp return nil, err } providers := model_runtime.Providers() - + providerMap := utils.SliceToMap(list, func(e *ai.Provider) string { return e.Id }) @@ -315,7 +315,7 @@ func (i *imlProviderModule) SimpleConfiguredProviders(ctx context.Context) ([]*a Name: model.ID(), }, } - + items = append(items, item) } sort.Slice(items, func(i, j int) bool { @@ -426,7 +426,7 @@ func (i *imlProviderModule) Provider(ctx context.Context, id string) (*ai_dto.Pr if info.Priority == 0 { info.Priority = maxPriority } - + return &ai_dto.Provider{ Id: info.Id, Name: info.Name, @@ -445,12 +445,12 @@ func (i *imlProviderModule) LLMs(ctx context.Context, driver string) ([]*ai_dto. if !has { return nil, nil, fmt.Errorf("ai provider not found") } - + llms, has := p.ModelsByType(model_runtime.ModelTypeLLM) if !has { return nil, nil, fmt.Errorf("ai provider not found") } - + items := make([]*ai_dto.LLMItem, 0, len(llms)) for _, v := range llms { items = append(items, &ai_dto.LLMItem{ @@ -478,7 +478,7 @@ func (i *imlProviderModule) LLMs(ctx context.Context, driver string) ([]*ai_dto. Logo: p.Logo(), }, nil } - + return items, &ai_dto.ProviderItem{ Id: info.Id, Name: info.Name, @@ -533,6 +533,7 @@ func (i *imlProviderModule) UpdateProviderConfig(ctx context.Context, id string, DefaultLLM: &input.DefaultLLM, Config: &input.Config, Priority: input.Priority, + Status: &status, } _, err = i.aiKeyService.DefaultKey(ctx, id) if err != nil { @@ -557,7 +558,7 @@ func (i *imlProviderModule) UpdateProviderConfig(ctx context.Context, id string, if err != nil { return err } - + if input.Enable != nil { status = 0 if *input.Enable { @@ -569,6 +570,7 @@ func (i *imlProviderModule) UpdateProviderConfig(ctx context.Context, id string, if err != nil { return err } + if *pInfo.Status == 0 { return i.syncGateway(ctx, cluster.DefaultClusterID, []*gateway.DynamicRelease{ { @@ -612,11 +614,11 @@ func (i *imlProviderModule) getAiProviders(ctx context.Context) ([]*gateway.Dyna if err != nil { return nil, err } - + providers := make([]*gateway.DynamicRelease, 0, len(list)) for _, l := range list { // 获取当前供应商所有Key信息 - + driver, has := model_runtime.GetProvider(l.Id) if !has { return nil, fmt.Errorf("provider not found: %s", l.Id) @@ -651,7 +653,7 @@ func (i *imlProviderModule) initGateway(ctx context.Context, clusterId string, c if err != nil { return err } - + for _, p := range providers { client, err := clientDriver.Dynamic(p.Resource) if err != nil { @@ -662,7 +664,7 @@ func (i *imlProviderModule) initGateway(ctx context.Context, clusterId string, c return err } } - + return nil } @@ -692,7 +694,7 @@ func (i *imlProviderModule) syncGateway(ctx context.Context, clusterId string, r return err } } - + return nil } @@ -725,9 +727,9 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st Name: s.Name, }) serviceTeamMap[s.Id] = s.Team - + } - + modelItems := utils.SliceToSlice(p.Models(), func(e model_runtime.IModel) *ai_dto.BasicInfo { return &ai_dto.BasicInfo{ Id: e.ID(), @@ -750,7 +752,7 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st if err != nil { return nil, nil, 0, err } - + if len(apis) <= 0 { return nil, condition, 0, nil } @@ -765,10 +767,10 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st if err != nil { return nil, nil, 0, err } - + apiItems := utils.SliceToSlice(results, func(e *ai_api.APIUse) *ai_dto.APIItem { info := apiMap[e.API] - + delete(apiMap, e.API) return &ai_dto.APIItem{ Id: e.API, @@ -812,8 +814,5 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st for i := offset; i < offset+size && i < len(sortApis); i++ { apiItems = append(apiItems, sortApis[i]) } - - total := int64(len(apis)) - return apiItems, condition, total, nil - } -} + + total := int64(len(apis)) \ No newline at end of file diff --git a/stores/api/model.go b/stores/api/model.go index 1cfb6106..d530cf3f 100644 --- a/stores/api/model.go +++ b/stores/api/model.go @@ -55,7 +55,7 @@ type Doc struct { Id int64 `gorm:"column:id;type:BIGINT(20);AUTO_INCREMENT;NOT NULL;comment:id;primary_key;comment:主键ID;"` UUID string `gorm:"type:varchar(36);not null;column:uuid;uniqueIndex:uuid;comment:UUID;"` Service string `gorm:"size:36;not null;column:service;comment:服务;index:service"` - Content string `gorm:"type:text;null;column:content;comment:文档内容"` + Content string `gorm:"type:longtext;null;column:content;comment:文档内容"` Updater string `gorm:"size:36;not null;column:updater;comment:更新人;index:updater" aovalue:"updater"` UpdateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:update_at;comment:更新时间"` APICount int64 `gorm:"type:int(11);not null;column:api_count;comment:接口数量"` diff --git a/stores/universally/commit/commit.go b/stores/universally/commit/commit.go index d6850960..700fb722 100644 --- a/stores/universally/commit/commit.go +++ b/stores/universally/commit/commit.go @@ -7,7 +7,7 @@ type Commit[H any] struct { UUID string `gorm:"size:36;not null;column:uuid;comment:uuid;uniqueIndex:uuid;"` Target string `gorm:"column:target;type:varchar(36);NOT NULL;comment:目标id;index:target;"` Key string `gorm:"size:50;not null;column:key;comment:类型;index:key;"` - Data *H `gorm:"type:text;not null;column:data;comment:数据;charset=utf8mb4;serializer:json"` + Data *H `gorm:"type:longtext;not null;column:data;comment:数据;charset=utf8mb4;serializer:json"` CreateAt time.Time `gorm:"type:timestamp;NOT NULL;DEFAULT:CURRENT_TIMESTAMP;column:create_at;comment:创建时间"` Operator string `gorm:"size:36;not null;column:operator;comment:操作人;index:operator;"` }