Files
webup-cloud/frontend/src/views/ModelCatalog.vue
T
WebUp Cloud 891e4896cc
Verify control plane / verify (push) Canceled after 0s
Verify control plane / verify (pull_request) Canceled after 0s
Show enabled models and current prices in the member console
2026-11-08 08:57:24 +08:00

156 lines
5.5 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { api } from "../api";
type CatalogModel = {
id: string;
name: string;
model_id: string;
provider_name: string;
context_length: number;
max_output: number;
tools_enabled: boolean;
vision_enabled: boolean;
input_price: number | string;
output_price: number | string;
cache_read_price: number | string;
cache_write_price: number | string;
price_effective_at?: string;
};
const models = ref<CatalogModel[]>([]);
const provider = ref("");
const query = ref("");
const loading = ref(true);
const error = ref("");
const providers = computed(() =>
[...new Set(models.value.map((model) => model.provider_name))].sort((a, b) =>
a.localeCompare(b, "zh-CN"),
),
);
const filtered = computed(() => {
const needle = query.value.trim().toLocaleLowerCase();
return models.value.filter(
(model) =>
(!provider.value || model.provider_name === provider.value) &&
[model.name, model.model_id, model.provider_name].some((value) =>
value.toLocaleLowerCase().includes(needle),
),
);
});
const numberFormat = new Intl.NumberFormat("zh-CN");
const priceFormat = new Intl.NumberFormat("zh-CN", {
style: "currency",
currency: "CNY",
maximumFractionDigits: 8,
});
const dateFormat = new Intl.DateTimeFormat("zh-CN", {
dateStyle: "medium",
timeStyle: "short",
});
const price = (value: number | string) => priceFormat.format(Number(value));
async function load() {
loading.value = true;
error.value = "";
try {
models.value = await api<CatalogModel[]>("/models");
if (!providers.value.includes(provider.value)) provider.value = "";
} catch (cause) {
error.value = (cause as Error).message;
} finally {
loading.value = false;
}
}
onMounted(load);
</script>
<template>
<div class="page-heading">
<div>
<span class="eyebrow">AI MODEL CATALOG</span>
<h1>AI 模型</h1>
<p>查看当前启用的模型、能力和价格。</p>
</div>
<div class="table-actions">
<button class="secondary" :disabled="loading" @click="load">刷新</button>
<RouterLink class="primary" to="/develop">去 AI 开发</RouterLink>
</div>
</div>
<section class="panel table-panel" :aria-busy="loading">
<div class="panel-heading">
<div>
<h3>模型与价格</h3>
<p>单位:人民币 / 百万 Token。任务提交时锁定价格版本。</p>
</div>
<span v-if="!loading && !error" class="muted">{{ filtered.length }} 个模型</span>
</div>
<div v-if="error" class="alert error" role="alert">{{ error }}</div>
<div v-if="loading" class="empty" role="status">正在加载模型…</div>
<div v-else-if="!error && !models.length" class="empty">暂无启用的 AI 模型。</div>
<template v-else-if="!error">
<div class="toolbar">
<input v-model="query" type="search" aria-label="搜索模型" placeholder="搜索名称、模型 ID 或供应商" />
<select v-model="provider" aria-label="筛选供应商">
<option value="">全部供应商</option>
<option v-for="name in providers" :key="name" :value="name">{{ name }}</option>
</select>
</div>
<div v-if="!filtered.length" class="empty">没有匹配的模型。</div>
<div v-else class="table-scroll">
<table class="catalog-table">
<thead>
<tr>
<th scope="col">模型</th>
<th scope="col">供应商</th>
<th scope="col">能力与上下文</th>
<th scope="col">输入 / 输出</th>
<th scope="col">缓存读取 / 写入</th>
<th scope="col">价格生效时间</th>
</tr>
</thead>
<tbody>
<tr v-for="model in filtered" :key="model.id">
<th scope="row">
<strong>{{ model.name }}</strong>
<small class="muted model-id">{{ model.model_id }}</small>
</th>
<td>{{ model.provider_name }}</td>
<td>
{{ [model.tools_enabled ? "工具调用" : "", model.vision_enabled ? "图片输入" : ""].filter(Boolean).join(" · ") || "文本" }}
<small class="muted">上下文 {{ numberFormat.format(model.context_length) }}</small>
<small class="muted">最大输出 {{ numberFormat.format(model.max_output) }}</small>
</td>
<td class="prices">
<span>输入 {{ price(model.input_price) }}</span>
<span>输出 {{ price(model.output_price) }}</span>
</td>
<td class="prices">
<span>读 {{ price(model.cache_read_price) }}</span>
<span>写 {{ price(model.cache_write_price) }}</span>
</td>
<td>
<time v-if="model.price_effective_at" :datetime="model.price_effective_at">
{{ dateFormat.format(new Date(model.price_effective_at)) }}
</time>
<span v-else class="muted">—</span>
</td>
</tr>
</tbody>
</table>
</div>
</template>
</section>
</template>
<style scoped>
.toolbar input { max-width: 340px; }
.toolbar select { width: auto; }
.catalog-table th[scope="row"] { color: var(--text); }
.catalog-table td { vertical-align: top; }
.catalog-table small, .prices span { display: block; }
.model-id { overflow-wrap: anywhere; }
.prices { white-space: nowrap; font-variant-numeric: tabular-nums; }
</style>