Skip to content

Commit 7eca309

Browse files
authored
Merge pull request #257 from APIParkLab/feature/1.6-liujian
Feature/1.6 liujian
2 parents 31abd60 + 4143088 commit 7eca309

9 files changed

Lines changed: 53 additions & 26 deletions

File tree

Lines changed: 1 addition & 11 deletions
Loading
Lines changed: 1 addition & 4 deletions
Loading

ai-provider/model-runtime/model-providers/ollama/assets/icon_l_en.svg

Lines changed: 9 additions & 1 deletion
Loading

ai-provider/model-runtime/model-providers/ollama/assets/icon_s_en.svg

Lines changed: 9 additions & 1 deletion
Loading

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-balance/iml.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,8 @@ func (i *imlBalanceModule) Delete(ctx context.Context, id string) error {
220220
return i.syncGateway(ctx, cluster.DefaultClusterID, []*gateway.DynamicRelease{
221221
{
222222
BasicItem: &gateway.BasicItem{
223-
ID: id,
223+
ID: id,
224+
Resource: "ai-provider",
224225
},
225226
},
226227
}, false)

module/ai-key/iml.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,12 @@ func (i *imlKeyModule) UpdateKeyStatus(ctx context.Context, providerId string, i
383383
}
384384
releases := []*gateway.DynamicRelease{{
385385
BasicItem: &gateway.BasicItem{
386-
ID: id,
386+
ID: fmt.Sprintf("%s-%s", providerId, id),
387387
Resource: "ai-key",
388388
},
389389
Attr: nil,
390390
}}
391-
return i.syncGateway(ctx, providerId, releases, false)
391+
return i.syncGateway(ctx, cluster.DefaultClusterID, releases, false)
392392
}
393393
if info.Status == ai_key_dto.KeyDisable.Int() || info.Status == ai_key_dto.KeyExceed.Int() {
394394
// 超额 或 停用状态,可启用
@@ -411,7 +411,7 @@ func (i *imlKeyModule) UpdateKeyStatus(ctx context.Context, providerId string, i
411411
return err
412412
}
413413
releases := []*gateway.DynamicRelease{newKey(info)}
414-
return i.syncGateway(ctx, providerId, releases, true)
414+
return i.syncGateway(ctx, cluster.DefaultClusterID, releases, true)
415415
}
416416
return nil
417417
})

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

service/ai-api/model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func FromEntity(e *api.AiAPIInfo) *API {
7676
Updater: e.Updater,
7777
Disable: e.Disable,
7878
UseToken: e.UseToken,
79+
Provider: e.Provider,
7980
Type: e.Type,
8081
AdditionalConfig: cfg,
8182
}

0 commit comments

Comments
 (0)