fix: align model availability and retail pricing controls
This commit is contained in:
1 parent
af505c5596
commit
813b406da4
9 files changed
+130
-47
No files matched your search
@@ -5,7 +5,9 @@ import { catalogClient, type CatalogProvider, type CatalogModel, type LogicalMod
|
||||
import UiModal from './UiModal.vue'
|
||||
import ListPagination from './ListPagination.vue'
|
||||
import { usePagination } from '../composables/usePagination'
|
||||
import { calculateTokenRetailPricing } from '../services/pricing'
|
||||
import { calculateTokenRetailPricing, editRetailAmounts, platformPriceLabel, standardPriceLabel } from '../services/pricing'
|
||||
|
||||
import { routeReadinessLabel, routeReadinessReason } from '../services/model-catalog'
|
||||
|
||||
const props = defineProps<{ section: 'models' | 'channels' }>()
|
||||
const emit = defineEmits<{ notify: [message: string] }>()
|
||||
@@ -30,7 +32,7 @@ async function remove() {
|
||||
}
|
||||
const channel = reactive({ code: '', name: '', protocol: 'openai-compatible' as CatalogProvider['protocol'], sourceType: 'relay' as CatalogProvider['sourceType'], baseUrl: '', credentialType: 'api-key' as NonNullable<CatalogProvider['credentialType']>, credentialSecret: '', description: '', status: 'active' as CatalogProvider['status'] })
|
||||
const model = reactive({ publicName: '', modelKey: '', vendorName: '', type: 'text' as LogicalModel['type'], mode: 'sync' as LogicalModel['mode'], description: '', inputTypes: 'text', outputTypes: 'text', status: 'active' as LogicalModel['status'] })
|
||||
const group = reactive({ logicalModelId: '', providerId: '', sourceLabel: '', upstreamModel: '', input: '', output: '', cachedInput: '', unit: 'CNY / 1M tokens', discount: '', discountLabel: '', exchangeRate: '', priceSource: '', listPriceInput: '', listPriceOutput: '', listPriceCachedInput: '', priority: '100', maxConcurrency: '0', status: 'active' as CatalogModel['status'] })
|
||||
const group = reactive({ logicalModelId: '', providerId: '', sourceLabel: '', upstreamModel: '', input: '', output: '', cachedInput: '', imageInput: '', price: '', unit: 'CNY / 1M tokens', discount: '', discountLabel: '', exchangeRate: '', priceSource: '', listPriceInput: '', listPriceOutput: '', listPriceCachedInput: '', priority: '100', maxConcurrency: '0', status: 'active' as CatalogModel['status'] })
|
||||
const listCurrency = ref<'USD' | 'CNY'>('USD')
|
||||
const originalPricing = ref<CatalogModel['pricing']>()
|
||||
const shownModels = computed(() => models.value.filter(item => `${item.publicName} ${item.vendorName || ''} ${item.modelKey || ''}`.toLowerCase().includes(query.value.toLowerCase())))
|
||||
@@ -70,6 +72,8 @@ function editGroup(parent: LogicalModel, item?: CatalogModel) {
|
||||
originalPricing.value = item?.pricing
|
||||
listCurrency.value = item?.pricing?.listPriceCny ? 'CNY' : 'USD'
|
||||
Object.assign(group, { logicalModelId: parent.id, providerId: item?.providerId || '', sourceLabel: item?.sourceLabel || '', upstreamModel: item?.upstreamModel || '', input: item?.pricing?.input?.toString() || '', output: item?.pricing?.output?.toString() || '', cachedInput: item?.pricing?.cachedInput?.toString() || '', unit: item?.pricing?.unit || 'CNY / 1M tokens', discount: item?.pricing?.discount?.toString() || '', discountLabel: item?.pricing?.discountLabel || '', exchangeRate: item?.pricing?.exchangeRate?.toString() || '', priceSource: item?.pricing?.priceSource || '', listPriceInput: item?.pricing?.listPriceUsd?.input?.toString() || '', listPriceOutput: item?.pricing?.listPriceUsd?.output?.toString() || '', listPriceCachedInput: item?.pricing?.listPriceUsd?.cachedInput?.toString() || '', priority: String(item?.priority ?? 100), maxConcurrency: String(item?.maxConcurrency ?? 0), status: item?.status || 'active' })
|
||||
group.price = item?.pricing?.price?.toString() ?? ''
|
||||
group.imageInput = item?.pricing?.imageInput?.toString() ?? ''
|
||||
const list = item?.pricing?.listPriceCny || item?.pricing?.listPriceUsd
|
||||
group.listPriceInput = list?.input?.toString() ?? ''
|
||||
group.listPriceOutput = list?.output?.toString() ?? ''
|
||||
@@ -87,8 +91,10 @@ function calculateRetail() {
|
||||
}
|
||||
|
||||
function groupPricing(): CatalogModel['pricing'] {
|
||||
if (!originalPricing.value && [group.input, group.output, group.cachedInput, group.imageInput, group.price].every(value => value === '')) return undefined
|
||||
const amounts = editRetailAmounts(originalPricing.value, group.unit, group)
|
||||
const list = group.listPriceInput === '' && group.listPriceOutput === '' && group.listPriceCachedInput === '' ? undefined : {input:group.listPriceInput === '' ? undefined : Number(group.listPriceInput),output:group.listPriceOutput === '' ? undefined : Number(group.listPriceOutput),cachedInput:group.listPriceCachedInput === '' ? undefined : Number(group.listPriceCachedInput)}
|
||||
return {...originalPricing.value,input:group.input === '' ? undefined : Number(group.input),output:group.output === '' ? undefined : Number(group.output),cachedInput:group.cachedInput === '' ? undefined : Number(group.cachedInput),unit:group.unit,discount:group.discount === '' ? undefined : Number(group.discount),discountLabel:group.discountLabel.trim() || undefined,exchangeRate:listCurrency.value === 'CNY' && list ? 1 : group.exchangeRate === '' ? undefined : Number(group.exchangeRate),priceSource:group.priceSource.trim() || undefined,listPriceUsd:listCurrency.value === 'USD' ? list : undefined,listPriceCny:listCurrency.value === 'CNY' ? list : undefined}
|
||||
return {...amounts,discount:group.discount === '' ? undefined : Number(group.discount),discountLabel:group.discountLabel.trim() || undefined,exchangeRate:listCurrency.value === 'CNY' && list ? 1 : group.exchangeRate === '' ? undefined : Number(group.exchangeRate),priceSource:group.priceSource.trim() || undefined,listPriceUsd:group.unit === 'CNY / 1M tokens' ? (listCurrency.value === 'USD' ? list : undefined) : originalPricing.value?.listPriceUsd,listPriceCny:group.unit === 'CNY / 1M tokens' ? (listCurrency.value === 'CNY' ? list : undefined) : originalPricing.value?.listPriceCny}
|
||||
}
|
||||
async function save() {
|
||||
if (saving.value) return
|
||||
@@ -139,7 +145,7 @@ async function toggle(kind: 'channel' | 'model' | 'group', item: CatalogProvider
|
||||
<section v-for="item in pagedModels" :key="item.id" class="model-definition-section">
|
||||
<header class="panel-header"><div><h3>{{ item.publicName }}</h3><small>{{ item.vendorName || '未标注厂商' }} · {{ item.modelKey || item.id }} · {{ item.type }} · {{ item.mode }}</small></div><div class="heading-actions"><label class="catalog-toggle"><input type="checkbox" :checked="item.status === 'active'" :disabled="saving" :aria-label="`${item.publicName} 启用`" @change="toggle('model', item)" />启用</label><button class="icon-button" :title="`编辑模型 ${item.publicName}`" @click="editModel(item)"><Pencil :size="16" /></button><button class="icon-button" :title="`删除模型 ${item.publicName}`" :disabled="saving" @click="confirmDelete('model', item.id, item.publicName)"><Trash2 :size="16" /></button><button class="button secondary small" @click="editGroup(item)"><Plus :size="15" />添加分组</button></div></header>
|
||||
<p v-if="item.description" class="catalog-secondary">{{ item.description }}</p>
|
||||
<div class="responsive-table"><table><thead><tr><th>分组名称</th><th>渠道</th><th>上游模型</th><th>输入 / 输出价格</th><th>对外折扣</th><th>并发</th><th>状态</th><th>操作</th></tr></thead><tbody><tr v-for="route in modelGroups(item.id)" :key="route.id"><td>{{ route.sourceLabel }}</td><td>{{ channelName(route.providerId) }}</td><td><code>{{ route.upstreamModel }}</code></td><td>{{ route.pricing?.input ?? '—' }} / {{ route.pricing?.output ?? '—' }}<small class="catalog-secondary">{{ route.pricing?.unit }}</small></td><td>{{ route.pricing?.discountLabel || '—' }}</td><td>{{ route.maxConcurrency === undefined || route.maxConcurrency === null || route.maxConcurrency === 0 ? '不限(由渠道限流)' : route.maxConcurrency }}</td><td><label class="catalog-toggle"><input type="checkbox" :checked="route.status === 'active'" :disabled="saving" :aria-label="`${route.sourceLabel} 启用`" @change="toggle('group', route)" />{{ route.status === 'active' ? '已启用' : '已停用' }}</label></td><td><button class="icon-button" :title="`编辑分组 ${route.sourceLabel}`" @click="editGroup(item, route)"><Pencil :size="16" /></button><button class="icon-button" :title="`删除分组 ${route.sourceLabel}`" :disabled="saving" @click="confirmDelete('group', route.id, route.sourceLabel || '默认分组')"><Trash2 :size="16" /></button></td></tr><tr v-if="!modelGroups(item.id).length"><td colspan="8">暂无分组</td></tr></tbody></table></div>
|
||||
<div class="responsive-table"><table><thead><tr><th>分组名称</th><th>渠道</th><th>上游模型</th><th>人民币售价 / 计费单位</th><th>对外折扣</th><th>并发</th><th>状态</th><th>操作</th></tr></thead><tbody><tr v-for="route in modelGroups(item.id)" :key="route.id"><td>{{ route.sourceLabel }}</td><td>{{ channelName(route.providerId) }}</td><td><code>{{ route.upstreamModel }}</code></td><td>{{ route.pricingConfigured ? platformPriceLabel(route.pricing) : routeReadinessLabel(route) }}<small v-if="routeReadinessReason(route)" class="catalog-secondary">{{ routeReadinessReason(route) }}</small></td><td>{{ route.pricing?.discountLabel || '—' }}</td><td>{{ route.maxConcurrency === undefined || route.maxConcurrency === null || route.maxConcurrency === 0 ? '不限(由渠道限流)' : route.maxConcurrency }}</td><td><label class="catalog-toggle"><input type="checkbox" :checked="route.status === 'active'" :disabled="saving" :aria-label="`${route.sourceLabel} 启用`" @change="toggle('group', route)" />{{ route.status === 'active' ? '已启用' : '已停用' }}</label><small class="catalog-secondary">{{ routeReadinessLabel(route) }}</small></td><td><button class="icon-button" :title="`编辑分组 ${route.sourceLabel}`" @click="editGroup(item, route)"><Pencil :size="16" /></button><button class="icon-button" :title="`删除分组 ${route.sourceLabel}`" :disabled="saving" @click="confirmDelete('group', route.id, route.sourceLabel || '默认分组')"><Trash2 :size="16" /></button></td></tr><tr v-if="!modelGroups(item.id).length"><td colspan="8">暂无分组</td></tr></tbody></table></div>
|
||||
</section>
|
||||
<p v-if="!shownModels.length && !loading">暂无模型</p>
|
||||
<ListPagination v-model:page="modelPage" v-model:page-size="modelPageSize" :total="shownModels.length" label="管理端模型分页" />
|
||||
@@ -172,17 +178,23 @@ async function toggle(kind: 'channel' | 'model' | 'group', item: CatalogProvider
|
||||
<label class="form-label" for="group-name">分组名称</label><input id="group-name" v-model="group.sourceLabel" class="text-input" required maxlength="160" />
|
||||
<label class="form-label" for="group-channel">渠道</label><select id="group-channel" v-model="group.providerId" class="text-input" required><option value="" disabled>请选择渠道</option><option v-for="item in channels" :key="item.id" :value="item.id">{{ item.name }}{{ item.status === 'disabled' ? '(已停用)' : '' }}</option></select>
|
||||
<label class="form-label" for="group-upstream">上游模型标识</label><input id="group-upstream" v-model="group.upstreamModel" class="text-input" required maxlength="160" />
|
||||
<div class="modal-form-grid"><label><span class="form-label">输入价格</span><input v-model="group.input" class="text-input" type="number" min="0" step="any" /></label><label><span class="form-label">输出价格</span><input v-model="group.output" class="text-input" type="number" min="0" step="any" /></label></div>
|
||||
<label class="form-label" for="group-unit">人民币售价计费单位</label><select id="group-unit" v-model="group.unit" class="text-input" required><option value="CNY / 1M tokens">元 / 1M(一百万 Token)</option><option value="CNY / image">元 / 张</option><option value="CNY / task">元 / 任务</option><option value="CNY / generation">元 / 次生成</option></select>
|
||||
<template v-if="group.unit === 'CNY / 1M tokens'">
|
||||
<div class="modal-form-grid"><label><span class="form-label">文字输入价格(元 / 百万 Token)</span><input v-model="group.input" class="text-input" type="number" min="0" step="any" /></label><label><span class="form-label">输出价格(元 / 百万 Token)</span><input v-model="group.output" class="text-input" type="number" min="0" step="any" /></label></div>
|
||||
<label class="form-label">缓存命中输入价格(留空按普通输入价格)<input v-model="group.cachedInput" class="text-input" type="number" min="0" step="any" /></label>
|
||||
<label class="form-label" for="group-unit">价格单位</label><input id="group-unit" v-model="group.unit" class="text-input" required />
|
||||
<label class="form-label">图像输入价格(元 / 百万 Token,可选)<input v-model="group.imageInput" class="text-input" type="number" min="0" step="any" /></label>
|
||||
</template>
|
||||
<template v-else><label class="form-label">单价({{ group.unit === 'CNY / image' ? '元 / 张' : group.unit === 'CNY / task' ? '元 / 任务' : '元 / 次生成' }})<input v-model="group.price" class="text-input" type="number" min="0" max="1000000" step="any" /></label><small>已记录标准价:{{ standardPriceLabel(originalPricing) }}</small></template>
|
||||
<template v-if="group.unit === 'CNY / 1M tokens'">
|
||||
<label class="form-label" for="list-currency">渠道标准价币种</label><select id="list-currency" v-model="listCurrency" class="text-input"><option value="CNY">人民币 CNY</option><option value="USD">美元 USD</option></select>
|
||||
<div class="modal-form-grid"><label><span class="form-label">标准输入价({{ listCurrency }} / 百万 Token)</span><input v-model="group.listPriceInput" class="text-input" type="number" min="0" step="any" /></label><label><span class="form-label">标准输出价({{ listCurrency }} / 百万 Token)</span><input v-model="group.listPriceOutput" class="text-input" type="number" min="0" step="any" /></label></div>
|
||||
<label class="form-label">标准缓存输入价({{ listCurrency }} / 百万 Token,可选)<input v-model="group.listPriceCachedInput" class="text-input" type="number" min="0" step="any" /></label>
|
||||
</template>
|
||||
<label class="form-label">对外折扣数值<input v-model="group.discount" class="text-input" type="number" min="0" max="10" step="0.1" placeholder="例如:5.6 表示 5.6 折" /></label>
|
||||
<label v-if="listCurrency === 'USD'" class="form-label">美元兑人民币汇率<input v-model="group.exchangeRate" class="text-input" type="number" min="0.00000001" step="any" /></label>
|
||||
<button v-if="group.unit === 'CNY / 1M tokens'" type="button" class="button secondary" @click="calculateRetail">按标准价和对外折扣换算售价</button>
|
||||
<small>1M Token=1,000,000 Token=一百万 Token。人民币原价不乘汇率;美元原价仅换算一次。采购 4.6 折加 1 个折扣点,对外填 5.6。</small>
|
||||
<label class="form-label" for="group-discount">对外折扣(仅展示)</label><input id="group-discount" v-model="group.discountLabel" class="text-input" maxlength="24" placeholder="例如:5.6折" /><small>输入、输出价格是实际扣费值,单位为 CNY / 1M tokens。折扣只用于向用户展示,不会替代人民币售价;留空表示不展示折扣。</small>
|
||||
<label class="form-label" for="group-discount">对外折扣(仅展示)</label><input id="group-discount" v-model="group.discountLabel" class="text-input" maxlength="24" placeholder="例如:5.6折" /><small>上方人民币售价是实际扣费值。折扣和汇率仅在点击换算时参与计算,保存不会再次打折或换汇。留空不代表免费,也不会自动开放尚未完成计费或执行接口接入的模型。</small>
|
||||
<div class="modal-form-grid"><label><span class="form-label">优先级</span><input v-model="group.priority" class="text-input" type="number" min="0" step="1" required /></label><label><span class="form-label">MOYI 分组并发上限</span><input v-model="group.maxConcurrency" class="text-input" type="number" min="0" step="1" required /><small>填 0 表示不设置平台分组上限,直接测量渠道方的真实并发;只有渠道明确给出共享上限时才填写正整数。</small></label></div>
|
||||
</template>
|
||||
</form>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import type { ModelItem } from '../types'
|
||||
import { setGroupSelection } from '../services/model-catalog'
|
||||
import { setGroupSelection, routeReadinessLabel } from '../services/model-catalog'
|
||||
import { usePagination } from '../composables/usePagination'
|
||||
import ListPagination from './ListPagination.vue'
|
||||
|
||||
@@ -36,9 +36,9 @@ function clear() { expanded.value = []; emit('update:modelValue', []) }
|
||||
|
||||
<template>
|
||||
<div class="group-permissions">
|
||||
<p>可同时选择多个模型,再勾选各模型可调用的分组。搜索或翻页会保留已选权限。</p>
|
||||
<p>可同时选择多个模型,再勾选各模型可调用的分组。搜索或翻页会保留已选权限。授权不代表可立即调用,实际可用性以分组状态为准。</p>
|
||||
<section v-if="modelValue.length" class="selected-summary" aria-label="已选模型与分组">
|
||||
<strong>已选 {{ selectedCount }} 个模型 · {{ selectedGroups.length }} 个可用分组<span v-if="unavailable.length"> · {{ unavailable.length }} 个暂不可用授权</span></strong>
|
||||
<strong>已选 {{ selectedCount }} 个模型 · {{ selectedGroups.length }} 个已选分组<span v-if="unavailable.length"> · {{ unavailable.length }} 个暂不可用授权</span></strong>
|
||||
<div class="selected-tags"><button v-for="group in selectedGroups" :key="group.id" type="button" :disabled="disabled" :aria-label="`移除 ${group.name} / ${group.sourceLabel || '默认分组'}`" @click="toggle([group.id], false)">{{ group.name }} / {{ group.sourceLabel || '默认分组' }} ×</button></div>
|
||||
</section>
|
||||
<label class="permission-search">搜索模型或分组<input v-model="query" class="text-input" placeholder="模型名称、厂商、渠道或分组" :disabled="disabled" /></label>
|
||||
@@ -46,11 +46,11 @@ function clear() { expanded.value = []; emit('update:modelValue', []) }
|
||||
<div class="permission-list">
|
||||
<section v-for="model in pagedItems" :key="model.id" class="permission-model">
|
||||
<label class="model-choice"><input type="checkbox" :checked="modelChecked(model.id)" :disabled="disabled" @change="selectModel(model.id, ($event.target as HTMLInputElement).checked)" /><span><strong>{{ model.name }}</strong><small>{{ model.vendorName || '未标注厂商' }} · {{ model.groups.filter(group => modelValue.includes(group.id)).length }} / {{ model.groups.length }} 个分组已选</small></span></label>
|
||||
<fieldset v-if="modelChecked(model.id)" :disabled="disabled"><legend>{{ model.name }} 的可调用分组</legend>
|
||||
<fieldset v-if="modelChecked(model.id)" :disabled="disabled"><legend>{{ model.name }} 的分组权限</legend>
|
||||
<p v-if="!model.groups.some(group => modelValue.includes(group.id))">请选择至少一个分组以授权该模型。</p>
|
||||
<label v-for="group in model.groups" :key="group.id" class="group-option">
|
||||
<input type="checkbox" :checked="modelValue.includes(group.id)" @change="toggle([group.id], ($event.target as HTMLInputElement).checked)" />
|
||||
<span><strong>{{ group.sourceLabel || '默认分组' }}</strong><small>{{ group.provider }} · {{ group.mode }}</small></span>
|
||||
<span><strong>{{ group.sourceLabel || '默认分组' }}</strong><small>{{ group.provider }} · {{ group.mode }} · {{ routeReadinessLabel(group) }}</small></span>
|
||||
</label>
|
||||
</fieldset>
|
||||
</section>
|
||||
|
||||
Reference in new issue
Block a user