Skip to content

Commit 4143088

Browse files
committed
Fix the issue of local model data synchronization errors
1 parent 7333e4f commit 4143088

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

controller/service/iml.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ func (i *imlServiceController) createAIService(ctx *gin.Context, teamID string,
354354
if !has {
355355
return nil, fmt.Errorf("model %s not found", pv.DefaultLLM)
356356
}
357-
modelId = m.ID()
357+
//modelId = m.ID()
358+
modelId = m.Name()
358359
modelCfg = m.DefaultConfig()
359360

360361
}

module/ai-local/iml.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"time"
78

89
ai_balance "github.com/APIParkLab/APIPark/service/ai-balance"
910

@@ -60,6 +61,7 @@ func (i *imlLocalModel) SyncLocalModels(ctx context.Context, address string) err
6061
if err != nil {
6162
return err
6263
}
64+
6365
return i.syncGateway(ctx, cluster.DefaultClusterID, releases, true)
6466
}
6567

@@ -246,7 +248,7 @@ func (i *imlLocalModel) pullHook(fn ...func() error) func(msg ai_provider_local.
246248
v, _ := i.settingService.Get(ctx, "system.ai_model.ollama_address")
247249

248250
cfg := make(map[string]interface{})
249-
cfg["provider"] = "ollama"
251+
cfg["provider"] = ai_provider_local.ProviderLocal
250252
cfg["model"] = msg.Model
251253
cfg["model_config"] = ai_provider_local.LocalConfig
252254
cfg["priority"] = 0
@@ -448,7 +450,7 @@ func (i *imlLocalModel) Enable(ctx context.Context, model string) error {
448450
}
449451
v, _ := i.settingService.Get(ctx, "system.ai_model.ollama_address")
450452
cfg := make(map[string]interface{})
451-
cfg["provider"] = "ollama"
453+
cfg["provider"] = ai_provider_local.ProviderLocal
452454
cfg["model"] = info.Id
453455
cfg["model_config"] = ai_provider_local.LocalConfig
454456
cfg["priority"] = 0
@@ -615,14 +617,14 @@ func (i *imlLocalModel) getLocalModels(ctx context.Context, v string) ([]*gatewa
615617
return nil, errors.New("ollama_address not set")
616618
}
617619
}
618-
620+
provider := ai_provider_local.ProviderLocal
619621
releases := make([]*gateway.DynamicRelease, 0, len(list))
620622
for _, l := range list {
621623
if l.State != ai_local_dto.LocalModelStateNormal.Int() {
622624
continue
623625
}
624626
cfg := make(map[string]interface{})
625-
cfg["provider"] = "ollama"
627+
cfg["provider"] = provider
626628
cfg["model"] = l.Id
627629
cfg["model_config"] = ai_provider_local.LocalConfig
628630
cfg["base"] = v
@@ -639,6 +641,25 @@ func (i *imlLocalModel) getLocalModels(ctx context.Context, v string) ([]*gatewa
639641
Attr: cfg,
640642
})
641643
}
644+
releases = append(releases, &gateway.DynamicRelease{
645+
BasicItem: &gateway.BasicItem{
646+
ID: fmt.Sprintf("%s-key", ai_provider_local.ProviderLocal),
647+
Description: "auto generate key",
648+
Resource: "ai-key",
649+
Version: time.Now().Format("20060102150405"),
650+
MatchLabels: map[string]string{
651+
"module": "ai-key",
652+
},
653+
},
654+
Attr: map[string]interface{}{
655+
"expired": 0,
656+
"config": fmt.Sprintf("{\"base\":\"%s\"}", v),
657+
"provider": provider,
658+
"priority": 1,
659+
"disabled": true,
660+
},
661+
})
662+
642663
return releases, nil
643664
}
644665

0 commit comments

Comments
 (0)