fix(rate-limits): treat empty policies as unlimited
This commit is contained in:
@@ -270,9 +270,9 @@ export function RuntimePoliciesPanel(props: {
|
||||
<section className="runtimePolicySection spanTwo">
|
||||
<header><strong>限流策略</strong><span>TPM / RPM / 并发</span></header>
|
||||
<div className="runtimePolicyRows">
|
||||
<Label>RPM / 分钟请求<Input value={form.rpm} inputMode="numeric" onChange={(event) => setForm({ ...form, rpm: event.target.value })} /></Label>
|
||||
<Label>TPM / 分钟 Token<Input value={form.tpm} inputMode="numeric" onChange={(event) => setForm({ ...form, tpm: event.target.value })} /></Label>
|
||||
<Label>并发请求<Input value={form.concurrency} inputMode="numeric" onChange={(event) => setForm({ ...form, concurrency: event.target.value })} /></Label>
|
||||
<Label>RPM / 分钟请求<Input value={form.rpm} placeholder="不填或负数为不限" inputMode="numeric" onChange={(event) => setForm({ ...form, rpm: event.target.value })} /></Label>
|
||||
<Label>TPM / 分钟 Token<Input value={form.tpm} placeholder="不填或负数为不限" inputMode="numeric" onChange={(event) => setForm({ ...form, tpm: event.target.value })} /></Label>
|
||||
<Label>并发请求<Input value={form.concurrency} placeholder="不填或负数为不限" inputMode="numeric" onChange={(event) => setForm({ ...form, concurrency: event.target.value })} /></Label>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -760,9 +760,9 @@ function policyToForm(policy: RuntimePolicySet): RuntimePolicyForm {
|
||||
policyKey: policy.policyKey,
|
||||
name: policy.name,
|
||||
description: policy.description ?? '',
|
||||
rpm: String(readRateLimit(rateRules, 'rpm') || ''),
|
||||
tpm: String(readRateLimit(rateRules, 'tpm_total') || ''),
|
||||
concurrency: String(readRateLimit(rateRules, 'concurrent') || ''),
|
||||
rpm: formRateLimitText(readRateLimit(rateRules, 'rpm')),
|
||||
tpm: formRateLimitText(readRateLimit(rateRules, 'tpm_total')),
|
||||
concurrency: formRateLimitText(readRateLimit(rateRules, 'concurrent')),
|
||||
retryEnabled: readBool(retry.enabled, true),
|
||||
retryMaxAttempts: String(readNumber(retry.maxAttempts, 2)),
|
||||
retryAllowKeywords: tagsFromValue(retry.allowKeywords),
|
||||
@@ -825,9 +825,9 @@ function isDefaultPolicy(policy: RuntimePolicySet) {
|
||||
|
||||
function rateLimitSummary(policy: RuntimePolicySet) {
|
||||
const rules = Array.isArray(policy.rateLimitPolicy?.rules) ? policy.rateLimitPolicy.rules : [];
|
||||
const rpm = readRateLimit(rules, 'rpm') || '-';
|
||||
const tpm = readRateLimit(rules, 'tpm_total') || '-';
|
||||
const concurrent = readRateLimit(rules, 'concurrent') || '-';
|
||||
const rpm = rateLimitText(readRateLimit(rules, 'rpm'));
|
||||
const tpm = rateLimitText(readRateLimit(rules, 'tpm_total'));
|
||||
const concurrent = rateLimitText(readRateLimit(rules, 'concurrent'));
|
||||
return `RPM ${rpm} / TPM ${tpm} / 并发 ${concurrent}`;
|
||||
}
|
||||
|
||||
@@ -848,7 +848,16 @@ function degradeSummary(policy: RuntimePolicySet) {
|
||||
|
||||
function readRateLimit(rules: unknown[], metric: string) {
|
||||
const rule = rules.find((item) => readObject(item).metric === metric);
|
||||
return readNumber(readObject(rule).limit, 0);
|
||||
const limit = Number(readObject(rule).limit);
|
||||
return Number.isFinite(limit) ? limit : undefined;
|
||||
}
|
||||
|
||||
function formRateLimitText(value: number | undefined) {
|
||||
return value === undefined ? '' : String(value);
|
||||
}
|
||||
|
||||
function rateLimitText(value: number | undefined) {
|
||||
return value !== undefined && value > 0 ? String(value) : '不限';
|
||||
}
|
||||
|
||||
function stringifyKeywords(value: unknown) {
|
||||
|
||||
Reference in New Issue
Block a user