mirror of
https://github.com/APIParkLab/APIPark.git
synced 2026-06-04 10:13:53 +08:00
support service mapping
This commit is contained in:
@@ -1,342 +0,0 @@
|
||||
provider: volcengine_maas
|
||||
label:
|
||||
en_US: Volcengine
|
||||
description:
|
||||
en_US: Volcengine Ark models.
|
||||
zh_Hans: 火山方舟提供的模型,例如 Doubao-pro-4k、Doubao-pro-32k 和 Doubao-pro-128k。
|
||||
icon_small:
|
||||
en_US: icon_s_en.svg
|
||||
icon_large:
|
||||
en_US: icon_l_en.svg
|
||||
zh_Hans: icon_l_zh.svg
|
||||
background: "#F9FAFB"
|
||||
help:
|
||||
title:
|
||||
en_US: Get your Access Key and Secret Access Key from Volcengine Console
|
||||
zh_Hans: 从火山引擎控制台获取您的 Access Key 和 Secret Access Key
|
||||
url:
|
||||
en_US: https://console.volcengine.com/iam/keymanage/
|
||||
supported_model_types:
|
||||
- llm
|
||||
- text-embedding
|
||||
configurate_methods:
|
||||
- customizable-model
|
||||
model_credential_schema:
|
||||
model:
|
||||
label:
|
||||
en_US: Model Name
|
||||
zh_Hans: 模型名称
|
||||
placeholder:
|
||||
en_US: Enter your Model Name
|
||||
zh_Hans: 输入模型名称
|
||||
credential_form_schemas:
|
||||
- variable: auth_method
|
||||
required: true
|
||||
label:
|
||||
en_US: Authentication Method
|
||||
zh_Hans: 鉴权方式
|
||||
type: select
|
||||
default: aksk
|
||||
options:
|
||||
- label:
|
||||
en_US: API Key
|
||||
value: api_key
|
||||
- label:
|
||||
en_US: Access Key / Secret Access Key
|
||||
value: aksk
|
||||
placeholder:
|
||||
en_US: Enter your Authentication Method
|
||||
zh_Hans: 选择鉴权方式
|
||||
- variable: volc_access_key_id
|
||||
required: true
|
||||
show_on:
|
||||
- variable: auth_method
|
||||
value: aksk
|
||||
label:
|
||||
en_US: Access Key
|
||||
zh_Hans: Access Key
|
||||
type: secret-input
|
||||
placeholder:
|
||||
en_US: Enter your Access Key
|
||||
zh_Hans: 输入您的 Access Key
|
||||
- variable: volc_secret_access_key
|
||||
required: true
|
||||
show_on:
|
||||
- variable: auth_method
|
||||
value: aksk
|
||||
label:
|
||||
en_US: Secret Access Key
|
||||
zh_Hans: Secret Access Key
|
||||
type: secret-input
|
||||
placeholder:
|
||||
en_US: Enter your Secret Access Key
|
||||
zh_Hans: 输入您的 Secret Access Key
|
||||
- variable: volc_api_key
|
||||
required: true
|
||||
show_on:
|
||||
- variable: auth_method
|
||||
value: api_key
|
||||
label:
|
||||
en_US: API Key
|
||||
type: secret-input
|
||||
placeholder:
|
||||
en_US: Enter your API Key
|
||||
zh_Hans: 输入您的 API Key
|
||||
- variable: volc_region
|
||||
required: true
|
||||
label:
|
||||
en_US: Volcengine Region
|
||||
zh_Hans: 火山引擎地域
|
||||
type: text-input
|
||||
default: cn-beijing
|
||||
placeholder:
|
||||
en_US: Enter Volcengine Region
|
||||
zh_Hans: 输入火山引擎地域
|
||||
- variable: api_endpoint_host
|
||||
required: true
|
||||
label:
|
||||
en_US: API Endpoint Host
|
||||
zh_Hans: API Endpoint Host
|
||||
type: text-input
|
||||
default: https://ark.cn-beijing.volces.com/api/v3
|
||||
placeholder:
|
||||
en_US: Enter your API Endpoint Host
|
||||
zh_Hans: 输入 API Endpoint Host
|
||||
- variable: endpoint_id
|
||||
required: true
|
||||
label:
|
||||
en_US: Endpoint ID
|
||||
zh_Hans: Endpoint ID
|
||||
type: text-input
|
||||
placeholder:
|
||||
en_US: Enter your Endpoint ID
|
||||
zh_Hans: 输入您的 Endpoint ID
|
||||
- variable: base_model_name
|
||||
label:
|
||||
en_US: Base Model
|
||||
zh_Hans: 基础模型
|
||||
type: select
|
||||
required: true
|
||||
options:
|
||||
- label:
|
||||
en_US: DeepSeek-R1-Distill-Qwen-32B
|
||||
value: DeepSeek-R1-Distill-Qwen-32B
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: DeepSeek-R1-Distill-Qwen-7B
|
||||
value: DeepSeek-R1-Distill-Qwen-7B
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: DeepSeek-R1
|
||||
value: DeepSeek-R1
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: DeepSeek-V3
|
||||
value: DeepSeek-V3
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-1.5-vision-pro-32k
|
||||
value: Doubao-1.5-vision-pro-32k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-1.5-pro-32k
|
||||
value: Doubao-1.5-pro-32k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-1.5-lite-32k
|
||||
value: Doubao-1.5-lite-32k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-1.5-pro-256k
|
||||
value: Doubao-1.5-pro-256k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-vision-pro-32k
|
||||
value: Doubao-vision-pro-32k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-vision-lite-32k
|
||||
value: Doubao-vision-lite-32k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-pro-4k
|
||||
value: Doubao-pro-4k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-lite-4k
|
||||
value: Doubao-lite-4k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-pro-32k
|
||||
value: Doubao-pro-32k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-lite-32k
|
||||
value: Doubao-lite-32k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-pro-128k
|
||||
value: Doubao-pro-128k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-lite-128k
|
||||
value: Doubao-lite-128k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-pro-256k
|
||||
value: Doubao-pro-256k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Llama3-8B
|
||||
value: Llama3-8B
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Llama3-70B
|
||||
value: Llama3-70B
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Moonshot-v1-8k
|
||||
value: Moonshot-v1-8k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Moonshot-v1-32k
|
||||
value: Moonshot-v1-32k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Moonshot-v1-128k
|
||||
value: Moonshot-v1-128k
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: GLM3-130B
|
||||
value: GLM3-130B
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: GLM3-130B-Fin
|
||||
value: GLM3-130B-Fin
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Mistral-7B
|
||||
value: Mistral-7B
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- label:
|
||||
en_US: Doubao-embedding
|
||||
value: Doubao-embedding
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: text-embedding
|
||||
- label:
|
||||
en_US: Doubao-embedding-large
|
||||
value: Doubao-embedding-large
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: text-embedding
|
||||
- label:
|
||||
en_US: Custom
|
||||
zh_Hans: 自定义
|
||||
value: Custom
|
||||
- variable: mode
|
||||
required: true
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- variable: base_model_name
|
||||
value: Custom
|
||||
label:
|
||||
zh_Hans: 模型类型
|
||||
en_US: Completion Mode
|
||||
type: select
|
||||
default: chat
|
||||
placeholder:
|
||||
zh_Hans: 选择对话类型
|
||||
en_US: Select Completion Mode
|
||||
options:
|
||||
- value: completion
|
||||
label:
|
||||
en_US: Completion
|
||||
zh_Hans: 补全
|
||||
- value: chat
|
||||
label:
|
||||
en_US: Chat
|
||||
zh_Hans: 对话
|
||||
- variable: context_size
|
||||
required: true
|
||||
show_on:
|
||||
- variable: base_model_name
|
||||
value: Custom
|
||||
label:
|
||||
zh_Hans: 模型上下文长度
|
||||
en_US: Model Context Size
|
||||
type: text-input
|
||||
default: "4096"
|
||||
placeholder:
|
||||
zh_Hans: 输入您的模型上下文长度
|
||||
en_US: Enter your Model Context Size
|
||||
- variable: max_tokens
|
||||
required: true
|
||||
show_on:
|
||||
- variable: __model_type
|
||||
value: llm
|
||||
- variable: base_model_name
|
||||
value: Custom
|
||||
label:
|
||||
zh_Hans: 最大 token 上限
|
||||
en_US: Upper Bound for Max Tokens
|
||||
default: "4096"
|
||||
type: text-input
|
||||
placeholder:
|
||||
zh_Hans: 输入您的模型最大 token 上限
|
||||
en_US: Enter your model Upper Bound for Max Tokens
|
||||
address: https://open.volcengine.com
|
||||
model_config:
|
||||
access_configuration_status: true
|
||||
access_configuration_demo: "{\"endpoint\": \"https://196.1.1.2:3824\"}"
|
||||
@@ -14,6 +14,10 @@ type ClientDriver struct {
|
||||
client admin_client.Client
|
||||
}
|
||||
|
||||
func (c *ClientDriver) Hash() gateway.IHashClient {
|
||||
return NewHashClient(c.client)
|
||||
}
|
||||
|
||||
func (c *ClientDriver) Strategy() gateway.IStrategyClient {
|
||||
return NewStrategyClient(c.client)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package apinto
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/APIParkLab/APIPark/gateway"
|
||||
admin_client "github.com/eolinker/eosc/process-admin/client"
|
||||
)
|
||||
|
||||
var _ gateway.IHashClient = &HashClient{}
|
||||
|
||||
type HashClient struct {
|
||||
client admin_client.Client
|
||||
}
|
||||
|
||||
func (s *HashClient) Online(ctx context.Context, resources ...*gateway.HashRelease) error {
|
||||
s.client.Begin(ctx)
|
||||
for _, r := range resources {
|
||||
// 先删除所有,再set
|
||||
err := s.client.HDelAll(ctx, r.HashKey)
|
||||
if err != nil {
|
||||
s.client.Rollback(ctx)
|
||||
return err
|
||||
}
|
||||
for key, value := range r.HashMap {
|
||||
err := s.client.HSet(ctx, r.HashKey, key, value)
|
||||
if err != nil {
|
||||
s.client.Rollback(ctx)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return s.client.Commit(ctx)
|
||||
}
|
||||
|
||||
func (s *HashClient) Offline(ctx context.Context, resources ...*gateway.HashRelease) error {
|
||||
s.client.Begin(ctx)
|
||||
for _, r := range resources {
|
||||
if len(r.HashMap) == 0 {
|
||||
err := s.client.HDelAll(ctx, r.HashKey)
|
||||
if err != nil {
|
||||
s.client.Rollback(ctx)
|
||||
return err
|
||||
}
|
||||
}
|
||||
for key, _ := range r.HashMap {
|
||||
err := s.client.HDel(ctx, r.HashKey, key)
|
||||
if err != nil {
|
||||
s.client.Rollback(ctx)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return s.client.Commit(ctx)
|
||||
}
|
||||
|
||||
func NewHashClient(client admin_client.Client) *HashClient {
|
||||
return &HashClient{client: client}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ type IClientDriver interface {
|
||||
Subscribe() ISubscribeClient
|
||||
Strategy() IStrategyClient
|
||||
Dynamic(resource string) (IDynamicClient, error)
|
||||
Hash() IHashClient
|
||||
PluginSetting() IPluginSetting
|
||||
Commit(ctx context.Context) error
|
||||
Rollback(ctx context.Context) error
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
package gateway
|
||||
|
||||
const KeyServiceMapping = "service_mapping"
|
||||
@@ -15,6 +15,8 @@ type IApplicationClient IResourceClient[ApplicationRelease]
|
||||
|
||||
type IServiceClient IResourceClient[ServiceRelease]
|
||||
|
||||
type IHashClient IResourceClient[HashRelease]
|
||||
|
||||
type ISubscribeClient IResourceClient[SubscribeRelease]
|
||||
|
||||
type IStrategyClient IResourceClient[eosc.Base[StrategyRelease]]
|
||||
@@ -133,6 +135,11 @@ type ServiceRelease struct {
|
||||
Apis []string
|
||||
}
|
||||
|
||||
type HashRelease struct {
|
||||
HashKey string
|
||||
HashMap map[string]string
|
||||
}
|
||||
|
||||
type SubscribeRelease struct {
|
||||
// 订阅服务ID
|
||||
Service string
|
||||
|
||||
@@ -37,7 +37,7 @@ type EditService struct {
|
||||
Model *string `json:"model"`
|
||||
ApprovalType *string `json:"approval_type"`
|
||||
State *string `json:"state"`
|
||||
ModelMapping string `json:"model_mapping"`
|
||||
ModelMapping *string `json:"model_mapping"`
|
||||
}
|
||||
|
||||
type CreateApp struct {
|
||||
|
||||
+48
-7
@@ -2,12 +2,17 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/APIParkLab/APIPark/gateway"
|
||||
|
||||
"github.com/APIParkLab/APIPark/service/cluster"
|
||||
|
||||
ai_local "github.com/APIParkLab/APIPark/service/ai-local"
|
||||
|
||||
model_runtime "github.com/APIParkLab/APIPark/ai-provider/model-runtime"
|
||||
@@ -68,6 +73,7 @@ type imlServiceModule struct {
|
||||
serviceTagService service_tag.ITagService `autowired:""`
|
||||
apiService api.IAPIService `autowired:""`
|
||||
apiDocService api_doc.IAPIDocService `autowired:""`
|
||||
clusterService cluster.IClusterService `autowired:""`
|
||||
transaction store.ITransaction `autowired:""`
|
||||
|
||||
serviceModelMappingService service_model_mapping.IServiceModelMappingService `autowired:""`
|
||||
@@ -464,15 +470,35 @@ func (i *imlServiceModule) Edit(ctx context.Context, id string, input *service_d
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
err = i.serviceModelMappingService.Save(ctx, &service_model_mapping.Save{
|
||||
Sid: id,
|
||||
Content: input.ModelMapping,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
if input.ModelMapping != nil {
|
||||
m := make(map[string]string)
|
||||
err = json.Unmarshal([]byte(*input.ModelMapping), &m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = i.serviceModelMappingService.Save(ctx, &service_model_mapping.Save{
|
||||
Sid: id,
|
||||
Content: *input.ModelMapping,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, err := i.clusterService.GatewayClient(ctx, cluster.DefaultClusterID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = client.Hash().Online(ctx, &gateway.HashRelease{
|
||||
HashKey: fmt.Sprintf("%s:%s", gateway.KeyServiceMapping, id),
|
||||
HashMap: m,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
@@ -491,7 +517,22 @@ func (i *imlServiceModule) Delete(ctx context.Context, id string) error {
|
||||
return fmt.Errorf("service has apis, can not delete")
|
||||
}
|
||||
|
||||
return i.serviceService.Delete(ctx, id)
|
||||
err = i.serviceService.Delete(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = i.serviceModelMappingService.Delete(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
client, err := i.clusterService.GatewayClient(ctx, cluster.DefaultClusterID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return client.Hash().Offline(ctx, &gateway.HashRelease{
|
||||
HashKey: fmt.Sprintf("%s:%s", gateway.KeyServiceMapping, id),
|
||||
})
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -16,6 +16,14 @@ type imlServiceModelMappingService struct {
|
||||
store service.IServiceModelMappingStore `autowired:""`
|
||||
}
|
||||
|
||||
func (i *imlServiceModelMappingService) Delete(ctx context.Context, sid string) error {
|
||||
_, err := i.store.DeleteWhere(ctx, map[string]interface{}{"sid": sid})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *imlServiceModelMappingService) Get(ctx context.Context, sid string) (*ModelMapping, error) {
|
||||
entity, err := i.store.First(ctx, map[string]interface{}{"sid": sid})
|
||||
if err != nil {
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
type IServiceModelMappingService interface {
|
||||
Get(ctx context.Context, sid string) (*ModelMapping, error)
|
||||
Save(ctx context.Context, input *Save) error
|
||||
Delete(ctx context.Context, sid string) error
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
Reference in New Issue
Block a user