feat: add ai benchmark

This commit is contained in:
zhengkunwang223
2026-04-30 17:48:04 +08:00
parent 8d44105f88
commit 22c3fc8c40
12 changed files with 189 additions and 12 deletions
+1
View File
@@ -471,6 +471,7 @@ TaskScan: "Scan"
# task - ai
OllamaModelPull: 'Pull Ollama model {{ .name }}'
OllamaModelSize: 'Get Ollama model size: {{ .name }}'
AIBenchmarkRun: 'Run AI benchmark'
# task-snapshot
Snapshot: 'Snapshot'
+1
View File
@@ -471,6 +471,7 @@ TaskScan: "扫描"
# task - ai
OllamaModelPull: "拉取 Ollama 模型 {{ .name }}"
OllamaModelSize: "获取 Ollama 模型 {{ .name }} 大小"
AIBenchmarkRun: "执行 AI 基准测试"
# task - snapshot
Snapshot: "快照"
+2
View File
@@ -57,6 +57,7 @@ const (
TaskCreateCluster = "TaskCreateCluster"
TaskBackup = "TaskBackup"
TaskPush = "TaskPush"
TaskExec = "TaskExec"
)
const (
@@ -66,6 +67,7 @@ const (
TaskScopeAppBackup = "AppBackup"
TaskScopeCluster = "Cluster"
TaskScopeAppInstall = "AppInstallTask"
TaskScopeAI = "AI"
)
func GetTaskName(resourceName, operate, scope string) string {
+3 -2
View File
@@ -1,8 +1,9 @@
package constant
const (
StatusSuccess = "Success"
StatusFailed = "Failed"
StatusSuccess = "Success"
StatusFailed = "Failed"
StatusCanceled = "Canceled"
// node
StatusWaiting = "Waiting"
+1
View File
@@ -131,6 +131,7 @@ TaskUpgrade: "Upgrade"
TaskSync: 'Sync'
TaskSyncForNode: "Sync node data"
TaskBackup: "Backup"
AIBenchmarkRun: "Run AI benchmark"
SuccessStatus: "{{ .name }} succeeded"
FailedStatus: "{{ .name }} failed {{ .err }}"
Start: "Start"
+1
View File
@@ -130,6 +130,7 @@ TaskUpgrade: "升级"
TaskSync: "同步"
TaskSyncForNode: "同步节点数据"
TaskBackup: "备份"
AIBenchmarkRun: "执行 AI 基准测试"
SuccessStatus: "{{ .name }} 成功"
FailedStatus: "{{ .name }} 失败 {{ .err }}"
Start: "开始"
+13
View File
@@ -86,6 +86,18 @@ func LoadMenus() string {
}
if global.CONF.Base.IsEnterprise {
for i := range item {
if item[i].Label == "AI-Menu" {
item[i].Children = UpsertMenuByLabel(item[i].Children, dto.ShowMenu{
ID: "45",
Disabled: false,
Title: "aiTools.benchmark.title",
IsShow: true,
Label: "AIBenchmark",
Path: "/ai/benchmark",
Sort: 150,
}, "AIModel")
continue
}
if item[i].Label != "Xpack-Menu" {
continue
}
@@ -112,6 +124,7 @@ func MenuSort() []dto.MenuLabelSort {
{Label: "AI-Menu", Sort: 300},
{Label: "Agents", Sort: 50},
{Label: "AIModel", Sort: 100},
{Label: "AIBenchmark", Sort: 150},
{Label: "MCPServer", Sort: 200},
{Label: "GPU", Sort: 300},
{Label: "Website-Menu", Sort: 400},
+1
View File
@@ -39,6 +39,7 @@ func Init() {
migrations.AddDocSourceSetting,
migrations.AddAppStoreInstallAllowPortSetting,
migrations.AddUserManagementMenu,
migrations.AddAIBenchmarkMenu,
migrations.AddOperationLogUser,
migrations.AddIsOfflineSetting,
})
+58
View File
@@ -953,6 +953,15 @@ func buildAiMenuChildren(children []dto.ShowMenu) []dto.ShowMenu {
Path: "/ai/model/account",
Sort: 100,
}, "AIModel", "OllamaModel"),
normalizeAiMenuChild(children, dto.ShowMenu{
ID: "45",
Label: "AIBenchmark",
Disabled: false,
IsShow: true,
Title: "aiTools.benchmark.title",
Path: "/ai/benchmark",
Sort: 150,
}, "AIBenchmark"),
normalizeAiMenuChild(children, dto.ShowMenu{
ID: "42",
Label: "MCPServer",
@@ -993,6 +1002,55 @@ func normalizeAiMenuChild(children []dto.ShowMenu, fallback dto.ShowMenu, labels
return fallback
}
var AddAIBenchmarkMenu = &gormigrate.Migration{
ID: "20260429-add-ai-benchmark-menu",
Migrate: func(tx *gorm.DB) error {
if !global.CONF.Base.IsEnterprise {
return nil
}
var menuJSON string
if err := tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Pluck("value", &menuJSON).Error; err != nil {
return err
}
if menuJSON == "" {
menuJSON = helper.LoadMenus()
}
var menus []dto.ShowMenu
if err := json.Unmarshal([]byte(menuJSON), &menus); err != nil {
return tx.Model(&model.Setting{}).
Where("key = ?", "HideMenu").
Update("value", helper.LoadMenus()).Error
}
newItem := dto.ShowMenu{
ID: "45",
Disabled: false,
Title: "aiTools.benchmark.title",
IsShow: true,
Label: "AIBenchmark",
Path: "/ai/benchmark",
Sort: 150,
}
for i := range menus {
if menus[i].Label != "AI-Menu" {
continue
}
menus[i].Children = helper.UpsertMenuByLabel(menus[i].Children, newItem, "AIModel")
break
}
updatedJSON, err := json.Marshal(menus)
if err != nil {
return tx.Model(&model.Setting{}).
Where("key = ?", "HideMenu").
Update("value", helper.LoadMenus()).Error
}
return tx.Model(&model.Setting{}).Where("key = ?", "HideMenu").Update("value", string(updatedJSON)).Error
},
}
var AddUserManagementMenu = &gormigrate.Migration{
ID: "20260415-add-user-management-menu",
Migrate: func(tx *gorm.DB) error {
+18 -2
View File
@@ -22,6 +22,7 @@ import (
const maxStreamOutputCapture = 64 * 1024
type CommandHelper struct {
context context.Context
workDir string
outputFile string
env []string
@@ -167,7 +168,10 @@ func (c *CommandHelper) RunPipe(commands ...PipeCommand) (string, error) {
}
func (c *CommandHelper) pipeContext() (context.Context, context.CancelFunc) {
ctx := context.Background()
ctx := c.context
if ctx == nil {
ctx = context.Background()
}
if c.timeout == 0 {
return ctx, nil
}
@@ -243,9 +247,16 @@ func (c *CommandHelper) run(name string, arg ...string) (string, error) {
var cancel context.CancelFunc
if c.timeout != 0 {
ctx, cancel = context.WithTimeout(context.Background(), c.timeout)
if c.context == nil {
ctx, cancel = context.WithTimeout(context.Background(), c.timeout)
} else {
ctx, cancel = context.WithTimeout(c.context, c.timeout)
}
defer cancel()
cmd = exec.CommandContext(ctx, name, arg...)
} else if c.context != nil {
ctx = c.context
cmd = exec.CommandContext(ctx, name, arg...)
} else {
cmd = exec.Command(name, arg...)
}
@@ -337,6 +348,11 @@ func WithOutputFile(outputFile string) Option {
s.outputFile = outputFile
}
}
func WithContext(ctx context.Context) Option {
return func(s *CommandHelper) {
s.context = ctx
}
}
func WithTimeout(timeout time.Duration) Option {
return func(s *CommandHelper) {
s.timeout = timeout
+46 -4
View File
@@ -914,12 +914,15 @@ const message = {
failureCount: 'Failures',
lastError: 'Last Error',
modelMap: 'Model Mapping',
apiKeys: 'API Keys',
apiKey: 'API Key',
apiKeyKeepEmpty: 'API Key (leave empty to keep unchanged)',
apiKeyOnceHint: 'The API Key is shown only once after creation. Copy and save it now.',
apiKeyOnceSave: 'The API Key is shown only once. Save it now:',
apiKeyReset: 'Reset API Key (leave empty to keep unchanged)',
qpsLimit: 'QPS Limit',
unlimited: 'Unlimited',
userGroup: 'User Group',
userGroups: 'User Groups',
defaultGroup: 'Default',
apiKeyCount: 'API Keys',
lastUsedAt: 'Last Used',
settingTitle: 'AI Proxy Settings',
lbPolicy: 'Load Balancing Policy',
@@ -947,7 +950,8 @@ const message = {
serviceOperateConfirm: 'Confirm to {0} the AI Proxy service?',
deleteBackendConfirm: 'Delete model account {0}?',
deleteBackendTitle: 'Delete Model Account',
deleteUserConfirm: 'Delete user {0}?',
deleteUserConfirm: 'Delete API Key {0}?',
deleteGroupConfirm: 'Delete user group {0}?',
userFallback: 'User {0}',
requestModel: 'Request Model',
upstreamModel: 'Upstream Model',
@@ -983,6 +987,44 @@ const message = {
validationModelMapEmpty: 'Model mapping names cannot be empty',
validationModelMapDuplicate: 'Request model {0} is duplicated',
},
benchmark: {
title: 'Benchmark',
create: 'Create',
launchCommand: 'Launch Command',
retest: 'Retest',
statusRunning: 'Running',
statusWaiting: 'Waiting',
base: 'Basic Information',
backend: 'Backend',
baseUrl: 'Base URL',
endpoint: 'Endpoint',
tokenizer: 'Tokenizer',
tokenizerPlaceholder:
'Select or enter a local tokenizer directory, e.g. /opt/1panel/tokenizers/DeepSeek-V3',
runConfig: 'Run Config',
rawResult: 'Raw Result',
contextTokens: 'Context Length',
contextTokensHelper: 'Input token limit plus output token limit for this benchmark.',
outputThroughput: 'Output Throughput',
outputThroughputHelper: 'Generated output tokens per second. Higher means faster generation.',
totalThroughput: 'Total Throughput',
totalThroughputHelper: 'Input and output tokens processed per second. Used to measure overall capacity.',
firstTokenLatency: 'First Token Latency',
firstTokenLatencyHelper:
'Time from sending the request to receiving the first token. Lower means faster response.',
inputTokens: 'Input Tokens',
outputTokens: 'Output Tokens',
numPrompts: 'Prompts',
concurrency: 'Concurrency',
requestRate: 'Request Rate',
requestRateUnlimited: 'Unlimited (max throughput)',
requestRateCustom: 'Custom QPS',
requestRateCustomPlaceholder: 'Requests per second, e.g. 2.5',
timeout: 'Timeout (seconds)',
image: 'vLLM Image',
ignoreEos: 'Ignore EOS',
extraHeaders: 'Extra Headers',
},
gpu: {
gpu: 'GPU Monitoring',
gpuHelper: 'The system did not detect NVIDIA-SMI or XPU-SMI commands. Please check and try again!',
+44 -4
View File
@@ -858,12 +858,15 @@ const message = {
failureCount: '失败次数',
lastError: '最近错误',
modelMap: '模型映射',
apiKeys: 'API Key',
apiKey: 'API Key',
apiKeyKeepEmpty: 'API Key(留空不改)',
apiKeyOnceHint: 'API Key 仅创建时显示一次,请及时复制保存。',
apiKeyOnceSave: 'API Key 只显示一次,请立即保存:',
apiKeyReset: '重置 API Key(留空不改)',
qpsLimit: 'QPS 限制',
unlimited: '不限',
userGroup: '用户组',
userGroups: '用户组',
defaultGroup: '默认',
apiKeyCount: 'API Key 数',
lastUsedAt: '最近使用时间',
settingTitle: 'AI 代理设置',
lbPolicy: '负载策略',
@@ -889,7 +892,8 @@ const message = {
serviceOperateConfirm: '确认{0} AI 代理服务?',
deleteBackendConfirm: '确认删除模型账号 {0}?',
deleteBackendTitle: '删除模型账号',
deleteUserConfirm: '确认删除用户 {0}?',
deleteUserConfirm: '确认删除 API Key {0}?',
deleteGroupConfirm: '确认删除用户组 {0}?',
userFallback: '用户 {0}',
requestModel: '请求模型',
upstreamModel: '上游模型',
@@ -925,6 +929,42 @@ const message = {
validationModelMapEmpty: '模型映射的模型名不能为空',
validationModelMapDuplicate: '请求模型 {0} 重复',
},
benchmark: {
title: '基准测试',
create: '创建',
launchCommand: '启动命令',
retest: '重新测试',
statusRunning: '运行中',
statusWaiting: '等待中',
base: '基础信息',
backend: '后端',
baseUrl: '服务地址',
endpoint: '接口路径',
tokenizer: '分词器',
tokenizerPlaceholder: '请选择或输入本地分词器目录,例如 /opt/1panel/tokenizers/DeepSeek-V3',
runConfig: '运行配置',
rawResult: '原始结果',
contextTokens: '上下文长度',
contextTokensHelper: '本次测试的输入 Token 与输出 Token 上限之和。',
outputThroughput: '输出吞吐',
outputThroughputHelper: '模型每秒生成的输出 Token 数,越高表示生成速度越快。',
totalThroughput: '总吞吐',
totalThroughputHelper: '每秒处理的输入与输出 Token 总数,用于衡量整体处理能力。',
firstTokenLatency: '首 Token 延迟',
firstTokenLatencyHelper: '从请求发出到收到第一个 Token 的时间,越低表示响应越快。',
inputTokens: '输入 Token',
outputTokens: '输出 Token',
numPrompts: '请求数量',
concurrency: '并发数',
requestRate: '请求速率',
requestRateUnlimited: '不限速(最大吞吐)',
requestRateCustom: '自定义 QPS',
requestRateCustomPlaceholder: '请输入每秒请求数,如 2.5',
timeout: '超时时间(秒)',
image: 'vLLM 镜像',
ignoreEos: '忽略 EOS',
extraHeaders: '额外请求头',
},
gpu: {
gpu: 'GPU 监控',
gpuHelper: '当前系统未检测到 NVIDIA-SMI 或 XPU-SMI 指令,请检查后重试!',