mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-04 10:13:53 +08:00
update ai provider api
This commit is contained in:
@@ -21,8 +21,10 @@ type Provider struct {
|
||||
Help Help `json:"help" yaml:"help"`
|
||||
SupportedModelTypes []string `json:"supported_model_types" yaml:"supported_model_types"`
|
||||
ProviderCredentialSchema ProviderCredentialSchema `json:"provider_credential_schema" yaml:"provider_credential_schema"`
|
||||
Default map[string]string `json:"default"`
|
||||
Address string `json:"address"`
|
||||
Default map[string]string `json:"default" yaml:"default"`
|
||||
Address string `json:"address" yaml:"address"`
|
||||
Recommend bool `json:"recommend" yaml:"recommend"`
|
||||
Sort int `json:"sort" yaml:"sort"`
|
||||
}
|
||||
|
||||
type ProviderCredentialSchema struct {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package model_runtime
|
||||
|
||||
import "github.com/eolinker/eosc"
|
||||
import (
|
||||
"github.com/eolinker/eosc"
|
||||
)
|
||||
|
||||
var (
|
||||
defaultManager = NewManager()
|
||||
@@ -27,6 +29,13 @@ func (m *Manager) Del(name string) {
|
||||
}
|
||||
|
||||
func (m *Manager) List() []IProvider {
|
||||
//list := m.providers.List()
|
||||
//sort.Slice(list, func(i, j int) bool {
|
||||
// if list[i].Sort() == list[j].Sort() {
|
||||
// return list[i].ID() < list[j].ID()
|
||||
// }
|
||||
// return list[i].Sort() < list[j].Sort()
|
||||
//})
|
||||
return m.providers.List()
|
||||
}
|
||||
|
||||
|
||||
@@ -38,3 +38,5 @@ provider_credential_schema:
|
||||
zh_Hans: 在此输入您的 API URL
|
||||
en_US: Enter your API URL
|
||||
address: https://api.anthropic.com
|
||||
recommend: true
|
||||
sort: 2
|
||||
@@ -1,6 +1,6 @@
|
||||
provider: bedrock
|
||||
label:
|
||||
en_US: AWS
|
||||
en_US: AWS Bedrock
|
||||
description:
|
||||
en_US: AWS Bedrock's models.
|
||||
icon_small:
|
||||
@@ -87,4 +87,6 @@ provider_credential_schema:
|
||||
placeholder:
|
||||
en_US: A model you have access to (e.g. amazon.titan-text-lite-v1) for validation.
|
||||
zh_Hans: 为了进行验证,请输入一个您可用的模型名称 (例如:amazon.titan-text-lite-v1)
|
||||
address: https://bedrock-runtime.amazonaws.com
|
||||
address: https://bedrock-runtime.amazonaws.com
|
||||
sort: 4
|
||||
recommend: true
|
||||
@@ -1,6 +1,6 @@
|
||||
provider: google
|
||||
label:
|
||||
en_US: Google
|
||||
en_US: Google Gemini
|
||||
description:
|
||||
en_US: Google's Gemini model.
|
||||
zh_Hans: 谷歌提供的 Gemini 模型.
|
||||
@@ -38,4 +38,6 @@ provider_credential_schema:
|
||||
placeholder:
|
||||
zh_Hans: 在此输入您的 API Base, 如:https://api.google.com
|
||||
en_US: Enter your API Base, e.g. https://api.google.com
|
||||
address: https://generativelanguage.googleapis.com
|
||||
address: https://generativelanguage.googleapis.com
|
||||
recommend: true
|
||||
sort: 3
|
||||
@@ -27,4 +27,6 @@ provider_credential_schema:
|
||||
placeholder:
|
||||
zh_Hans: 在此输入您的 API Key
|
||||
en_US: Enter your API Key
|
||||
address: https://api.minimax.chat
|
||||
address: https://api.minimax.chat
|
||||
recommend: true
|
||||
sort: 5
|
||||
@@ -31,4 +31,6 @@ provider_credential_schema:
|
||||
placeholder:
|
||||
zh_Hans: 在此输入您的 API Key
|
||||
en_US: Enter your API Key
|
||||
address: https://api.moonshot.cn
|
||||
address: https://api.moonshot.cn
|
||||
recommend: true
|
||||
sort: 6
|
||||
@@ -1,6 +1,6 @@
|
||||
provider: nvidia
|
||||
label:
|
||||
en_US: API Catalog
|
||||
en_US: Nvidia
|
||||
description:
|
||||
en_US: API Catalog
|
||||
zh_Hans: API Catalog
|
||||
|
||||
@@ -88,3 +88,5 @@ provider_credential_schema:
|
||||
zh_Hans: 在此输入您的 API Base, 如:https://api.openai.com
|
||||
en_US: Enter your API Base, e.g. https://api.openai.com
|
||||
address: https://api.openai.com
|
||||
recommend: true
|
||||
sort: 1
|
||||
@@ -1,6 +1,6 @@
|
||||
provider: wenxin
|
||||
label:
|
||||
en_US: WenXin
|
||||
en_US: Wenxin YiYan
|
||||
zh_Hans: 文心一言
|
||||
icon_small:
|
||||
en_US: icon_s_en.svg
|
||||
@@ -38,4 +38,6 @@ provider_credential_schema:
|
||||
placeholder:
|
||||
zh_Hans: 在此输入您的 Secret Key
|
||||
en_US: Enter your Secret Key
|
||||
address: https://aip.baidubce.com
|
||||
address: https://aip.baidubce.com
|
||||
recommend: true
|
||||
sort: 7
|
||||
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
@@ -22,6 +22,8 @@ type IProvider interface {
|
||||
ModelsByType(modelType string) ([]IModel, bool)
|
||||
IConfig
|
||||
MaskConfig(cfg string) string
|
||||
Sort() int
|
||||
Recommend() bool
|
||||
}
|
||||
|
||||
type IProviderURI interface {
|
||||
@@ -72,6 +74,8 @@ func NewProvider(providerData string, modelContents map[string]eosc.Untyped[stri
|
||||
defaultModels: eosc.BuildUntyped[string, IModel](),
|
||||
modelsByType: eosc.BuildUntyped[string, []IModel](),
|
||||
maskKeys: make([]string, 0),
|
||||
recommend: providerCfg.Recommend,
|
||||
sort: providerCfg.Sort,
|
||||
uri: uri,
|
||||
}
|
||||
defaultCfg := make(map[string]string)
|
||||
@@ -126,9 +130,19 @@ type Provider struct {
|
||||
modelsByType eosc.Untyped[string, []IModel]
|
||||
maskKeys []string
|
||||
uri IProviderURI
|
||||
sort int
|
||||
recommend bool
|
||||
IConfig
|
||||
}
|
||||
|
||||
func (p *Provider) Sort() int {
|
||||
return p.sort
|
||||
}
|
||||
|
||||
func (p *Provider) Recommend() bool {
|
||||
return p.recommend
|
||||
}
|
||||
|
||||
func (p *Provider) URI() IProviderURI {
|
||||
return p.uri
|
||||
}
|
||||
|
||||
@@ -5,5 +5,6 @@ type UpdateLLM struct {
|
||||
}
|
||||
|
||||
type UpdateConfig struct {
|
||||
Config string `json:"config"`
|
||||
DefaultLLM string `json:"default_llm"`
|
||||
Config string `json:"config"`
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ type Provider struct {
|
||||
Name string `json:"name"`
|
||||
Config string `json:"config"`
|
||||
GetAPIKeyUrl string `json:"get_apikey_url"`
|
||||
DefaultLLM string `json:"-"`
|
||||
DefaultLLM string `json:"defaultLLM"`
|
||||
DefaultLLMConfig string `json:"-"`
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ type ProviderItem struct {
|
||||
DefaultLLMLogo string `json:"default_llm_logo"`
|
||||
Logo string `json:"logo"`
|
||||
Configured bool `json:"configured"`
|
||||
Recommend bool `json:"recommend"`
|
||||
Sort int `json:"sort"`
|
||||
UpdateTime time.Time `json:"-"`
|
||||
}
|
||||
|
||||
|
||||
+23
-10
@@ -90,9 +90,11 @@ func (i *imlProviderModule) Providers(ctx context.Context) ([]*ai_dto.ProviderIt
|
||||
continue
|
||||
}
|
||||
item := &ai_dto.ProviderItem{
|
||||
Id: v.ID(),
|
||||
Name: v.Name(),
|
||||
Logo: v.Logo(),
|
||||
Id: v.ID(),
|
||||
Name: v.Name(),
|
||||
Logo: v.Logo(),
|
||||
Recommend: v.Recommend(),
|
||||
Sort: v.Sort(),
|
||||
}
|
||||
if info, has := providerMap[v.ID()]; has {
|
||||
item.Configured = true
|
||||
@@ -103,8 +105,19 @@ func (i *imlProviderModule) Providers(ctx context.Context) ([]*ai_dto.ProviderIt
|
||||
items = append(items, item)
|
||||
}
|
||||
sort.Slice(items, func(i, j int) bool {
|
||||
|
||||
return items[i].UpdateTime.After(items[j].UpdateTime)
|
||||
if items[i].Configured == items[j].Configured && items[i].Configured {
|
||||
return items[i].Name < items[j].Name
|
||||
}
|
||||
if items[i].Sort != items[j].Sort {
|
||||
if items[i].Sort == 0 {
|
||||
return false
|
||||
}
|
||||
if items[j].Sort == 0 {
|
||||
return true
|
||||
}
|
||||
return items[i].Sort < items[j].Sort
|
||||
}
|
||||
return items[i].Name < items[j].Name
|
||||
})
|
||||
return items, nil
|
||||
}
|
||||
@@ -262,14 +275,14 @@ func (i *imlProviderModule) UpdateProviderConfig(ctx context.Context, id string,
|
||||
if !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return err
|
||||
}
|
||||
defaultLLm, ok := p.DefaultModel(model_runtime.ModelTypeLLM)
|
||||
if !ok {
|
||||
return fmt.Errorf("ai provider default llm not found")
|
||||
}
|
||||
//defaultLLm, ok := p.DefaultModel(model_runtime.ModelTypeLLM)
|
||||
//if !ok {
|
||||
// return fmt.Errorf("ai provider default llm not found")
|
||||
//}
|
||||
info = &ai.Provider{
|
||||
Id: id,
|
||||
Name: p.Name(),
|
||||
DefaultLLM: defaultLLm.ID(),
|
||||
DefaultLLM: input.DefaultLLM,
|
||||
Config: input.Config,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ type AppItem struct {
|
||||
Team auto.Label `json:"team" aolabel:"team"`
|
||||
SubscribeNum int64 `json:"subscribe_num"`
|
||||
SubscribeVerifyNum int64 `json:"subscribe_verify_num"`
|
||||
AuthNum int64 `json:"auth_num"`
|
||||
Description string `json:"description"`
|
||||
CreateTime auto.TimeLabel `json:"create_time"`
|
||||
UpdateTime auto.TimeLabel `json:"update_time"`
|
||||
|
||||
+13
-5
@@ -7,6 +7,8 @@ import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
application_authorization "github.com/APIParkLab/APIPark/service/application-authorization"
|
||||
|
||||
api_doc "github.com/APIParkLab/APIPark/service/api-doc"
|
||||
|
||||
service_tag "github.com/APIParkLab/APIPark/service/service-tag"
|
||||
@@ -532,11 +534,12 @@ var (
|
||||
)
|
||||
|
||||
type imlAppModule struct {
|
||||
teamService team.ITeamService `autowired:""`
|
||||
serviceService service.IServiceService `autowired:""`
|
||||
teamMemberService team_member.ITeamMemberService `autowired:""`
|
||||
subscribeService subscribe.ISubscribeService `autowired:""`
|
||||
transaction store.ITransaction `autowired:""`
|
||||
teamService team.ITeamService `autowired:""`
|
||||
serviceService service.IServiceService `autowired:""`
|
||||
teamMemberService team_member.ITeamMemberService `autowired:""`
|
||||
subscribeService subscribe.ISubscribeService `autowired:""`
|
||||
authService application_authorization.IAuthorizationService `autowired:""`
|
||||
transaction store.ITransaction `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlAppModule) ExportAll(ctx context.Context) ([]*service_dto.ExportApp, error) {
|
||||
@@ -600,6 +603,10 @@ func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string
|
||||
|
||||
}
|
||||
}
|
||||
appMap, err := i.authService.CountByApp(ctx, serviceIds...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items := make([]*service_dto.AppItem, 0, len(services))
|
||||
for _, model := range services {
|
||||
subscribeNum := subscribeCount[model.Id]
|
||||
@@ -614,6 +621,7 @@ func (i *imlAppModule) Search(ctx context.Context, teamId string, keyword string
|
||||
SubscribeNum: subscribeNum,
|
||||
SubscribeVerifyNum: verifyNum,
|
||||
CanDelete: subscribeNum == 0,
|
||||
AuthNum: appMap[model.Id],
|
||||
})
|
||||
}
|
||||
sort.Slice(items, func(i, j int) bool {
|
||||
|
||||
@@ -3,11 +3,11 @@ package application_authorization
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
|
||||
"github.com/eolinker/go-common/utils"
|
||||
|
||||
|
||||
"github.com/eolinker/go-common/auto"
|
||||
|
||||
|
||||
"github.com/APIParkLab/APIPark/service/universally"
|
||||
"github.com/APIParkLab/APIPark/stores/service"
|
||||
)
|
||||
@@ -24,6 +24,14 @@ type imlAuthorizationService struct {
|
||||
universally.IServiceEdit[Edit]
|
||||
}
|
||||
|
||||
func (i *imlAuthorizationService) CountByApp(ctx context.Context, appId ...string) (map[string]int64, error) {
|
||||
w := map[string]interface{}{}
|
||||
if len(appId) > 0 {
|
||||
w["application"] = appId
|
||||
}
|
||||
return i.store.CountByGroup(ctx, "", w, "application")
|
||||
}
|
||||
|
||||
func (i *imlAuthorizationService) ListByApp(ctx context.Context, appId ...string) ([]*Authorization, error) {
|
||||
w := map[string]interface{}{}
|
||||
if len(appId) > 0 {
|
||||
@@ -51,11 +59,11 @@ func (i *imlAuthorizationService) GetLabels(ctx context.Context, ids ...string)
|
||||
|
||||
func (i *imlAuthorizationService) OnComplete() {
|
||||
i.IServiceGet = universally.NewGet[Authorization, service.Authorization](i.store, FromEntity)
|
||||
|
||||
|
||||
i.IServiceDelete = universally.NewDelete[service.Authorization](i.store)
|
||||
|
||||
|
||||
i.IServiceCreate = universally.NewCreator[Create, service.Authorization](i.store, "project_authorization", createEntityHandler, uniquestHandler, labelHandler)
|
||||
|
||||
|
||||
i.IServiceEdit = universally.NewEdit[Edit, service.Authorization](i.store, updateHandler, labelHandler)
|
||||
auto.RegisterService("project_authorization", i)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package application_authorization
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
|
||||
|
||||
"github.com/APIParkLab/APIPark/service/universally"
|
||||
"github.com/eolinker/go-common/autowire"
|
||||
)
|
||||
@@ -14,6 +14,7 @@ type IAuthorizationService interface {
|
||||
universally.IServiceCreate[Create]
|
||||
universally.IServiceEdit[Edit]
|
||||
ListByApp(ctx context.Context, appId ...string) ([]*Authorization, error)
|
||||
CountByApp(ctx context.Context, appId ...string) (map[string]int64, error)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
Reference in New Issue
Block a user