fix: show task model list prices accurately
This commit is contained in:
1 parent
b2266d7e9d
commit
b455d8d79f
9 files changed
+165
-30
No files matched your search
@@ -39,6 +39,7 @@ import {
|
||||
import type { ApiKeyItem, CallMode, ModelItem, ModelType, TaskItem, TaskStatus } from '../types'
|
||||
import { catalogClient, platformApiBaseUrl, type AsyncTaskResult, type CatalogApiKey, type CatalogModel, type LogicalModel, type CatalogProject, type PlatformOverview, type UserUsageRecord } from '../services/catalog'
|
||||
import { buildModelCatalog } from '../services/model-catalog'
|
||||
import { groupDiscountLabel as formatGroupDiscountLabel, modelStandardPriceLabel, platformPriceLabel } from '../services/pricing'
|
||||
import { usePagination } from '../composables/usePagination'
|
||||
import ListPagination from '../components/ListPagination.vue'
|
||||
import { copyText, type CopyResult } from '../services/clipboard'
|
||||
@@ -212,36 +213,21 @@ const recentTasks = computed(() => tasks.value.slice(0, 3))
|
||||
const modelTypes: Array<'全部' | ModelType> = ['全部', '文本', '多模态', '图像', '3D', '视频', '音频']
|
||||
const callModes: Array<'全部' | CallMode> = ['全部', '同步', '流式', '异步']
|
||||
|
||||
function formatUsdPrice(value: number | undefined) {
|
||||
if (value === undefined || value === null) return '待配置'
|
||||
return `$${value.toLocaleString('en-US', { maximumFractionDigits: 6 })}`
|
||||
function standardPriceLabel(model: GalleryModel) {
|
||||
return modelStandardPriceLabel(model.groups.map(group => group.pricing))
|
||||
}
|
||||
|
||||
function standardPriceLabel(model: GalleryModel) {
|
||||
const pricing = model.groups.find(group => group.pricing?.listPriceUsd)?.pricing
|
||||
if (!pricing?.listPriceUsd) {
|
||||
const unit = pricing?.unit
|
||||
const price = pricing?.price ?? pricing?.input
|
||||
return unit && price !== undefined ? `¥${Number(price).toLocaleString('zh-CN', { maximumFractionDigits: 8 })} / ${unit}` : '标准价待同步'
|
||||
}
|
||||
return `${formatUsdPrice(pricing.listPriceUsd.input)} 输入 / ${formatUsdPrice(pricing.listPriceUsd.output)} 输出 · USD / 1M`
|
||||
function groupStandardPriceLabel(group: ModelItem) {
|
||||
return modelStandardPriceLabel([group.pricing])
|
||||
}
|
||||
|
||||
function groupDiscountLabel(group: ModelItem) {
|
||||
if (!group.pricingConfigured || !group.pricing) return '价格待配置'
|
||||
return group.pricing.discountLabel || '折扣待配置'
|
||||
return formatGroupDiscountLabel(group.pricing, group.pricingConfigured)
|
||||
}
|
||||
|
||||
function groupPriceLabel(group: ModelItem) {
|
||||
const pricing = group.pricing
|
||||
if (!group.pricingConfigured || !pricing) return '当前不可调用:价格待配置'
|
||||
if (pricing.unit && !String(pricing.unit).toLowerCase().includes('token')) {
|
||||
const price = pricing.price ?? pricing.input
|
||||
return price === undefined ? `计费单位:${pricing.unit}` : `¥${Number(price).toLocaleString('zh-CN', { maximumFractionDigits: 8 })} / ${pricing.unit}`
|
||||
}
|
||||
const input = pricing.input === undefined ? '待定' : `¥${pricing.input.toLocaleString('zh-CN', { maximumFractionDigits: 8 })}`
|
||||
const output = pricing.output === undefined ? '待定' : `¥${pricing.output.toLocaleString('zh-CN', { maximumFractionDigits: 8 })}`
|
||||
return `${input} 输入 / ${output} 输出 · ${pricing.unit || 'CNY / 1M tokens'}`
|
||||
if (!group.pricingConfigured || !group.pricing) return '当前不可调用:价格待配置'
|
||||
return platformPriceLabel(group.pricing)
|
||||
}
|
||||
|
||||
function hasCallableGroup(model: GalleryModel) {
|
||||
@@ -615,7 +601,7 @@ async function createProject() {
|
||||
<template v-else-if="view === 'models'">
|
||||
<section class="page-heading"><div><span>MODEL CATALOG</span><h1>模型广场</h1><p>按能力选择模型,用一个 Key 完成接入。</p></div><button class="button secondary" @click="emit('navigate', 'docs')"><BookOpen :size="16" />接入指南</button></section>
|
||||
<section class="model-filter-panel"><div class="model-filter-head"><div><strong>筛选模型</strong><span>模型厂商是实际研发方,供应商是请求经过的渠道或中转站</span></div><button v-if="activeModelFilters.length || modelQuery" class="text-link" @click="resetModelFilters">清空筛选</button></div><div class="model-filter-grid"><label class="search-input model-filter-search"><Search :size="16" /><input v-model="modelQuery" placeholder="搜索模型名称、厂商、渠道或能力" /></label><label class="select-filter"><span>模型厂商</span><select v-model="modelVendor"><option value="全部">全部模型厂商</option><option v-for="vendor in modelVendors" :key="vendor" :value="vendor">{{ vendor }}</option></select></label><label class="select-filter"><span>供应商 / 渠道</span><select v-model="modelProvider"><option value="全部">全部渠道</option><option v-for="provider in modelProviders" :key="provider" :value="provider">{{ provider }}</option></select></label><label class="select-filter"><span>模型类型</span><select v-model="modelType"><option v-for="type in modelTypes" :key="type" :value="type">{{ type === '全部' ? '全部类型' : type }}</option></select></label><label class="select-filter"><span>调用方式</span><select v-model="modelMode"><option v-for="mode in callModes" :key="mode" :value="mode">{{ mode === '全部' ? '全部方式' : mode }}</option></select></label><label class="select-filter"><span>可用状态</span><select v-model="modelAvailability"><option value="全部">全部状态</option><option value="在线">在线</option><option value="待上线">待上线</option></select></label></div><div class="filter-summary"><span>共 {{ filteredModels.length }} 个模型</span><span v-if="activeModelFilters.length">已选:{{ activeModelFilters.join(' · ') }}</span></div></section>
|
||||
<section class="model-grid catalog"><article v-for="model in pagedModels" :key="model.id" class="model-card catalog-card" @click="selectedModel = model"><div class="model-card-top"><span class="model-icon" :class="model.accent"><component :is="model.icon" :size="21" /></span><span class="availability" :class="{ pending: !hasCallableGroup(model) }"><i></i>{{ modelAvailabilityLabel(model) }}</span></div><div class="model-title"><h3>{{ model.name }}</h3><span>{{ model.type }}</span></div><small class="provider"><strong>{{ model.vendorName || '未标注厂商' }}</strong><span>渠道:{{ model.provider }}</span><span v-if="model.sourceLabel"> · {{ model.sourceLabel }}</span></small><p>{{ model.description }}</p><div class="model-pricing"><span><strong>标准价</strong>{{ standardPriceLabel(model) }}</span><span><strong>分组折扣</strong><template v-if="model.groups.length"><em v-for="group in model.groups" :key="group.id">{{ group.sourceLabel || '默认分组' }}:{{ groupDiscountLabel(group) }}</em></template><em v-else>暂无上线分组</em></span></div><div class="model-specs"><span><Timer :size="14" />{{ model.latency }}</span><span><Layers3 :size="14" />{{ model.specification }}</span></div><footer><span class="mode-tag" :class="{ async: model.mode === '异步' }">{{ model.mode }}调用</span><button class="text-link" :disabled="!hasCallableGroup(model)" @click.stop="tryModel(model)">{{ !model.groups.length ? '分组待上线' : hasCallableGroup(model) ? `在线试用 · ${model.groups.length} 个分组` : modelUnavailableLabel(model) }}<ArrowRight :size="14" /></button></footer></article><div v-if="!filteredModels.length" class="empty-state"><Search :size="24" /><strong>没有找到匹配模型</strong><span>换个关键词或筛选条件试试</span></div></section>
|
||||
<section class="model-grid catalog"><article v-for="model in pagedModels" :key="model.id" class="model-card catalog-card" @click="selectedModel = model"><div class="model-card-top"><span class="model-icon" :class="model.accent"><component :is="model.icon" :size="21" /></span><span class="availability" :class="{ pending: !hasCallableGroup(model) }"><i></i>{{ modelAvailabilityLabel(model) }}</span></div><div class="model-title"><h3>{{ model.name }}</h3><span>{{ model.type }}</span></div><small class="provider"><strong>{{ model.vendorName || '未标注厂商' }}</strong><span>渠道:{{ model.provider }}</span><span v-if="model.sourceLabel"> · {{ model.sourceLabel }}</span></small><p>{{ model.description }}</p><div class="model-pricing"><span><strong>标准价</strong>{{ standardPriceLabel(model) }}</span><span><strong>分组售价 / 折扣</strong><template v-if="model.groups.length"><em v-for="group in model.groups" :key="group.id">{{ group.sourceLabel || '默认分组' }}:{{ groupPriceLabel(group) }} · {{ groupDiscountLabel(group) }}</em></template><em v-else>暂无上线分组</em></span></div><div class="model-specs"><span><Timer :size="14" />{{ model.latency }}</span><span><Layers3 :size="14" />{{ model.specification }}</span></div><footer><span class="mode-tag" :class="{ async: model.mode === '异步' }">{{ model.mode }}调用</span><button class="text-link" :disabled="!hasCallableGroup(model)" @click.stop="tryModel(model)">{{ !model.groups.length ? '分组待上线' : hasCallableGroup(model) ? `在线试用 · ${model.groups.length} 个分组` : modelUnavailableLabel(model) }}<ArrowRight :size="14" /></button></footer></article><div v-if="!filteredModels.length" class="empty-state"><Search :size="24" /><strong>没有找到匹配模型</strong><span>换个关键词或筛选条件试试</span></div></section>
|
||||
<ListPagination v-model:page="modelPage" v-model:page-size="modelPageSize" :total="filteredModels.length" label="模型广场分页" />
|
||||
</template>
|
||||
|
||||
@@ -773,7 +759,7 @@ $env:OPENAI_API_KEY="你的 MOYI 用户 API Key"
|
||||
<strong>{{ group.sourceLabel || '默认分组' }}</strong><small>{{ group.provider }}</small>
|
||||
<label>调用模型 ID <code>{{ group.id }}</code></label>
|
||||
<button class="text-link" @click="copy(group.id, '调用模型 ID', group.id)"><Copy :size="14" />{{ copySucceeded(group.id) ? '已复制' : '复制调用 ID' }}</button>
|
||||
<small class="drawer-pricing">标准价:{{ group.pricing?.listPriceUsd ? `${formatUsdPrice(group.pricing.listPriceUsd.input)} 输入 / ${formatUsdPrice(group.pricing.listPriceUsd.output)} 输出 · USD / 1M` : '待同步' }} · {{ groupPriceLabel(group) }} · 对外 {{ groupDiscountLabel(group) }}</small>
|
||||
<small class="drawer-pricing">标准价:{{ groupStandardPriceLabel(group) }} · {{ groupPriceLabel(group) }} · 对外 {{ groupDiscountLabel(group) }}</small>
|
||||
<button class="button secondary" :disabled="!group.pricingConfigured || group.billingReady === false || group.executionReady === false" @click="tryModel({ ...selectedModel, groups: [group] })">{{ !group.pricingConfigured ? '价格待配置' : group.executionReady === false ? '异步执行器待接入' : group.billingReady === false ? '异步按任务计费待配置' : '试用此分组' }}</button>
|
||||
</section>
|
||||
<template #footer><button class="button primary full" :disabled="!hasCallableGroup(selectedModel)" @click="tryModel(selectedModel)"><Play :size="16" />{{ !selectedModel.groups.length ? '分组待上线' : hasCallableGroup(selectedModel) ? '在线试用' : modelUnavailableLabel(selectedModel) }}</button><button class="button secondary full" @click="selectedModel = null; emit('navigate', 'docs')"><BookOpen :size="16" />查看文档</button></template>
|
||||
@@ -803,7 +789,7 @@ $env:OPENAI_API_KEY="你的 MOYI 用户 API Key"
|
||||
.model-pricing { display: grid; gap: 6px; margin-top: 10px; padding: 9px 10px; border: 1px solid #ece9f8; border-radius: 8px; color: #687378; background: #faf9ff; font-size: 9px; line-height: 1.55; }
|
||||
.model-pricing span { display: grid; gap: 2px; }
|
||||
.model-pricing strong { color: #4c3e87; font-size: 8px; letter-spacing: .03em; }
|
||||
.model-pricing em { display: block; color: #687378; font-style: normal; }
|
||||
.model-pricing em { display: block; color: #687378; font-style: normal; overflow-wrap: anywhere; }
|
||||
.drawer-pricing { line-height: 1.6; }
|
||||
.catalog-group-detail button:disabled { color: #8a6b32; cursor: default; }
|
||||
.request-panel, .response-panel { min-width: 0; }
|
||||
|
||||
Reference in new issue
Block a user