Merge branch 'feature/1.5-local-model' into 'main'

Feature/1.5 local model

See merge request apipark/APIPark!197
This commit is contained in:
刘健
2025-02-16 21:51:20 +08:00
3 changed files with 7 additions and 98 deletions
-97
View File
@@ -92,18 +92,6 @@ func (i *imlServiceController) QuickCreateAIService(ctx *gin.Context, input *ser
if err != nil {
return err
}
//pv, err := i.providerModule.Provider(ctx, input.Provider)
//if err != nil {
// return err
//}
//p, has := model_runtime.GetProvider(input.Provider)
//if !has {
// return fmt.Errorf("provider not found")
//}
//m, has := p.GetModel(pv.DefaultLLM)
//if !has {
// return fmt.Errorf("model %s not found", pv.DefaultLLM)
//}
id := uuid.NewString()
prefix := fmt.Sprintf("/%s", id[:8])
@@ -124,91 +112,6 @@ func (i *imlServiceController) QuickCreateAIService(ctx *gin.Context, input *ser
Kind: "ai",
})
return err
//info, err = i.module.Create(ctx, input.Team, &service_dto.CreateService{
// Id: uuid.NewString(),
// Name: input.Provider + " AI Service",
// Prefix: prefix,
// Description: "Quick create by AI provider",
// ServiceType: "public",
// State: "normal",
// Catalogue: catalogueInfo.Id,
// ApprovalType: "auto",
// Provider: &input.Provider,
// Kind: "ai",
//})
//if err != nil {
// return err
//}
//
//path := fmt.Sprintf("%s/chat", prefix)
//timeout := 300000
//retry := 0
//aiPrompt := &ai_api_dto.AiPrompt{
// Variables: []*ai_api_dto.AiPromptVariable{},
// Prompt: "",
//}
//aiModel := &ai_api_dto.AiModel{
// Id: m.ID(),
// Config: m.DefaultConfig(),
// Provider: input.Provider,
//}
//name := "Demo AI API"
//description := "A demo that shows you how to use a e a Chat"
//apiId := uuid.New().String()
//err = i.aiAPIModule.Create(
// ctx,
// info.Id,
// &ai_api_dto.CreateAPI{
// Id: apiId,
// Name: name,
// Path: path,
// Description: description,
// Disable: false,
// AiPrompt: aiPrompt,
// AiModel: aiModel,
// Timeout: timeout,
// Retry: retry,
// },
//)
//if err != nil {
// return err
//}
//plugins := make(map[string]api.PluginSetting)
//plugins["ai_prompt"] = api.PluginSetting{
// Config: plugin_model.ConfigType{
// "prompt": aiPrompt.Prompt,
// "variables": aiPrompt.Variables,
// },
//}
//plugins["ai_formatter"] = api.PluginSetting{
// Config: plugin_model.ConfigType{
// "model": aiModel.Id,
// "provider": info.Provider.Id,
// "config": aiModel.Config,
// },
//}
//_, err = i.routerModule.Create(ctx, info.Id, &router_dto.Create{
// Id: apiId,
// Name: name,
// Path: path,
// Methods: []string{
// http.MethodPost,
// },
// Description: description,
// Protocols: []string{"http", "https"},
// MatchRules: nil,
// Proxy: &router_dto.InputProxy{
// Path: path,
// Timeout: timeout,
// Retry: retry,
// Plugins: plugins,
// },
// Disable: false,
//})
//if err != nil {
// return err
//}
})
}
+1 -1
View File
@@ -150,7 +150,7 @@ func (i *imlBalanceModule) List(ctx context.Context, keyword string) ([]*ai_bala
sort.Slice(list, func(i, j int) bool {
return list[i].Priority < list[j].Priority
})
aiAPIMap, err := i.aiAPIService.CountMapByProvider(ctx, "", nil)
aiAPIMap, err := i.aiAPIService.CountMapByModel(ctx, "", nil)
if err != nil {
return nil, fmt.Errorf("get ai api count error:%v", err)
}
+6
View File
@@ -97,6 +97,7 @@ 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"`
ApprovalType string `json:"approval_type"`
AsServer bool `json:"as_server"`
AsApp bool `json:"as_app"`
@@ -119,6 +120,7 @@ func ToService(model *service.Service) *Service {
if model.Prefix != "" {
prefix = model.Prefix
}
s := &Service{
Id: model.Id,
Name: model.Name,
@@ -146,6 +148,10 @@ func ToService(model *service.Service) *Service {
case service.AIService:
provider := auto.UUID(model.AdditionalConfig["provider"])
s.Provider = &provider
s.ProviderType = "local"
if provider.Id != "ollama" {
s.ProviderType = "online"
}
}
return s
}