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

Method getLocalModels

module/ai-local/iml.go:608–665  ·  view source on GitHub ↗
(ctx context.Context, v string)

Source from the content-addressed store, hash-verified

606}
607
608func (i *imlLocalModel) getLocalModels(ctx context.Context, v string) ([]*gateway.DynamicRelease, error) {
609 list, err := i.localModelService.List(ctx)
610 if err != nil {
611 return nil, err
612 }
613 if v == "" {
614 var has bool
615 v, has = i.settingService.Get(ctx, "system.ai_model.ollama_address")
616 if !has {
617 //return nil, errors.New("ollama_address not set")
618 return nil, nil
619 }
620 }
621 provider := ai_provider_local.ProviderLocal
622 releases := make([]*gateway.DynamicRelease, 0, len(list))
623 for _, l := range list {
624 if l.State != ai_local_dto.LocalModelStateNormal.Int() {
625 continue
626 }
627 cfg := make(map[string]interface{})
628 cfg["provider"] = provider
629 cfg["model"] = l.Id
630 cfg["model_config"] = ai_provider_local.LocalConfig
631 cfg["base"] = v
632 releases = append(releases, &gateway.DynamicRelease{
633 BasicItem: &gateway.BasicItem{
634 ID: l.Id,
635 Description: l.Name,
636 Resource: "ai-provider",
637 Version: l.UpdateAt.Format("20060102150405"),
638 MatchLabels: map[string]string{
639 "module": "ai-provider",
640 },
641 },
642 Attr: cfg,
643 })
644 }
645 releases = append(releases, &gateway.DynamicRelease{
646 BasicItem: &gateway.BasicItem{
647 ID: fmt.Sprintf("%s-key", ai_provider_local.ProviderLocal),
648 Description: "auto generate key",
649 Resource: "ai-key",
650 Version: time.Now().Format("20060102150405"),
651 MatchLabels: map[string]string{
652 "module": "ai-key",
653 },
654 },
655 Attr: map[string]interface{}{
656 "expired": 0,
657 "config": fmt.Sprintf("{\"base\":\"%s\"}", v),
658 "provider": provider,
659 "priority": 1,
660 "disabled": true,
661 },
662 })
663
664 return releases, nil
665}

Callers 2

SyncLocalModelsMethod · 0.95
initGatewayMethod · 0.95

Calls 3

ListMethod · 0.65
GetMethod · 0.65
IntMethod · 0.45

Tested by

no test coverage detected