(ctx context.Context, keyword string)
| 173 | } |
| 174 | |
| 175 | func (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 | |
| 214 | func (i *imlBalanceModule) Delete(ctx context.Context, id string) error { |
| 215 | return i.transaction.Transaction(ctx, func(ctx context.Context) error { |
nothing calls this directly
no test coverage detected