Show enabled models and current prices in the member console

This commit is contained in:
WebUp Cloud committed 2026-11-08 08:57:24 +08:00
1 parent 572371d7af
commit 891e4896cc
6 files changed
+233 -4

No files matched your search

@@ -179,9 +179,9 @@ public class ModelController {
private List<Map<String, Object>> models(boolean all) {
return db.queryForList(
"SELECT m.*,p.name AS provider_name,p.api_type,v.id AS"
+ " price_version_id,v.input_price,v.output_price,v.cache_read_price,v.cache_write_price"
+ " FROM ai_models m JOIN ai_providers p ON p.id=m.provider_id JOIN"
+ " ai_model_price_versions v ON v.id=m.current_price_version "
+ " price_version_id,v.input_price,v.output_price,v.cache_read_price,v.cache_write_price,"
+ " v.created_at AS price_effective_at FROM ai_models m JOIN ai_providers p ON"
+ " p.id=m.provider_id JOIN ai_model_price_versions v ON v.id=m.current_price_version "
+ (all ? "" : "WHERE m.enabled=TRUE AND p.enabled=TRUE ")
+ " ORDER BY m.created_at DESC");
}
@@ -78,6 +78,76 @@ class ModelApiIntegrationTest {
assertTrue(encrypted.startsWith("v1:"));
}
@Test
void memberCatalogShowsOnlyEnabledModelsAndTheCurrentPriceVersion() throws Exception {
UUID enabledProvider = UUID.randomUUID(), disabledProvider = UUID.randomUUID();
for (UUID provider : List.of(enabledProvider, disabledProvider)) {
users
.db()
.update(
"INSERT INTO"
+ " ai_providers(id,name,base_url,api_type,encrypted_key,enabled,timeout_seconds)"
+ " VALUES (?,?, 'https://api.openai.com/v1','OPENAI','private-fixture',?,30)",
provider,
provider.equals(enabledProvider) ? "Visible provider" : "Disabled provider",
provider.equals(enabledProvider));
}
var settings =
json.createObjectNode()
.put("providerId", enabledProvider.toString())
.put("name", "Catalog model")
.put("modelId", "visible-model")
.put("contextLength", 8192)
.put("maxOutput", 1024)
.put("enabled", true)
.put("toolsEnabled", true)
.put("visionEnabled", true)
.put("inputPrice", 2)
.put("outputPrice", 8)
.put("cacheReadPrice", 1)
.put("cacheWritePrice", 3);
var visibleId =
json.readTree(
mvc.perform(
post("/api/admin/models")
.header("Authorization", "Bearer " + a)
.contentType(MediaType.APPLICATION_JSON)
.content(settings.toString()))
.andExpect(status().isOk())
.andReturn()
.getResponse()
.getContentAsString())
.path("id")
.asText();
for (var hidden :
List.of(
settings.deepCopy().put("modelId", "disabled-model").put("enabled", false),
settings.deepCopy().put("providerId", disabledProvider.toString()))) {
mvc.perform(
post("/api/admin/models")
.header("Authorization", "Bearer " + a)
.contentType(MediaType.APPLICATION_JSON)
.content(hidden.toString()))
.andExpect(status().isOk());
}
mvc.perform(
put("/api/admin/models/" + visibleId)
.header("Authorization", "Bearer " + a)
.contentType(MediaType.APPLICATION_JSON)
.content(settings.put("inputPrice", 5).toString()))
.andExpect(status().isOk());
mvc.perform(get("/api/models").header("Authorization", "Bearer " + u))
.andExpect(status().isOk())
.andExpect(jsonPath("$.length()").value(1))
.andExpect(jsonPath("$[0].provider_name").value("Visible provider"))
.andExpect(jsonPath("$[0].input_price").value(5))
.andExpect(jsonPath("$[0].cache_read_price").value(1))
.andExpect(jsonPath("$[0].price_effective_at").isNotEmpty())
.andExpect(jsonPath("$[0].encrypted_key").doesNotExist())
.andExpect(jsonPath("$[0].base_url").doesNotExist());
}
@Test
void ordinaryUsersCannotAdjustWallets() throws Exception {
mvc.perform(
+1 -1
View File
@@ -68,7 +68,7 @@
| POST | `/api/admin/providers/{id}/test` | 实际调用上游模型列表,记录连接结果 |
| GET / POST | `/api/admin/models` | 管理列表 / 创建模型及初始价格版本 |
| PUT | `/api/admin/models/{id}` | 更新能力与开放状态,新增价格版本 |
| GET | `/api/models` | 当前用户可选模型及价格 |
| GET | `/api/models` | 当前已启用的模型、供应商名称、能力、价格及版本生效时间(`price_effective_at`) |
供应商字段:name、baseUrl(HTTPS 443;连接时校验 DNS、拒绝私网 / 元数据地址)、apiType(OPENAI / ANTHROPIC / GEMINI)、authMode(BEARER / API_KEY / X_API_KEY)、apiKey、enabled、timeoutSeconds(5–180)。供应商预设接口 `/api/admin/providers/presets` 提供 MiMo、DeepSeek、Kimi 等官方模板及自定义兼容中转配置,不预造模型或价格。已有模型引用的供应商不能原地更换地址或协议,需新建供应商。
+2
View File
@@ -20,6 +20,7 @@ import {
Server,
Wallet,
Code2,
Cpu,
HardDrive,
Globe,
LifeBuoy,
@@ -55,6 +56,7 @@ const nav = [
{ to: "/console", label: "数据概览", icon: LayoutDashboard },
{ to: "/projects", label: "我的项目", icon: FolderKanban },
{ to: "/develop", label: "AI 开发", icon: Code2 },
{ to: "/models", label: "AI 模型", icon: Cpu },
{ to: "/wallet", label: "钱包与账本", icon: Wallet },
{ to: "/hosting", label: "云托管", icon: Server },
{ to: "/storage", label: "对象存储", icon: HardDrive },
+2
View File
@@ -9,6 +9,7 @@ import Projects from "./views/Projects.vue";
import Account from "./views/Account.vue";
import Admin from "./views/Admin.vue";
import Models from "./views/Models.vue";
import ModelCatalog from "./views/ModelCatalog.vue";
import Wallet from "./views/Wallet.vue";
import Develop from "./views/Develop.vue";
import AdminTasks from "./views/AdminTasks.vue";
@@ -69,6 +70,7 @@ const router = createRouter({
{ path: "/admin/domains", component: AdminDomains, meta: { admin: true } },
{ path: "/admin/plans", component: Plans, meta: { admin: true } },
{ path: "/develop", component: Develop },
{ path: "/models", component: ModelCatalog },
{ path: "/admin/models", component: Models, meta: { admin: true } },
{ path: "/admin/tasks", component: AdminTasks, meta: { admin: true } },
{
+155
View File
@@ -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>