refactor: make stream smoothing parameters configurable and add models cache invalidation

- Move stream smoothing parameters (chunk_size, delay_ms) to database config
- Remove hardcoded stream smoothing constants from StreamProcessor
- Simplify dynamic delay calculation by using config values directly
- Add invalidate_models_list_cache() function to clear /v1/models endpoint cache
- Call cache invalidation on model create, update, delete, and bulk operations
- Update admin UI to allow runtime configuration of smoothing parameters
- Improve model listing freshness when models are modified
This commit is contained in:
fawney19
2025-12-19 11:03:46 +08:00
parent 912f6643e2
commit 97425ac68f
8 changed files with 150 additions and 90 deletions

View File

@@ -470,20 +470,68 @@
title="流式输出"
description="配置流式响应的输出效果"
>
<div class="flex items-center space-x-2">
<Checkbox
id="stream-smoothing-enabled"
v-model:checked="systemConfig.stream_smoothing_enabled"
/>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div class="md:col-span-2">
<div class="flex items-center space-x-2">
<Checkbox
id="stream-smoothing-enabled"
v-model:checked="systemConfig.stream_smoothing_enabled"
/>
<div>
<Label
for="stream-smoothing-enabled"
class="cursor-pointer"
>
启用平滑输出
</Label>
<p class="text-xs text-muted-foreground">
将上游返回的大块内容拆分成小块模拟打字效果
</p>
</div>
</div>
</div>
<div>
<Label
for="stream-smoothing-enabled"
class="cursor-pointer"
for="stream-smoothing-chunk-size"
class="block text-sm font-medium"
>
启用平滑输出
每块字符数
</Label>
<p class="text-xs text-muted-foreground">
自动根据文本长度调整输出速度短文本逐字符输出打字感更强长文本按块输出避免卡顿
<Input
id="stream-smoothing-chunk-size"
v-model.number="systemConfig.stream_smoothing_chunk_size"
type="number"
min="1"
max="100"
placeholder="20"
class="mt-1"
:disabled="!systemConfig.stream_smoothing_enabled"
/>
<p class="mt-1 text-xs text-muted-foreground">
每次输出的字符数量1-100
</p>
</div>
<div>
<Label
for="stream-smoothing-delay-ms"
class="block text-sm font-medium"
>
输出间隔 (毫秒)
</Label>
<Input
id="stream-smoothing-delay-ms"
v-model.number="systemConfig.stream_smoothing_delay_ms"
type="number"
min="1"
max="100"
placeholder="8"
class="mt-1"
:disabled="!systemConfig.stream_smoothing_enabled"
/>
<p class="mt-1 text-xs text-muted-foreground">
每块之间的延迟毫秒数1-100
</p>
</div>
</div>
@@ -838,6 +886,8 @@ interface SystemConfig {
audit_log_retention_days: number
// 流式输出
stream_smoothing_enabled: boolean
stream_smoothing_chunk_size: number
stream_smoothing_delay_ms: number
}
const loading = ref(false)
@@ -889,6 +939,8 @@ const systemConfig = ref<SystemConfig>({
audit_log_retention_days: 30,
// 流式输出
stream_smoothing_enabled: false,
stream_smoothing_chunk_size: 20,
stream_smoothing_delay_ms: 8,
})
// 计算属性KB 和 字节 之间的转换
@@ -947,6 +999,8 @@ async function loadSystemConfig() {
'audit_log_retention_days',
// 流式输出
'stream_smoothing_enabled',
'stream_smoothing_chunk_size',
'stream_smoothing_delay_ms',
]
for (const key of configs) {
@@ -1060,6 +1114,16 @@ async function saveSystemConfig() {
value: systemConfig.value.stream_smoothing_enabled,
description: '是否启用流式平滑输出'
},
{
key: 'stream_smoothing_chunk_size',
value: systemConfig.value.stream_smoothing_chunk_size,
description: '流式平滑输出每个小块的字符数'
},
{
key: 'stream_smoothing_delay_ms',
value: systemConfig.value.stream_smoothing_delay_ms,
description: '流式平滑输出每个小块之间的延迟毫秒数'
},
]
const promises = configItems.map(item =>