MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / List

Method List

module/ai-balance/iml.go:175–212  ·  view source on GitHub ↗
(ctx context.Context, keyword string)

Source from the content-addressed store, hash-verified

173}
174
175func (i *imlBalanceModule) List(ctx context.Context, keyword string) ([]*ai_balance_dto.Item, error) {
176 list, err := i.balanceService.Search(ctx, keyword, nil, "priority asc")
177 if err != nil {
178 return nil, err
179 }
180 sort.Slice(list, func(i, j int) bool {
181 return list[i].Priority < list[j].Priority
182 })
183 aiAPIMap, err := i.aiAPIService.CountMapByModel(ctx, "", nil)
184 if err != nil {
185 return nil, fmt.Errorf("get ai api count error:%v", err)
186 }
187 keyMap, err := i.aiKeyService.CountMapByProvider(ctx, "", nil)
188 if err != nil {
189 return nil, fmt.Errorf("get ai key count error:%v", err)
190 }
191 result := make([]*ai_balance_dto.Item, 0, len(list))
192 for i, item := range list {
193 priority := i + 1
194 result = append(result, &ai_balance_dto.Item{
195 Id: item.Id,
196 Provider: &ai_balance_dto.BasicItem{
197 Id: item.Provider,
198 Name: item.ProviderName,
199 },
200 Model: &ai_balance_dto.BasicItem{
201 Id: item.Model,
202 Name: item.ModelName,
203 },
204 Priority: priority,
205 Type: ai_balance_dto.ModelTypeFromInt(item.Type),
206 State: ai_balance_dto.ModelStateFromInt(item.State),
207 APICount: aiAPIMap[item.Model],
208 KeyCount: keyMap[item.Provider],
209 })
210 }
211 return result, nil
212}
213
214func (i *imlBalanceModule) Delete(ctx context.Context, id string) error {
215 return i.transaction.Transaction(ctx, func(ctx context.Context) error {

Callers

nothing calls this directly

Calls 3

SearchMethod · 0.65
CountMapByModelMethod · 0.65
CountMapByProviderMethod · 0.65

Tested by

no test coverage detected