(ctx context.Context, keyword string, providerId string, start int64, end int64, page int, pageSize int, sortCondition string, asc bool, models []string, serviceIds []string)
| 801 | } |
| 802 | |
| 803 | func (i *imlAIApiModule) APIs(ctx context.Context, keyword string, providerId string, start int64, end int64, page int, pageSize int, sortCondition string, asc bool, models []string, serviceIds []string) ([]*ai_dto.APIItem, *ai_dto.Condition, int64, error) { |
| 804 | modelItems := make([]*ai_dto.BasicInfo, 0) |
| 805 | if providerId == ai_provider_local.ProviderLocal { |
| 806 | items, err := i.aiLocalModelService.Search(ctx, "", nil, "update_at desc") |
| 807 | if err != nil { |
| 808 | return nil, nil, 0, err |
| 809 | } |
| 810 | modelItems = utils.SliceToSlice(items, func(e *ai_local.LocalModel) *ai_dto.BasicInfo { |
| 811 | return &ai_dto.BasicInfo{ |
| 812 | Id: e.Id, |
| 813 | Name: e.Name, |
| 814 | } |
| 815 | }) |
| 816 | } else { |
| 817 | p, has := model_runtime.GetProvider(providerId) |
| 818 | if !has { |
| 819 | return nil, nil, 0, fmt.Errorf("ai provider not found") |
| 820 | } |
| 821 | modelItems = utils.SliceToSlice(p.Models(), func(e model_runtime.IModel) *ai_dto.BasicInfo { |
| 822 | return &ai_dto.BasicInfo{ |
| 823 | Id: e.ID(), |
| 824 | Name: e.ID(), |
| 825 | } |
| 826 | }) |
| 827 | } |
| 828 | |
| 829 | sortRule := "desc" |
| 830 | if asc { |
| 831 | sortRule = "asc" |
| 832 | } |
| 833 | services, err := i.serviceService.ServiceListByKind(ctx, service.AIService) |
| 834 | if err != nil { |
| 835 | return nil, nil, 0, err |
| 836 | } |
| 837 | serviceItems := make([]*ai_dto.BasicInfo, 0, len(services)) |
| 838 | serviceTeamMap := make(map[string]string) |
| 839 | for _, s := range services { |
| 840 | serviceItems = append(serviceItems, &ai_dto.BasicInfo{ |
| 841 | Id: s.Id, |
| 842 | Name: s.Name, |
| 843 | }) |
| 844 | serviceTeamMap[s.Id] = s.Team |
| 845 | |
| 846 | } |
| 847 | |
| 848 | condition := &ai_dto.Condition{Services: serviceItems, Models: modelItems} |
| 849 | switch sortCondition { |
| 850 | default: |
| 851 | w := map[string]interface{}{ |
| 852 | "provider": providerId, |
| 853 | } |
| 854 | if len(models) > 0 { |
| 855 | w["model"] = models |
| 856 | } |
| 857 | if len(serviceIds) > 0 { |
| 858 | w["service"] = serviceIds |
| 859 | } |
| 860 | apis, err := i.aiAPIService.Search(ctx, keyword, w, "update_at desc") |
nothing calls this directly
no test coverage detected