VisibleBase
快速开始

添加模型

把模型作为数据库数据写入 Base,再在 service 里用 match 分流。

VisibleBase 现在把模型放进数据库,而不是在 Runtime 里手写注册。

最小字段有这些:

  • model_id
  • name
  • provider
  • upstream_model
  • description
  • is_primary
  • status
  • config_json

例如直接写入默认 SQLite:

import { DatabaseSync } from "node:sqlite";
import path from "node:path";

const db = new DatabaseSync(path.join(process.cwd(), ".base", "visiblebase.sqlite"));

db.prepare(`
  INSERT OR REPLACE INTO visiblebase_models (
    model_id,
    name,
    provider,
    upstream_model,
    description,
    is_primary,
    status,
    config_json,
    created_at,
    updated_at
  ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
`).run(
  "gpt-5.4",
  "GPT-5.4",
  "openai",
  "gpt-5.4",
  "Primary text model",
  "true",
  "active",
  JSON.stringify({ api_style: "responses" }),
  new Date().toISOString(),
  new Date().toISOString(),
);

然后在 Base 里定义 service 路由:

base.text()
  .default({ model: "gpt-5.4" })
  .match((ctx) => ctx.model.provider === "openai", async (ctx) => {
    return openai.responses.create({
      model: ctx.model.upstream_model,
      input: ctx.query.prompt,
      apiKey: ctx.env.OPENAI_API_KEY,
      baseURL: ctx.env.OPENAI_BASE_URL,
    });
  });

client 只需要知道 gpt-5.4 这个模型 ID,不需要知道背后怎么调用 provider。