@@ -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
3232func 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 ,
@@ -533,6 +533,7 @@ func (i *imlProviderModule) UpdateProviderConfig(ctx context.Context, id string,
533533 DefaultLLM : & input .DefaultLLM ,
534534 Config : & input .Config ,
535535 Priority : input .Priority ,
536+ Status : & status ,
536537 }
537538 _ , err = i .aiKeyService .DefaultKey (ctx , id )
538539 if err != nil {
@@ -557,7 +558,7 @@ func (i *imlProviderModule) UpdateProviderConfig(ctx context.Context, id string,
557558 if err != nil {
558559 return err
559560 }
560-
561+
561562 if input .Enable != nil {
562563 status = 0
563564 if * input .Enable {
@@ -569,6 +570,7 @@ func (i *imlProviderModule) UpdateProviderConfig(ctx context.Context, id string,
569570 if err != nil {
570571 return err
571572 }
573+
572574 if * pInfo .Status == 0 {
573575 return i .syncGateway (ctx , cluster .DefaultClusterID , []* gateway.DynamicRelease {
574576 {
@@ -612,11 +614,11 @@ func (i *imlProviderModule) getAiProviders(ctx context.Context) ([]*gateway.Dyna
612614 if err != nil {
613615 return nil , err
614616 }
615-
617+
616618 providers := make ([]* gateway.DynamicRelease , 0 , len (list ))
617619 for _ , l := range list {
618620 // 获取当前供应商所有Key信息
619-
621+
620622 driver , has := model_runtime .GetProvider (l .Id )
621623 if ! has {
622624 return nil , fmt .Errorf ("provider not found: %s" , l .Id )
@@ -651,7 +653,7 @@ func (i *imlProviderModule) initGateway(ctx context.Context, clusterId string, c
651653 if err != nil {
652654 return err
653655 }
654-
656+
655657 for _ , p := range providers {
656658 client , err := clientDriver .Dynamic (p .Resource )
657659 if err != nil {
@@ -662,7 +664,7 @@ func (i *imlProviderModule) initGateway(ctx context.Context, clusterId string, c
662664 return err
663665 }
664666 }
665-
667+
666668 return nil
667669}
668670
@@ -692,7 +694,7 @@ func (i *imlProviderModule) syncGateway(ctx context.Context, clusterId string, r
692694 return err
693695 }
694696 }
695-
697+
696698 return nil
697699}
698700
@@ -725,9 +727,9 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st
725727 Name : s .Name ,
726728 })
727729 serviceTeamMap [s .Id ] = s .Team
728-
730+
729731 }
730-
732+
731733 modelItems := utils .SliceToSlice (p .Models (), func (e model_runtime.IModel ) * ai_dto.BasicInfo {
732734 return & ai_dto.BasicInfo {
733735 Id : e .ID (),
@@ -750,7 +752,7 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st
750752 if err != nil {
751753 return nil , nil , 0 , err
752754 }
753-
755+
754756 if len (apis ) <= 0 {
755757 return nil , condition , 0 , nil
756758 }
@@ -765,10 +767,10 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st
765767 if err != nil {
766768 return nil , nil , 0 , err
767769 }
768-
770+
769771 apiItems := utils .SliceToSlice (results , func (e * ai_api.APIUse ) * ai_dto.APIItem {
770772 info := apiMap [e .API ]
771-
773+
772774 delete (apiMap , e .API )
773775 return & ai_dto.APIItem {
774776 Id : e .API ,
@@ -812,8 +814,5 @@ func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId st
812814 for i := offset ; i < offset + size && i < len (sortApis ); i ++ {
813815 apiItems = append (apiItems , sortApis [i ])
814816 }
815-
816- total := int64 (len (apis ))
817- return apiItems , condition , total , nil
818- }
819- }
817+
818+ total := int64 (len (apis ))
0 commit comments