fix(web): 仪表盘 curl 示例模型名改用真实可用模型

硬编码的 gpt-test 让快速开始示例照抄必失败。并发拉取 /user/models
取第一个可用模型,拿不到时退回占位符。
This commit is contained in:
Sakurasan committed 2026-10-30 01:42:24 +08:00
1 parent 7dce4cadde
commit dfe31b5b4f
1 file changed
+12 -5
+12 -5
View File
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { computed, onMounted, ref } from 'vue'
import { http, errMsg } from '@/api/client'
import { useToastStore } from '@/stores/toast'
import { fmtMoney, fmtNum, fmtCost, fmtTime } from '@/lib/format'
@@ -19,13 +19,16 @@ const monthCost = ref(0)
const models = ref(0)
const trend = ref<{ label: string; value: number }[]>([])
const logs = ref<UsageLog[]>([])
// curl 示例里的 model 用真实可用模型(拿不到时退占位符),避免示例跑不通
const exampleModel = ref('<your-model>')
async function load() {
try {
const [b, s, l] = await Promise.all([
const [b, s, l, m] = await Promise.all([
http.get('/user/balance'),
http.get('/usage/stats?group=day&from=' + daysAgo(13)),
http.get('/usage/logs?page_size=8'),
http.get('/user/models').catch(() => null),
])
const d = b.data.data
balance.value = d.balance
@@ -34,6 +37,8 @@ async function load() {
models.value = d.models_available
trend.value = s.data.data.items.map((x: { date: string; cost: number }) => ({ label: x.date.slice(5), value: x.cost }))
logs.value = l.data.data.items
const items = m?.data?.data?.items as string[] | undefined
if (items?.length) exampleModel.value = items[0]
} catch (e) {
toast.err(errMsg(e))
} finally {
@@ -46,12 +51,14 @@ function daysAgo(n: number): string {
return d.toISOString().slice(0, 10)
}
// 快速开始:Base URL 用浏览器当前 host(兼容端点),curl 示例
// 快速开始:Base URL 用浏览器当前 host(兼容端点),curl 示例;模型名跟随可用列表
const baseURL = `${window.location.origin}/v1`
const curlCmd = `curl ${baseURL}/chat/completions \\
const curlCmd = computed(
() => `curl ${baseURL}/chat/completions \\
-H "Authorization: Bearer sk-ot-xxxx" \\
-H "Content-Type: application/json" \\
-d '{"model":"gpt-test","stream":true,"messages":[{"role":"user","content":"hi"}]}'`
-d '{"model":"${exampleModel.value}","stream":true,"messages":[{"role":"user","content":"hi"}]}'`,
)
const copied = ref('')
async function copy(text: string, key: string) {