Show enabled models and current prices in the member console
This commit is contained in:
1 parent
572371d7af
commit
891e4896cc
6 files changed
+233
-4
No files matched your search
@@ -0,0 +1,155 @@
|
||||
<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>
|
||||
Reference in new issue
Block a user