@mottyjs /核心
Motty SDK的核心:所有Motty需要工作和一个插件需要编写。它拥有
这个 motty 建筑工人, model组合子 fallback, race, retry 和 timeout, answer,
reroute, think, said,错误类和类型。它没有依赖关系,只有
导入的内容最终会出现在motty's bundle中。 said(message) 一条信息说的是什么,是不是
之际, text 或者作为部分。
bun add @mottyjs/core
import { fallback, model, motty, race, retry, reroute } from "@mottyjs/core";
在没有工具的情况下回答请求的motty,使用两个小模型中的第一个来回答,以及 任何其他有强模型的,重试两次,第二个在它后面:
import { fallback, model, motty, race, retry, reroute } from "@mottyjs/core";
const luna = model("openai/gpt-6-luna");
const sol = model("openai/gpt-6.1-sol");
const haiku = model("anthropic/claude-haiku-5-5");
const sonnet = model("anthropic/claude-sonnet-5-5");
export default motty({ name: "coder" })
.route(({ request }) => (request.tools.length === 0 ? "quick" : "standard"), {
// A quick question still gets an answer when both small models are down
quick: ({ prompt }) => race(luna, haiku).complete(prompt).catch(() => reroute("standard")),
standard: ({ prompt }) => fallback(retry(sonnet, 2), sol).complete(prompt),
});
一个电话可能会说 headers 在响应它的请求的选项中。它们只被发送
其中主机的连接允许该名称,并且不带值的头被跳过:
const session = request.headers.get("x-session");
prompt.options = { ...prompt.options, headers: { "x-session": session } };
return sonnet.complete(prompt);
插件通过导入路径到达主机 @mottyjs/core/host.
SDK作为一个整体在 根的自述,以及其设计背后的原因 ARCHITECTURE.md.