@dbx-tools/shared-model-gateway (英语)
发现由 dbx-tools 模型网关从浏览器、边缘或 共享应用程序代码 。 软件包在 网络边界,并提供不导入节点的取模合同 或 Databricks AppKit 运行时代码.
列出可用的模型
import { createModelGatewayClient } from "@dbx-tools/shared-model-gateway";
const client = createModelGatewayClient();
const response = await client.listModels({ search: "claude sonnet" });
const modelIds = "data" in response ? response.data.map((model) => model.id) : [];
目录包括虚拟 smart-router 仅当聊天模式
网关被纪念的"Databricks"智能路由器探测器成功. 内容
capabilities.smart_router 字段将其与具体终点区分开来.
成功探测器默认在5分钟后到期, 并被刷新
小时在背景。 路由请求失败, 正探测器无效
所以后来的模型列表回复 停止广告虚拟模型.
在浏览器中,客户端使用活性源. 供应 baseUrl 在测试中,
服务器渲染, 或任何运行时间 globalThis.location数字 :
const client = createModelGatewayClient({
baseUrl: "http://127.0.0.1:4000/",
});
请求编码目录
当客户端需要特定 Codex 的模型元数据时使用 Codex 目录 推理控件 :
const response = await client.listModels({ codex: true });
设定 metadata: true 当调用者需要排序时, 任意一个目录形状
耐久性,综合LMArena质量,来源排名,限制和定价. 客户端发送
GET /v1/models?metadata=true; 省略选项的请求收到
兼容有效载荷不变.
通过一个 AbortSignal 取消模型发现。 HTTP 失败
ModelGatewayClientError,其中包含状态代码和已验证的网关
返回时的错误反应 .
验证网关有效载荷
使用导出 Zod 计划与另一个 HTTP 传输 :
import { ModelListResponseSchema } from "@dbx-tools/shared-model-gateway";
const models = ModelListResponseSchema.parse(await response.json());
这个 models 模块覆盖 OpenAI、Codex、Anthropic、嵌入和出错
载荷。 这个 contracts 模块涵盖模型能力和确定性
路由选择输入和结果.
配置网关选项
ModelGatewayOptionsSchema 定义服务器默认和验证。 来源
ModelGatewayCliOptionsSchema 添加 runtimeInfo 并需要一个非零端口
前景和服务命令:
import {
ModelGatewayOptionsSchema,
resolveModelGatewayOptions,
} from "@dbx-tools/shared-model-gateway/options";
const options = resolveModelGatewayOptions({
smartRouter: "auto",
smartRouterTimeoutMs: 10000,
listen: "localhost:4400",
modelClass: "chat-balanced",
preferSystemModels: true,
bodyLimit: "100mb",
});
ModelGatewayOptionsSchema.parse(options);
ModelSelectionOptionsSchema 定义相互排斥 model 财务报告和审定财务报表
modelClass 模式门道和Genie代码呼叫器共享的字段。 都让开
选择最佳的聊天模式. preferSystemModels 默认为 false。 。 。 .
启用时使用非精确请求 system.ai.* 服务而不是工作空间
服务端点.
这个 smartRouter 模块导出 cononial smart-router id, 验证
routes:select 以及用于观察《公约》
选定具体模式和 task_v3 简介.
运行时边界
发现客户端执行 HTTP 请求 GET /v1/models计划
选项帮助者不会启动网关、解析 Databricks 证书或引用
模特们 使用
@dbx-tools/appkit-模范出道道 应用程序
网关运输及 @dbx-工具/型号 用于服务器侧
模型发现和选择.
软件包出口
client:创建模型发现客户端并输入了HTTP出错.models:验证公用模型,嵌入和出错的有效载荷.contracts:验证共享的路由和容量值.options:验证共享服务器和CLI配置.smartRouter:拥有虚拟模型id,有线计和观测头.