mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-14 20:41:15 +08:00
Merge branch 'feature/1.5-local-model' into 'main'
Add model information field to service information See merge request apipark/APIPark!221
This commit is contained in:
@@ -227,6 +227,7 @@ func (i *imlLocalModelController) initAILocalService(ctx context.Context, model
|
||||
ApprovalType: "auto",
|
||||
Kind: "ai",
|
||||
Provider: &providerId,
|
||||
Model: &model,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -94,7 +94,10 @@ func (i *imlServiceController) QuickCreateAIService(ctx *gin.Context, input *ser
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p, err := i.providerModule.Provider(ctx, input.Provider)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
id := uuid.NewString()
|
||||
prefix := fmt.Sprintf("/%s", id[:8])
|
||||
catalogueInfo, err := i.catalogueModule.DefaultCatalogue(ctx)
|
||||
@@ -111,6 +114,7 @@ func (i *imlServiceController) QuickCreateAIService(ctx *gin.Context, input *ser
|
||||
Catalogue: catalogueInfo.Id,
|
||||
ApprovalType: "auto",
|
||||
Provider: &input.Provider,
|
||||
Model: &p.DefaultLLM,
|
||||
Kind: "ai",
|
||||
})
|
||||
return err
|
||||
|
||||
@@ -351,6 +351,12 @@ func (i *imlInitController) createAIService(ctx context.Context, teamID string,
|
||||
if input.Id == "" {
|
||||
input.Id = uuid.New().String()
|
||||
}
|
||||
providerInfo, err := i.providerModule.Provider(ctx, *input.Provider)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
input.Model = &providerInfo.DefaultLLM
|
||||
|
||||
if input.Prefix == "" {
|
||||
if len(input.Id) < 9 {
|
||||
input.Prefix = input.Id
|
||||
|
||||
@@ -529,7 +529,7 @@ func (i *imlLocalModel) getLocalModels(ctx context.Context) ([]*gateway.DynamicR
|
||||
cfg := make(map[string]interface{})
|
||||
cfg["provider"] = "ollama"
|
||||
cfg["model"] = l.Id
|
||||
cfg["model_config"] = ai_provider_local.OllamaSvg
|
||||
cfg["model_config"] = ai_provider_local.OllamaConfig
|
||||
cfg["base"] = v
|
||||
releases = append(releases, &gateway.DynamicRelease{
|
||||
BasicItem: &gateway.BasicItem{
|
||||
|
||||
@@ -20,6 +20,7 @@ type CreateService struct {
|
||||
Kind string `json:"service_kind"`
|
||||
State string `json:"state"`
|
||||
Provider *string `json:"provider"`
|
||||
Model *string `json:"model"`
|
||||
AsApp *bool `json:"as_app"`
|
||||
AsServer *bool `json:"as_server"`
|
||||
}
|
||||
@@ -32,6 +33,7 @@ type EditService struct {
|
||||
Logo *string `json:"logo"`
|
||||
Tags *[]string `json:"tags"`
|
||||
Provider *string `json:"provider"`
|
||||
Model *string `json:"model"`
|
||||
ApprovalType *string `json:"approval_type"`
|
||||
State *string `json:"state"`
|
||||
}
|
||||
|
||||
@@ -97,7 +97,8 @@ type Service struct {
|
||||
Tags []auto.Label `json:"tags" aolabel:"tag"`
|
||||
Logo string `json:"logo"`
|
||||
Provider *auto.Label `json:"provider,omitempty" aolabel:"ai_provider"`
|
||||
ProviderType string `json:"provider_type"`
|
||||
ProviderType string `json:"provider_type,omitempty"`
|
||||
Model string `json:"model,omitempty"`
|
||||
ApprovalType string `json:"approval_type"`
|
||||
AsServer bool `json:"as_server"`
|
||||
AsApp bool `json:"as_app"`
|
||||
@@ -152,6 +153,10 @@ func ToService(model *service.Service) *Service {
|
||||
if provider.Id != "ollama" {
|
||||
s.ProviderType = "online"
|
||||
}
|
||||
modelId := model.AdditionalConfig["model"]
|
||||
if modelId != "" {
|
||||
s.Model = modelId
|
||||
}
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ai_local "github.com/APIParkLab/APIPark/service/ai-local"
|
||||
|
||||
model_runtime "github.com/APIParkLab/APIPark/ai-provider/model-runtime"
|
||||
|
||||
"github.com/eolinker/eosc/log"
|
||||
|
||||
"github.com/APIParkLab/APIPark/resources/access"
|
||||
@@ -58,6 +62,7 @@ type imlServiceModule struct {
|
||||
teamService team.ITeamService `autowired:""`
|
||||
teamMemberService team_member.ITeamMemberService `autowired:""`
|
||||
tagService tag.ITagService `autowired:""`
|
||||
localModelService ai_local.ILocalModelService `autowired:""`
|
||||
|
||||
serviceTagService service_tag.ITagService `autowired:""`
|
||||
apiService api.IAPIService `autowired:""`
|
||||
@@ -223,6 +228,25 @@ func (i *imlServiceModule) Get(ctx context.Context, id string) (*service_dto.Ser
|
||||
s.Tags = auto.List(utils.SliceToSlice(tags, func(p *service_tag.Tag) string {
|
||||
return p.Tid
|
||||
}))
|
||||
if s.Model == "" {
|
||||
switch s.ProviderType {
|
||||
case "online":
|
||||
p, has := model_runtime.GetProvider(s.Provider.Id)
|
||||
if has {
|
||||
m, has := p.DefaultModel(model_runtime.ModelTypeLLM)
|
||||
if has {
|
||||
s.Model = m.ID()
|
||||
}
|
||||
}
|
||||
case "local":
|
||||
info, err := i.localModelService.DefaultModel(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.Model = info.Id
|
||||
|
||||
}
|
||||
}
|
||||
log.Infof("get service cost %d ms", time.Since(now).Milliseconds())
|
||||
return s, nil
|
||||
}
|
||||
@@ -328,6 +352,11 @@ func (i *imlServiceModule) Create(ctx context.Context, teamID string, input *ser
|
||||
return nil, fmt.Errorf("ai service: provider can not be empty")
|
||||
}
|
||||
mo.AdditionalConfig["provider"] = *input.Provider
|
||||
if input.Model == nil {
|
||||
return nil, fmt.Errorf("ai service: model can not be empty")
|
||||
}
|
||||
mo.AdditionalConfig["model"] = *input.Model
|
||||
|
||||
}
|
||||
if input.AsApp == nil {
|
||||
// 默认值为false
|
||||
@@ -378,6 +407,9 @@ func (i *imlServiceModule) Edit(ctx context.Context, id string, input *service_d
|
||||
if input.Provider != nil {
|
||||
info.AdditionalConfig["provider"] = *input.Provider
|
||||
}
|
||||
if input.Model != nil {
|
||||
info.AdditionalConfig["model"] = *input.Model
|
||||
}
|
||||
|
||||
}
|
||||
err = i.transaction.Transaction(ctx, func(ctx context.Context) error {
|
||||
|
||||
@@ -20,6 +20,14 @@ type imlLocalModelService struct {
|
||||
universally.IServiceDelete
|
||||
}
|
||||
|
||||
func (i *imlLocalModelService) DefaultModel(ctx context.Context) (*LocalModel, error) {
|
||||
info, err := i.store.First(ctx, map[string]interface{}{"state": 1})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return i.fromEntity(info), nil
|
||||
}
|
||||
|
||||
func (i *imlLocalModelService) OnComplete() {
|
||||
i.IServiceGet = universally.NewGet[LocalModel, ai.LocalModel](i.store, i.fromEntity)
|
||||
i.IServiceCreate = universally.NewCreator[CreateLocalModel, ai.LocalModel](i.store, "ai_local_model", i.createEntityHandler, i.uniquestHandler, i.labelHandler)
|
||||
|
||||
@@ -13,6 +13,7 @@ type ILocalModelService interface {
|
||||
universally.IServiceCreate[CreateLocalModel]
|
||||
universally.IServiceEdit[EditLocalModel]
|
||||
universally.IServiceDelete
|
||||
DefaultModel(ctx context.Context) (*LocalModel, error)
|
||||
}
|
||||
|
||||
type ILocalModelPackageService interface {
|
||||
|
||||
Reference in New Issue
Block a user