163 lines
5.8 KiB
Vue
163 lines
5.8 KiB
Vue
<script setup lang="ts">
|
||
import type { ModelPlan, ModelProvider } from '#/api/console';
|
||
|
||
import { computed, onMounted, reactive, ref } from 'vue';
|
||
|
||
import { useAccess } from '@vben/access';
|
||
|
||
import { Alert, Button, Card, Descriptions, DescriptionsItem, Form, FormItem, message, Select, Tag } from 'ant-design-vue';
|
||
|
||
import { fetchModels, saveModelPlan } from '#/api/console';
|
||
|
||
const { hasAccessByCodes } = useAccess();
|
||
const canWrite = computed(() => hasAccessByCodes(['model:write']));
|
||
|
||
const loading = ref(false);
|
||
const models = ref<ModelProvider[]>([]);
|
||
const current = ref<ModelPlan | null>(null);
|
||
const judgeModes = ref<string[]>([]);
|
||
|
||
const form = reactive({
|
||
answer_ids: [] as string[],
|
||
judge_id: '',
|
||
vision_id: '',
|
||
fallback_ids: [] as string[],
|
||
judge_mode: 'shadow',
|
||
});
|
||
|
||
/** ComfyUI 当不了对话候选,选项里直接不给——省得配完了发现不生效。 */
|
||
const chatOptions = computed(() =>
|
||
models.value
|
||
.filter((item) => item.kind !== 'comfyui' && item.enabled)
|
||
.map((item) => ({ value: item.id, label: `${item.name}(${item.kind})` })),
|
||
);
|
||
|
||
const visionOptions = computed(() =>
|
||
chatOptions.value.filter((option) =>
|
||
models.value
|
||
.find((item) => item.id === option.value)
|
||
?.capabilities.includes('vision'),
|
||
),
|
||
);
|
||
|
||
const MODE_HELP: Record<string, string> = {
|
||
shadow:
|
||
'照常发主模型的回复,裁判只打分、不参与挑选答案;被判高风险的回复仍转人工审核(1.5.2 及更早的桌面端不会)。先量出现有回复的真实水平,再决定要不要花第二份钱。',
|
||
score_only:
|
||
'裁判打绝对分并标风险,高风险转人工审核;不做二选一,不改变答案选择。',
|
||
arbitrate:
|
||
'完整的 best-of-N:并发问多个模型,按裁判选出的赢家发送,高风险同样转人工审核。成本约 2.3 倍。',
|
||
};
|
||
|
||
async function load() {
|
||
loading.value = true;
|
||
try {
|
||
const data = await fetchModels();
|
||
models.value = data.models;
|
||
judgeModes.value = data.judge_modes;
|
||
current.value = data.roles;
|
||
const split = (value: string) =>
|
||
(value || '').split(',').map((s) => s.trim()).filter(Boolean);
|
||
Object.assign(form, {
|
||
answer_ids: split(data.roles.answer_ids),
|
||
fallback_ids: split(data.roles.fallback_ids),
|
||
judge_id: data.roles.judge_id || '',
|
||
vision_id: data.roles.vision_id || '',
|
||
judge_mode: data.roles.judge_mode || 'shadow',
|
||
});
|
||
} finally {
|
||
loading.value = false;
|
||
}
|
||
}
|
||
|
||
async function submit() {
|
||
if (form.answer_ids.length === 0) {
|
||
message.warning('至少要指定一个答题模型');
|
||
return;
|
||
}
|
||
const data = await saveModelPlan({
|
||
answer_ids: form.answer_ids.join(','),
|
||
judge_id: form.judge_id,
|
||
vision_id: form.vision_id,
|
||
fallback_ids: form.fallback_ids.join(','),
|
||
judge_mode: form.judge_mode,
|
||
});
|
||
current.value = data.roles;
|
||
message.success(`已保存为 v${data.version},网关 20 秒内自动生效`);
|
||
}
|
||
|
||
onMounted(load);
|
||
</script>
|
||
|
||
<template>
|
||
<div class="p-5">
|
||
<Alert
|
||
class="mb-4"
|
||
type="warning"
|
||
show-icon
|
||
message="编排是追加版本,不是原地修改"
|
||
description="每次保存都产生一个新版本号,回滚就是指回旧版本。网关每 20 秒重读一次,不用重启。"
|
||
/>
|
||
|
||
<Card title="当前生效的编排" class="mb-4" :loading="loading">
|
||
<Descriptions v-if="current" :column="2" size="small" bordered>
|
||
<DescriptionsItem label="版本">v{{ current.version }}</DescriptionsItem>
|
||
<DescriptionsItem label="裁判模式">
|
||
<Tag :color="current.judge_mode === 'arbitrate' ? 'red' : current.judge_mode === 'score_only' ? 'orange' : 'blue'">
|
||
{{ current.judge_mode }}
|
||
</Tag>
|
||
</DescriptionsItem>
|
||
<DescriptionsItem label="答题模型">{{ current.answer_ids || '—' }}</DescriptionsItem>
|
||
<DescriptionsItem label="裁判模型">{{ current.judge_id || '—' }}</DescriptionsItem>
|
||
</Descriptions>
|
||
</Card>
|
||
|
||
<Card title="修改编排">
|
||
<Form :model="form" layout="vertical">
|
||
<FormItem label="答题模型(多选 = 并发提问,按顺序第一个是主模型)">
|
||
<Select
|
||
v-model:value="form.answer_ids" mode="multiple"
|
||
:options="chatOptions" :disabled="!canWrite"
|
||
placeholder="至少选一个"
|
||
/>
|
||
<p v-if="form.answer_ids.length > 1" class="mt-1 text-xs text-orange-500">
|
||
选了 {{ form.answer_ids.length }} 个 = 每条回复都要付 {{ form.answer_ids.length }} 份生成费用。
|
||
建议先跑一段影子模式,用调用统计里的分数分布判断值不值。
|
||
</p>
|
||
</FormItem>
|
||
|
||
<FormItem label="裁判模型(给回复打绝对分和风险等级)">
|
||
<Select
|
||
v-model:value="form.judge_id" :options="chatOptions"
|
||
:disabled="!canWrite" allow-clear placeholder="不选则不做评审"
|
||
/>
|
||
</FormItem>
|
||
|
||
<FormItem label="裁判模式">
|
||
<Select
|
||
v-model:value="form.judge_mode" :disabled="!canWrite"
|
||
:options="judgeModes.map((m) => ({ value: m, label: m }))"
|
||
/>
|
||
<p class="mt-1 text-xs text-gray-500">{{ MODE_HELP[form.judge_mode] }}</p>
|
||
</FormItem>
|
||
|
||
<FormItem label="媒体消息专用模型(需具备视觉能力,留空则从答题池里挑)">
|
||
<Select
|
||
v-model:value="form.vision_id" :options="visionOptions"
|
||
:disabled="!canWrite" allow-clear
|
||
/>
|
||
</FormItem>
|
||
|
||
<FormItem label="降级链(主链全挂时按顺序尝试)">
|
||
<Select
|
||
v-model:value="form.fallback_ids" mode="multiple"
|
||
:options="chatOptions" :disabled="!canWrite"
|
||
/>
|
||
</FormItem>
|
||
|
||
<Button v-if="canWrite" type="primary" @click="submit">保存为新版本</Button>
|
||
</Form>
|
||
</Card>
|
||
</div>
|
||
</template>
|