@ codeworksh/ aikit
AiKit是一个 类型脚本 SDK 提供统一的API,用于与多个LLM提供商合作,自动模型发现,提供商配置,信使和成本跟踪,以及会中交接到其他模型. 它给了你基本原始的 流出LLM反应 没有额外的bloat, 让你自己处理管弦乐.
目录
安装
npm install @codeworksh/aikit
节点 >=22.0.0 需要时间.
支持供应商
建于Vercel AI SDK上方, @codeworksh/aikit 在本地支持各种提供者:
- 安东尼 (单位:千美元)
@ai-sdk/anthropic(中文(简体) ) - 开放AI (单位:千美元)
@ai-sdk/openai(中文(简体) ) - 谷歌 (单位:千美元)
@ai-sdk/google(中文(简体) ) - Google Vertex AI (谷歌Vertex AI) 互联网档案馆的存檔,存档日期2013-10-02 (单位:千美元)
@ai-sdk/google-vertex(中文(简体) ) - 页:1 大赦国际 (单位:千美元)
@ai-sdk/xai(中文(简体) ) - 打开路透社 (单位:千美元)
@openrouter/ai-sdk-provider(中文(简体) ) - OpenAI 兼容的 API (单位:千美元)
@ai-sdk/openai-compatible(中文(简体) )
快速启动
import { llm, stream, Message } from "@codeworksh/aikit";
// Resolve a model from the built-in registry
const model = await llm("anthropic", "claude-haiku-4-5-20251001");
if (!model) throw new Error("Model not found");
// Setup conversation context
const context: Message.Context = {
systemPrompt: "You are a helpful coding assistant.",
messages: [
Message.createUserMessage({
role: "user",
time: { created: Date.now() },
parts: [{ type: "text", text: "Write a simple loop in TypeScript." }],
}),
],
};
// Option 1: Stream events
const s = stream(model, context, { apiKey: process.env.ANTHROPIC_API_KEY });
for await (const event of s) {
if (event.type === "text.delta") {
process.stdout.write(event.delta);
}
}
const finalMessage = await s.result();
console.log(`\nMessage ID: ${finalMessage.messageId}`);
// Option 2: Get complete response without streaming
const message = await stream.complete(model, context, { apiKey: process.env.ANTHROPIC_API_KEY });
console.log(message.parts);
工具
工具使LLMs能够与外部系统交互. @codeworksh/aikit 使用 TypeBox 为函数调用和计划验证提供本地支持.
import { Type, llm, stream, Message, validateToolArguments } from "@codeworksh/aikit";
const calculatorTool = {
name: "calculator",
description: "Evaluate arithmetic expressions",
parameters: Type.Object({
expression: Type.String(),
}),
};
const context: Message.Context = {
messages: [
Message.createUserMessage({
role: "user",
time: { created: Date.now() },
parts: [{ type: "text", text: "What is 25 * 18?" }],
}),
],
tools: [calculatorTool],
};
const response = await stream.complete(model, context, { apiKey: process.env.ANTHROPIC_API_KEY });
// Check for tool calls in the response
for (const part of response.parts) {
if (part.type === "toolCall") {
console.log(`Executing tool: ${part.name}`);
// Validates arguments against TypeBox schema automatically
const args = validateToolArguments(calculatorTool.parameters, part.arguments);
// Execute your tool logic here...
}
}
供应商和模式
@codeworksh/aikit 使用一个登记册获取模型规格和元数据.
import { llm } from "@codeworksh/aikit";
// Get all available providers
const providers = await llm.providers();
console.log(providers);
// Get all models for a specific provider
const anthropicModels = await llm.models("anthropic");
// Get a specific model directly
const gpt4 = await llm.model("openai", "gpt-4o");
CLI 工具
@codeworksh/aikit 具有管理本地元数据和认证的CLI工具的船舶.
你可以用它来引用 npx aikit 或者说 pnpm aikit。 。 。 .
模型生成
生成 a models.gen.json 文件获取关于提供者及其可用模型的最新元数据 models.dev。 。 。 .
pnpm aikit modelgen [path]
OAuth 供应商
管理OAuth对需要的提供者的证书,例如OpenAI Codex和GitHub Copilot.
# Start an OAuth login flow in your browser
pnpm aikit auth --openai-codex
# Codex with a device code instead: no localhost callback port, so it works
# over SSH, in containers, and when something else holds port 1455
pnpm aikit auth --openai-codex --device
# GitHub Copilot uses the device flow; add --enterprise <domain> for GitHub Enterprise
pnpm aikit auth --github-copilot
# Check the status of your stored credentials
pnpm aikit auth --openai-codex --status
pnpm aikit auth --github-copilot --status
# Refresh your current credentials
pnpm aikit auth --openai-codex --refresh
# Clear stored credentials
pnpm aikit auth --openai-codex --logout
pnpm aikit auth --github-copilot --logout
贡献
@codeworksh/aikit 开放给社区捐助。 请在提交拉力请求前确保提交问题。 该项目在接受新特征之前更倾向于公开的社区讨论.