This commit is contained in:
maggieyyy
2024-10-21 14:20:25 +08:00
24 changed files with 788 additions and 203 deletions
+3 -2
View File
@@ -24,8 +24,9 @@ type AiPromptVariable struct {
}
type AiModel struct {
Id string `json:"id"`
Config string `json:"config"`
Id string `json:"id"`
Config string `json:"config"`
Provider string `json:"provider"`
}
type EditAPI struct {
+7
View File
@@ -26,6 +26,7 @@ type APIItem struct {
Updater auto.Label `json:"updater" aolabel:"user"`
CreateTime auto.TimeLabel `json:"create_time"`
UpdateTime auto.TimeLabel `json:"update_time"`
Provider ProviderItem `json:"provider"`
Model ModelItem `json:"model"`
}
@@ -33,3 +34,9 @@ type ModelItem struct {
Id string `json:"id"`
Logo string `json:"logo"`
}
type ProviderItem struct {
Id string `json:"id"`
Name string `json:"name"`
Logo string `json:"logo"`
}
+27 -13
View File
@@ -9,6 +9,7 @@ import (
"strings"
model_runtime "github.com/APIParkLab/APIPark/ai-provider/model-runtime"
ai_api_dto "github.com/APIParkLab/APIPark/module/ai-api/dto"
ai_api "github.com/APIParkLab/APIPark/service/ai-api"
"github.com/APIParkLab/APIPark/service/api"
@@ -203,19 +204,8 @@ func (i *imlAPIModule) List(ctx context.Context, keyword string, serviceId strin
if err != nil {
return nil, err
}
p, has := model_runtime.GetProvider(info.AdditionalConfig["provider"])
if !has {
return nil, fmt.Errorf("provider not found")
}
return utils.SliceToSlice(apis, func(t *ai_api.API) *ai_api_dto.APIItem {
modelItem := ai_api_dto.ModelItem{
Id: t.Model,
}
model, has := p.DefaultModel(t.Model)
if has {
modelItem.Logo = model.Logo()
}
return &ai_api_dto.APIItem{
item := &ai_api_dto.APIItem{
Id: t.ID,
Name: t.Name,
RequestPath: t.Path,
@@ -225,8 +215,32 @@ func (i *imlAPIModule) List(ctx context.Context, keyword string, serviceId strin
Updater: auto.UUID(t.Updater),
CreateTime: auto.TimeLabel(t.CreateAt),
UpdateTime: auto.TimeLabel(t.UpdateAt),
Model: modelItem,
}
aiModel, err := ConvertStruct[ai_api_dto.AiModel](t.AdditionalConfig["ai_model"])
if err != nil {
return item
}
p, has := model_runtime.GetProvider(aiModel.Provider)
if has {
item.Provider = ai_api_dto.ProviderItem{
Id: p.ID(),
Name: p.Name(),
Logo: p.Logo(),
}
m, has := p.GetModel(t.Model)
if has {
item.Model = ai_api_dto.ModelItem{
Id: m.ID(),
Logo: m.Logo(),
}
}
} else {
item.Model = ai_api_dto.ModelItem{
Id: aiModel.Id,
}
}
return item
}), nil
}
+2 -1
View File
@@ -398,7 +398,8 @@ func (i *imlProviderModule) initGateway(ctx context.Context, clusterId string, c
func (i *imlProviderModule) syncGateway(ctx context.Context, clusterId string, releases []*gateway.DynamicRelease, online bool) error {
client, err := i.clusterService.GatewayClient(ctx, clusterId)
if err != nil {
return err
log.Errorf("get apinto client error: %v", err)
return nil
}
defer func() {
err := client.Close(ctx)
+16 -10
View File
@@ -2,16 +2,18 @@ package cluster
import (
"context"
"github.com/APIParkLab/APIPark/service/setting"
cluster_dto "github.com/APIParkLab/APIPark/module/cluster/dto"
"github.com/APIParkLab/APIPark/gateway/admin"
"github.com/eolinker/eosc/log"
"github.com/eolinker/go-common/store"
"github.com/APIParkLab/APIPark/gateway"
"github.com/APIParkLab/APIPark/service/cluster"
"github.com/eolinker/ap-account/service/account"
"github.com/eolinker/go-common/utils"
@@ -23,6 +25,7 @@ var (
type imlClusterModule struct {
clusterService cluster.IClusterService `autowired:""`
settingService setting.ISettingService `autowired:""`
userNameService account.IAccountService `autowired:""`
transaction store.ITransaction `autowired:""`
}
@@ -42,12 +45,12 @@ func (m *imlClusterModule) CheckCluster(ctx context.Context, address ...string)
}
})
nodeStatus(ctx, nodesOut)
return nodesOut, nil
}
func (m *imlClusterModule) ResetCluster(ctx context.Context, clusterId string, address string) ([]*cluster_dto.Node, error) {
nodes, err := m.clusterService.UpdateAddress(ctx, clusterId, address)
if err != nil {
return nil, err
@@ -65,7 +68,10 @@ func (m *imlClusterModule) ResetCluster(ctx context.Context, clusterId string, a
Gateways: i.Server,
}
})
v, has := m.settingService.Get(ctx, setting.KeyInvokeAddress)
if (!has || v == "") && len(nodesOut) > 0 && len(nodesOut[0].Gateways) > 0 {
m.settingService.Set(ctx, setting.KeyInvokeAddress, nodesOut[0].Gateways[0], utils.UserId(ctx))
}
nodeStatus(ctx, nodesOut)
return nodesOut, nil
}
@@ -83,7 +89,7 @@ func (m *imlClusterModule) initGateway(ctx context.Context, clusterId string) er
return gateway.InitGateway(ctx, clusterId, client)
}
func (m *imlClusterModule) ClusterNodes(ctx context.Context, clusterId string) ([]*cluster_dto.Node, error) {
nodes, err := m.clusterService.Nodes(ctx)
if err != nil {
return nil, err
@@ -98,7 +104,7 @@ func (m *imlClusterModule) ClusterNodes(ctx context.Context, clusterId string) (
}
})
nodeStatus(ctx, nodesOut)
return nodesOut, nil
}
+1
View File
@@ -24,6 +24,7 @@ type IServiceModule interface {
Edit(ctx context.Context, id string, input *service_dto.EditService) (*service_dto.Service, error)
// Delete 删除项目
Delete(ctx context.Context, id string) error
// Simple 获取简易项目列表
//Simple(ctx context.Context, keyword string) ([]*service_dto.SimpleServiceItem, error)
-16
View File
@@ -161,19 +161,3 @@ func (m *imlTeamModule) Delete(ctx context.Context, id string) error {
})
return err
}
func (m *imlTeamModule) OnInit() {
ctx := context.Background()
list, err := m.service.List(ctx)
if err != nil {
return
}
if len(list) == 0 {
teamId := uuid.New().String()
err = m.service.Create(ctx, &team.CreateTeam{
Id: teamId,
Name: "Default Team",
Description: "Auto create default team",
})
}
}