新闻详情

新闻详情

首页 / 资讯中心 / 详情

如何用 AI SDK 的 uploadSkill 上传技能包并在推理调用中引用

发布时间:2026/9/13 3:50:24来源:尧图网络
如何用 AI SDK 的 uploadSkill 上传技能包并在推理调用中引用
如何用 AI SDK 的 uploadSkill 上传技能包并在推理调用中引用【免费下载链接】aiThe AI Toolkit for TypeScript. From the creators of Next.js, the AI SDK is a free open-source library for building AI-powered applications and agents项目地址: https://gitcode.com/GitHub_Trending/ai/ai当你的 AI 应用需要让模型在沙箱容器里执行特定任务例如按SKILL.md描述的行为处理文档或运行脚本时AI SDK 提供了uploadSkill函数它把一组文件技能包上传到 provider返回一个ProviderReference你把这个引用传进后续的推理调用模型就能在代码执行环境中加载并使用该技能。当前支持skills()接口的 provider 是 Anthropicanthropic.skills()和 OpenAIopenai.skills()详见 Skill Uploads 文档。准备条件Node.js 22 环境AI SDK 的快速上手文档以此为运行要求项目中已安装ai包和对应的 provider 包。本文示例从ai、ai-sdk/anthropic、ai-sdk/openai导入对应仓库中的 packages/ai、packages/anthropic、packages/openai本地准备好技能包文件。技能是一个文件束典型结构是包含描述技能行为的SKILL.md可以附带辅助文件如脚本对应 provider 的 API 访问能力Anthropic 或 OpenAI因为上传发生在 provider 侧。注意示例代码中使用了fs.readFileSync所以这段代码只能运行在 Node.js 运行时中不能在浏览器环境执行。第一步调用 uploadSkill 上传技能包uploadSkill的参数与返回结构见 API 参考参数类型说明apiSkillsV4 \| ProviderV4上传使用的 skills API 接口如anthropic.skills()也可以直接传 provider 实例如anthropicSDK 会自动调用.skills()filesSkillsV4File[]组成技能的文件列表每个文件有相对路径path和内容contentUint8Array或 base64 字符串displayTitlestring可选技能的人类可读标题providerOptionsProviderOptions可选额外的 provider 特定选项以 Anthropic 为例files中的path: my-skill/SKILL.md是技能包内的相对路径readFileSync(./SKILL.md)读取的是你本地的技能文件——两者需要按你的实际文件布局替换import { uploadSkill } from ai; import { anthropic } from ai-sdk/anthropic; import { readFileSync } from fs; const { providerReference } await uploadSkill({ api: anthropic.skills(), files: [ { path: my-skill/SKILL.md, content: readFileSync(./SKILL.md), }, ], displayTitle: My Skill, });技能可以包含多个文件例如附带一个 Python 辅助脚本const { providerReference } await uploadSkill({ api: openai.skills(), files: [ { path: my-skill/SKILL.md, content: readFileSync(./SKILL.md), // Uint8Array }, { path: my-skill/helper.py, content: readFileSync(./helper.py), }, ], });另外api也可以直接传 provider 实例SDK 会自动调用.skills()const { providerReference } await uploadSkill({ api: anthropic, // shorthand for anthropic.skills() files: [{ path: my-skill/SKILL.md, content: readFileSync(./SKILL.md) }], displayTitle: My Skill, });第二步检查上传结果uploadSkill返回一个UploadSkillResult各字段含义如下引自 uploadSkill 参考文档字段类型说明providerReferenceProviderReference映射 provider 名称到该 provider 的技能 ID后续推理调用要用它displayTitlestring?provider 返回的人类可读标题如支持且已提供namestring?provider 从技能文件推断出的名称descriptionstring?provider 从技能文件推断出的描述latestVersionstring?provider 分配的最新版本标识providerMetadataobject?其他 provider 特定元数据如时间戳warningsWarning[]针对不支持选项的警告例如 OpenAI 不支持displayTitle其中providerReference是一个Recordstring, string把 provider 名称映射到 provider 特定的技能标识符。文档给出的示例结果仅作格式参考不是固定输出// 示例 ProviderReference { anthropic: skill_abc123, }上传完成后可以检查两点providerReference中是否包含当前 provider 的条目warnings中是否有不支持选项的警告。第三步在推理调用中引用技能技能如何挂到推理调用上取决于 provider两个 provider 的机制不同但都要求模型同时具备代码执行能力——技能在沙箱容器中运行。Anthropic通过 container.skills 引用Anthropic 的技能运行在沙箱容器中必须启用代码执行工具。做法是在providerOptions.anthropic.container.skills数组中放入{ type: custom, providerReference }import { uploadSkill, generateText } from ai; import { anthropic, type AnthropicLanguageModelOptions, } from ai-sdk/anthropic; import { readFileSync } from fs; const { providerReference } await uploadSkill({ api: anthropic.skills(), files: [ { path: my-skill/SKILL.md, content: readFileSync(./SKILL.md), }, ], displayTitle: My Skill, }); const { text } await generateText({ model: anthropic(claude-sonnet-4-6), tools: { code_execution: anthropic.tools.codeExecution_20260120(), }, prompt: Use the skill to complete the task., providerOptions: { anthropic: { container: { skills: [{ type: custom, providerReference }], }, } satisfies AnthropicLanguageModelOptions, }, });关于codeExecution_20260120文档说明它是推荐版本不需要 beta header支持 Claude Opus 4.6、Sonnet 4.6、Sonnet 4.5 和 Opus 4.5。Anthropic 还有codeExecution_20250825支持 Python 和 Bash增强文件操作与codeExecution_20250522仅支持 Bash两个版本可选。OpenAI通过 shell 工具的 environment.skills 引用OpenAI 侧的做法是把providerReference放进shell工具的environment.skills数组环境类型设为containerAuto时在 OpenAI 托管的容器中执行await generateText({ model: openai.responses(gpt-5.2), tools: { shell: openai.tools.shell({ environment: { type: containerAuto, skills: [{ type: skillReference, providerReference }], }, }), }, prompt: ..., });OpenAI provider 文档补充说明技能是带SKILL.md清单的版本化文件束可以附加到containerAuto和local两种环境。除了引用已上传的技能skillReference容器环境还支持内联 base64 zip 格式的技能local环境则直接指向磁盘上含SKILL.md的目录。可选分支同一技能用于多个 provider如果希望同一个技能在不同 provider 间通用需要分别上传并把引用合并。每个 provider 会各自查找自己的技能 IDconst [openaiUpload, anthropicUpload] await Promise.all([ uploadSkill({ api: openai.skills(), files: [{ path: my-skill/SKILL.md, content: skillSource }], }), uploadSkill({ api: anthropic.skills(), files: [{ path: my-skill/SKILL.md, content: skillSource }], displayTitle: My Skill, }), ]); const mergedReference { ...openaiUpload.providerReference, ...anthropicUpload.providerReference, }; // mergedReference: { openai: sk_..., anthropic: sk_... }合并后的引用可以在任意一个 provider 处理请求时使用。限制与错误行为provider 缺失条目会报错推理调用时每个 provider 从providerReference中查找自己的技能 ID如果引用中没有当前 provider 的条目会抛出错误。这是引用失败时最直接的现象。不支持的选项走警告而非报错例如对 OpenAI 传displayTitle结果会出现在warnings数组中需要检查返回值确认上传是否符合预期。name、description、latestVersion、providerMetadata均为可选字段由 provider 从技能文件推断或分配不能假定一定存在。技能与代码执行工具绑定Anthropic 文档明确技能运行在沙箱容器中且要求启用代码执行工具OpenAI 侧技能附加在 shell 工具的环境上。推理调用漏配对应的执行工具技能就没有运行环境。支持范围目前只有 Anthropic 和 OpenAI 提供skills()与技能上传能力其他 provider 不适用本文路径。如果你在自定义 provider 或 provider registry 上组织代码可以把anthropic.skills()挂到customProvider的skills选项或通过registry.skills(providerId)取出 skills 接口后调用uploadSkill用法见 Provider Management 文档。结果验证按以上步骤完成后验证路径是uploadSkill的返回值中providerReference包含目标 provider 的技能 ID格式如文档示例中的{ anthropic: skill_abc123 }且warnings无与你的参数相关的条目generateText调用能正常返回text没有因providerReference缺少当前 provider 条目而抛错。上传与引用的完整说明以 Skill Uploads 文档为准uploadSkill的参数与返回字段以 API 参考为准。【免费下载链接】aiThe AI Toolkit for TypeScript. From the creators of Next.js, the AI SDK is a free open-source library for building AI-powered applications and agents项目地址: https://gitcode.com/GitHub_Trending/ai/ai创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
网站建设高端定制企业官网
RELATED

相关资讯

更多精彩内容,欢迎继续阅读

较早相关资讯

最新相关资讯

Skyvern Claude Desktop MCP Bundle 发布与安全维护指南:.mcpb 安装包的构建、版本刷新与依赖审计全流程 2026/9/13 4:26:29

Skyvern Claude Desktop MCP Bundle 发布与安全维护指南:.mcpb 安装包的构建、版本刷新与依赖审计全流程

Skyvern Claude Desktop MCP Bundle 发布与安全维护指南:.mcpb 安装包的构建、版本刷新与依赖审计全流程 【免费下载链接】skyvern Automate browser based workflows with AI 项目地址: https://gitcode.com/GitHub_Trending/sk/skyvern 导读 Skyvern 通过…

阅读更多 →
基于 Data-Science-For-Beginners 的 Soda Profits 实战:用电子表格公式与函数补齐可口可乐毛利核算 2026/9/13 4:26:29

基于 Data-Science-For-Beginners 的 Soda Profits 实战:用电子表格公式与函数补齐可口可乐毛利核算

基于 Data-Science-For-Beginners 的 Soda Profits 实战:用电子表格公式与函数补齐可口可乐毛利核算 【免费下载链接】Data-Science-For-Beginners 10 Weeks, 20 Lessons, Data Science for All! 项目地址: https://gitcode.com/GitHub_Trending/da/Data-Science-…

阅读更多 →
Authelia 集成 ownCloud Infinite Scale:OpenID Connect 1.0 单点登录(SSO)完整配置指南 2026/9/13 4:26:29

Authelia 集成 ownCloud Infinite Scale:OpenID Connect 1.0 单点登录(SSO)完整配置指南

Authelia 集成 ownCloud Infinite Scale:OpenID Connect 1.0 单点登录(SSO)完整配置指南 【免费下载链接】authelia The Single Sign-On Multi-Factor portal for web apps. OpenID Certified™ and Post-Quantum Cryptography Ready. 项目…

阅读更多 →
CodexBar 中 Vertex AI Provider 的实现剖析:gcloud ADC 凭证、Cloud Monitoring 配额查询与 Claude 日志成本识别 2026/9/13 4:26:29

CodexBar 中 Vertex AI Provider 的实现剖析:gcloud ADC 凭证、Cloud Monitoring 配额查询与 Claude 日志成本识别

CodexBar 中 Vertex AI Provider 的实现剖析:gcloud ADC 凭证、Cloud Monitoring 配额查询与 Claude 日志成本识别 【免费下载链接】CodexBar Show usage stats for OpenAI Codex and Claude Code, without having to login. 项目地址: https://gitcode.com/GitHu…

阅读更多 →
Ignite 原生 Android 工程指南:manual 工作流下的 android 目录与 CNG 取舍 2026/9/13 4:26:29

Ignite 原生 Android 工程指南:manual 工作流下的 android 目录与 CNG 取舍

Ignite 原生 Android 工程指南:manual 工作流下的 android 目录与 CNG 取舍 【免费下载链接】ignite Infinite Reds battle-tested React Native project boilerplate, along with a CLI, component/model generators, and more! 9 years of continuous development…

阅读更多 →
Sunshine 游戏串流怎么把 PC 游戏推到电视和手机上 2026/9/13 4:23:29

Sunshine 游戏串流怎么把 PC 游戏推到电视和手机上

Sunshine 游戏串流怎么把 PC 游戏推到电视和手机上 【免费下载链接】Sunshine Self-hosted game stream host for Moonlight. 项目地址: https://gitcode.com/GitHub_Trending/su/Sunshine Sunshine 游戏串流的做法是:Sunshine(自托管游戏串流服务…

阅读更多 →

今日资讯

本周资讯

本月资讯

看完文章仍有疑问?

联系尧图顾问,获取一对一建站咨询

立即免费咨询 📞 400-888-8888
📞