Skip to content

Commit d8cb4a0

Browse files
committed
fix:ai init bug
1 parent 2eb2e69 commit d8cb4a0

File tree

1 file changed

+42
-39
lines changed

1 file changed

+42
-39
lines changed

module/ai/iml.go

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import (
77
"net/http"
88
"sort"
99
"time"
10-
10+
1111
"github.com/APIParkLab/APIPark/service/service"
12-
12+
1313
ai_key_dto "github.com/APIParkLab/APIPark/module/ai-key/dto"
14-
14+
1515
ai_key "github.com/APIParkLab/APIPark/service/ai-key"
16-
16+
1717
"github.com/eolinker/go-common/auto"
18-
18+
1919
ai_api "github.com/APIParkLab/APIPark/service/ai-api"
20-
20+
2121
model_runtime "github.com/APIParkLab/APIPark/ai-provider/model-runtime"
2222
"github.com/APIParkLab/APIPark/gateway"
2323
ai_dto "github.com/APIParkLab/APIPark/module/ai/dto"
@@ -30,7 +30,7 @@ import (
3030
)
3131

3232
func newKey(key *ai_key.Key) *gateway.DynamicRelease {
33-
33+
3434
return &gateway.DynamicRelease{
3535
BasicItem: &gateway.BasicItem{
3636
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
9191
if !has {
9292
continue
9393
}
94-
94+
9595
l, has := providerMap[id]
9696
if !has {
9797
continue
@@ -139,7 +139,7 @@ func (i *imlProviderModule) Sort(ctx context.Context, input *ai_dto.Sort) error
139139
return err
140140
}
141141
return i.syncGateway(ctx, cluster.DefaultClusterID, offlineReleases, false)
142-
142+
143143
})
144144
}
145145

@@ -176,7 +176,7 @@ func (i *imlProviderModule) ConfiguredProviders(ctx context.Context) ([]*ai_dto.
176176
return nil, nil, fmt.Errorf("create default key error:%v", err)
177177
}
178178
}
179-
179+
180180
p, has := model_runtime.GetProvider(l.Id)
181181
if !has {
182182
continue
@@ -185,7 +185,7 @@ func (i *imlProviderModule) ConfiguredProviders(ctx context.Context) ([]*ai_dto.
185185
if err != nil {
186186
return nil, nil, fmt.Errorf("get provider keys error:%v", err)
187187
}
188-
188+
189189
keysStatus := make([]*ai_dto.KeyStatus, 0, len(keys))
190190
for _, k := range keys {
191191
status := ai_key_dto.ToKeyStatus(k.Status)
@@ -204,7 +204,7 @@ func (i *imlProviderModule) ConfiguredProviders(ctx context.Context) ([]*ai_dto.
204204
sort.Slice(keysStatus, func(i, j int) bool {
205205
return keysStatus[i].Priority < keysStatus[j].Priority
206206
})
207-
207+
208208
providers = append(providers, &ai_dto.ConfiguredProviderItem{
209209
Id: l.Id,
210210
Name: l.Name,
@@ -248,7 +248,7 @@ func (i *imlProviderModule) SimpleProviders(ctx context.Context) ([]*ai_dto.Simp
248248
return nil, err
249249
}
250250
providers := model_runtime.Providers()
251-
251+
252252
providerMap := utils.SliceToMap(list, func(e *ai.Provider) string {
253253
return e.Id
254254
})
@@ -315,7 +315,7 @@ func (i *imlProviderModule) SimpleConfiguredProviders(ctx context.Context) ([]*a
315315
Name: model.ID(),
316316
},
317317
}
318-
318+
319319
items = append(items, item)
320320
}
321321
sort.Slice(items, func(i, j int) bool {
@@ -426,7 +426,7 @@ func (i *imlProviderModule) Provider(ctx context.Context, id string) (*ai_dto.Pr
426426
if info.Priority == 0 {
427427
info.Priority = maxPriority
428428
}
429-
429+
430430
return &ai_dto.Provider{
431431
Id: info.Id,
432432
Name: info.Name,
@@ -445,12 +445,12 @@ func (i *imlProviderModule) LLMs(ctx context.Context, driver string) ([]*ai_dto.
445445
if !has {
446446
return nil, nil, fmt.Errorf("ai provider not found")
447447
}
448-
448+
449449
llms, has := p.ModelsByType(model_runtime.ModelTypeLLM)
450450
if !has {
451451
return nil, nil, fmt.Errorf("ai provider not found")
452452
}
453-
453+
454454
items := make([]*ai_dto.LLMItem, 0, len(llms))
455455
for _, v := range llms {
456456
items = append(items, &ai_dto.LLMItem{
@@ -478,7 +478,7 @@ func (i *imlProviderModule) LLMs(ctx context.Context, driver string) ([]*ai_dto.
478478
Logo: p.Logo(),
479479
}, nil
480480
}
481-
481+
482482
return items, &ai_dto.ProviderItem{
483483
Id: info.Id,
484484
Name: info.Name,
@@ -558,19 +558,19 @@ func (i *imlProviderModule) UpdateProviderConfig(ctx context.Context, id string,
558558
if err != nil {
559559
return err
560560
}
561-
562-
if input.Enable != nil {
563-
status = 0
564-
if *input.Enable {
565-
status = 1
566-
}
567-
pInfo.Status = &status
568-
}
561+
562+
//if input.Enable != nil {
563+
// status = 0
564+
// if *input.Enable {
565+
// status = 1
566+
// }
567+
// pInfo.Status = &status
568+
//}
569569
err = i.providerService.Save(ctx, id, pInfo)
570570
if err != nil {
571571
return err
572572
}
573-
573+
574574
if *pInfo.Status == 0 {
575575
return i.syncGateway(ctx, cluster.DefaultClusterID, []*gateway.DynamicRelease{
576576
{
@@ -614,11 +614,11 @@ func (i *imlProviderModule) getAiProviders(ctx context.Context) ([]*gateway.Dyna
614614
if err != nil {
615615
return nil, err
616616
}
617-
617+
618618
providers := make([]*gateway.DynamicRelease, 0, len(list))
619619
for _, l := range list {
620620
// 获取当前供应商所有Key信息
621-
621+
622622
driver, has := model_runtime.GetProvider(l.Id)
623623
if !has {
624624
return nil, fmt.Errorf("provider not found: %s", l.Id)
@@ -653,7 +653,7 @@ func (i *imlProviderModule) initGateway(ctx context.Context, clusterId string, c
653653
if err != nil {
654654
return err
655655
}
656-
656+
657657
for _, p := range providers {
658658
client, err := clientDriver.Dynamic(p.Resource)
659659
if err != nil {
@@ -664,7 +664,7 @@ func (i *imlProviderModule) initGateway(ctx context.Context, clusterId string, c
664664
return err
665665
}
666666
}
667-
667+
668668
return nil
669669
}
670670

@@ -694,7 +694,7 @@ func (i *imlProviderModule) syncGateway(ctx context.Context, clusterId string, r
694694
return err
695695
}
696696
}
697-
697+
698698
return nil
699699
}
700700

@@ -727,9 +727,9 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st
727727
Name: s.Name,
728728
})
729729
serviceTeamMap[s.Id] = s.Team
730-
730+
731731
}
732-
732+
733733
modelItems := utils.SliceToSlice(p.Models(), func(e model_runtime.IModel) *ai_dto.BasicInfo {
734734
return &ai_dto.BasicInfo{
735735
Id: e.ID(),
@@ -752,7 +752,7 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st
752752
if err != nil {
753753
return nil, nil, 0, err
754754
}
755-
755+
756756
if len(apis) <= 0 {
757757
return nil, condition, 0, nil
758758
}
@@ -767,10 +767,10 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st
767767
if err != nil {
768768
return nil, nil, 0, err
769769
}
770-
770+
771771
apiItems := utils.SliceToSlice(results, func(e *ai_api.APIUse) *ai_dto.APIItem {
772772
info := apiMap[e.API]
773-
773+
774774
delete(apiMap, e.API)
775775
return &ai_dto.APIItem{
776776
Id: e.API,
@@ -814,5 +814,8 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st
814814
for i := offset; i < offset+size && i < len(sortApis); i++ {
815815
apiItems = append(apiItems, sortApis[i])
816816
}
817-
818-
total := int64(len(apis))
817+
818+
total := int64(len(apis))
819+
return apiItems, condition, total, nil
820+
}
821+
}

0 commit comments

Comments
 (0)