MCPcopy Create free account
hub / github.com/APIParkLab/APIPark / List

Method List

module/ai-api/iml.go:234–301  ·  view source on GitHub ↗
(ctx context.Context, keyword string, serviceId string)

Source from the content-addressed store, hash-verified

232}
233
234func (i *imlAPIModule) List(ctx context.Context, keyword string, serviceId string) ([]*ai_api_dto.APIItem, error) {
235 info, err := i.serviceService.Get(ctx, serviceId)
236 if err != nil {
237 return nil, err
238 }
239 if info.Kind != service.AIService {
240 return nil, fmt.Errorf("service kind is not ai service")
241 }
242 apis, err := i.aiAPIService.Search(ctx, keyword, map[string]interface{}{
243 "service": serviceId,
244 }, "update_at desc")
245 if err != nil {
246 return nil, err
247 }
248 return utils.SliceToSlice(apis, func(t *ai_api.API) *ai_api_dto.APIItem {
249 item := &ai_api_dto.APIItem{
250 Id: t.ID,
251 Name: t.Name,
252 RequestPath: t.Path,
253 Description: t.Description,
254 Disable: t.Disable,
255 Creator: auto.UUID(t.Creator),
256 Updater: auto.UUID(t.Updater),
257 CreateTime: auto.TimeLabel(t.CreateAt),
258 UpdateTime: auto.TimeLabel(t.UpdateAt),
259 }
260 aiModel, err := ConvertStruct[ai_api_dto.AiModel](t.AdditionalConfig["ai_model"])
261 if err != nil {
262 return item
263 }
264 item.ModelType = ai_api_dto.ModelType(aiModel.Type)
265 if item.ModelType == ai_api_dto.ModelTypeLocal {
266 item.Model = ai_api_dto.ModelItem{
267 Id: aiModel.Id,
268 Name: aiModel.Id,
269 }
270 item.Provider = ai_api_dto.ProviderItem{
271 Id: ai_provider_local.ProviderLocal,
272 Name: ai_provider_local.ProviderLocal,
273 Logo: "",
274 }
275 } else {
276 p, has := model_runtime.GetProvider(aiModel.Provider)
277 if has {
278 item.Provider = ai_api_dto.ProviderItem{
279 Id: p.ID(),
280 Name: p.Name(),
281 Logo: "",
282 }
283 m, has := p.GetModel(t.Model)
284 if has {
285 item.Model = ai_api_dto.ModelItem{
286 Id: m.ID(),
287 Name: m.Name(),
288 Logo: "",
289 }
290 }
291 } else {

Callers

nothing calls this directly

Calls 6

GetMethod · 0.65
SearchMethod · 0.65
ModelTypeMethod · 0.65
IDMethod · 0.65
NameMethod · 0.65
GetModelMethod · 0.65

Tested by

no test coverage detected