mirror of
https://github.com/CJackHwang/ds2api.git
synced 2026-05-10 11:17:41 +08:00
feat: add compatibility setting to strip reference markers from model output and update stream handlers accordingly
This commit is contained in:
34
webui/src/features/settings/CompatibilitySection.jsx
Normal file
34
webui/src/features/settings/CompatibilitySection.jsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import { ShieldAlert } from 'lucide-react'
|
||||
|
||||
export default function CompatibilitySection({ t, form, setForm }) {
|
||||
return (
|
||||
<div className="bg-card border border-border rounded-xl p-5 space-y-4">
|
||||
<div className="flex items-center gap-2">
|
||||
<ShieldAlert className="w-4 h-4 text-muted-foreground" />
|
||||
<h3 className="font-semibold">{t('settings.compatibilityTitle')}</h3>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">{t('settings.compatibilityDesc')}</p>
|
||||
<div className="flex items-center justify-between gap-4">
|
||||
<label className="text-sm font-medium">{t('settings.stripReferenceMarkers')}</label>
|
||||
<button
|
||||
type="button"
|
||||
role="switch"
|
||||
aria-checked={form.compat?.strip_reference_markers ?? true}
|
||||
onClick={() => setForm((prev) => ({
|
||||
...prev,
|
||||
compat: { ...prev.compat, strip_reference_markers: !Boolean(prev.compat?.strip_reference_markers ?? true) },
|
||||
}))}
|
||||
className={`relative inline-flex h-6 w-11 items-center rounded-full transition-colors ${
|
||||
form.compat?.strip_reference_markers ?? true ? 'bg-primary' : 'bg-muted'
|
||||
}`}
|
||||
>
|
||||
<span
|
||||
className={`inline-block h-4 w-4 transform rounded-full bg-white transition-transform ${
|
||||
form.compat?.strip_reference_markers ?? true ? 'translate-x-6' : 'translate-x-1'
|
||||
}`}
|
||||
/>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import { useSettingsForm } from './useSettingsForm'
|
||||
import SecuritySection from './SecuritySection'
|
||||
import RuntimeSection from './RuntimeSection'
|
||||
import BehaviorSection from './BehaviorSection'
|
||||
import CompatibilitySection from './CompatibilitySection'
|
||||
import AutoDeleteSection from './AutoDeleteSection'
|
||||
import ModelSection from './ModelSection'
|
||||
import BackupSection from './BackupSection'
|
||||
@@ -94,6 +95,8 @@ export default function SettingsContainer({ onRefresh, onMessage, authFetch, onF
|
||||
|
||||
<BehaviorSection t={t} form={form} setForm={setForm} />
|
||||
|
||||
<CompatibilitySection t={t} form={form} setForm={setForm} />
|
||||
|
||||
<AutoDeleteSection t={t} form={form} setForm={setForm} />
|
||||
|
||||
<ModelSection t={t} form={form} setForm={setForm} />
|
||||
|
||||
@@ -13,6 +13,7 @@ const MAX_AUTO_FETCH_FAILURES = 3
|
||||
const DEFAULT_FORM = {
|
||||
admin: { jwt_expire_hours: 24 },
|
||||
runtime: { account_max_inflight: 2, account_max_queue: 10, global_max_inflight: 10, token_refresh_interval_hours: 6 },
|
||||
compat: { strip_reference_markers: true },
|
||||
responses: { store_ttl_seconds: 900 },
|
||||
embeddings: { provider: '' },
|
||||
auto_delete: { sessions: false },
|
||||
@@ -46,6 +47,9 @@ function fromServerForm(data) {
|
||||
global_max_inflight: Number(data.runtime?.global_max_inflight || 10),
|
||||
token_refresh_interval_hours: Number(data.runtime?.token_refresh_interval_hours || 6),
|
||||
},
|
||||
compat: {
|
||||
strip_reference_markers: data.compat?.strip_reference_markers ?? true,
|
||||
},
|
||||
responses: {
|
||||
store_ttl_seconds: Number(data.responses?.store_ttl_seconds || 900),
|
||||
},
|
||||
@@ -69,6 +73,9 @@ function toServerPayload(form) {
|
||||
global_max_inflight: Number(form.runtime.global_max_inflight),
|
||||
token_refresh_interval_hours: Number(form.runtime.token_refresh_interval_hours),
|
||||
},
|
||||
compat: {
|
||||
strip_reference_markers: Boolean(form.compat?.strip_reference_markers ?? true),
|
||||
},
|
||||
responses: { store_ttl_seconds: Number(form.responses.store_ttl_seconds) },
|
||||
embeddings: { provider: String(form.embeddings.provider || '').trim() },
|
||||
auto_delete: { sessions: Boolean(form.auto_delete?.sessions) },
|
||||
|
||||
@@ -236,6 +236,9 @@
|
||||
"behaviorTitle": "Behavior",
|
||||
"responsesTTL": "Responses store TTL (seconds)",
|
||||
"embeddingsProvider": "Embeddings provider",
|
||||
"compatibilityTitle": "Compatibility",
|
||||
"compatibilityDesc": "Compatibility controls that keep stream output closer to the wire format or safer for the web UI.",
|
||||
"stripReferenceMarkers": "Strip [reference:N] markers",
|
||||
"modelTitle": "Model mapping",
|
||||
"claudeMapping": "Claude mapping (JSON)",
|
||||
"modelAliases": "Model aliases (JSON)",
|
||||
|
||||
@@ -236,6 +236,9 @@
|
||||
"behaviorTitle": "行为设置",
|
||||
"responsesTTL": "Responses 缓存 TTL(秒)",
|
||||
"embeddingsProvider": "Embeddings Provider",
|
||||
"compatibilityTitle": "兼容性设置",
|
||||
"compatibilityDesc": "用于控制输出格式兼容性,避免把模型原始流里的标记直接暴露到前端。",
|
||||
"stripReferenceMarkers": "移除 [reference:N] 标记",
|
||||
"modelTitle": "模型映射",
|
||||
"claudeMapping": "Claude 映射(JSON)",
|
||||
"modelAliases": "模型别名(JSON)",
|
||||
|
||||
Reference in New Issue
Block a user