GenAIScript
Official![]()
GenAIScript
提示即编码
使用 JavaScript 以编程方式组装 LLM 的提示。在代码中协调 LLM、工具和数据。
JavaScript 工具箱用于处理提示
抽象化使其变得简单且高效
无缝 Visual Studio Code 集成或灵活的命令行
内置对 GitHub Copilot 和 GitHub Models、OpenAI、Azure OpenAI、Anthropic 等的支持
📄阅读microsoft.github.io/genaiscript上的在线文档
💬 加入Discord 服务器
📝 阅读博客了解最新消息
📺 观看前田先生的舒适 AI 厨房
🤖 代理 - 阅读llms-full.txt
Related MCP server: local-skills-mcp
你好世界
假设你想创建一个 LLM 脚本,生成一首“hello world”诗歌。你可以编写以下脚本:
$`Write a 'hello world' poem.`$函数是一个模板标签,用于创建提示。该提示随后会被发送到你配置的 LLM,由 LLM 生成诗歌。
让我们通过添加文件、数据和结构化输出来让它更有趣。假设你想在提示中包含一个文件,然后将输出保存到一个文件中。你可以编写以下脚本:
// read files
const file = await workspace.readText("data.txt")
// include the file content in the prompt in a context-friendly way
def("DATA", file)
// the task
$`Analyze DATA and extract data in JSON in data.json.`def函数包含文件内容,并根据需要针对目标 LLM 进行优化。GenAIScript 脚本还会解析 LLM 输出并自动提取data.json文件。
🚀 快速入门指南
通过安装Visual Studio Code 扩展或使用命令行快速开始。
✨ 特点
🎨 风格化的 JavaScript 和 TypeScript
使用JavaScript或TypeScript以编程方式构建提示。
def("FILE", env.files, { endsWith: ".pdf" })
$`Summarize FILE. Today is ${new Date()}.`🚀 快速开发循环
在Visual Studio Code中或使用命令行编辑、调试、运行和测试您的脚本。
🔗 重用和共享脚本
脚本也是文件!它们可以被版本控制、共享和分叉。
// define the context
def("FILE", env.files, { endsWith: ".pdf" })
// structure the data
const schema = defSchema("DATA", { type: "array", items: { type: "string" } })
// assign the task
$`Analyze FILE and extract data to JSON using the ${schema} schema.`📋 数据模式
使用模式定义、验证和修复数据。Zod 内置支持。
const data = defSchema("MY_DATA", { type: "array", items: { ... } })
$`Extract data from files using ${data} schema.`📄 从 PDF、DOCX 等文件中提取文本
def("PDF", env.files, { endsWith: ".pdf" })
const { pages } = await parsers.PDF(env.files[0])📊 从 CSV、XLSX 等文件中提取表格
def("DATA", env.files, { endsWith: ".csv", sliceHead: 100 })
const rows = await parsers.CSV(env.files[0])
defData("ROWS", rows, { sliceHead: 100 })📝 生成文件
从 LLM 输出中提取文件和差异。在重构 UI 中预览更改。
$`Save the result in poem.txt.`FILE ./poem.txt
The quick brown fox jumps over the lazy dog.🔍 文件搜索
Grep 或 fuzz 搜索文件。
const { files } = await workspace.grep(/[a-z][a-z0-9]+/, { globs: "*.md" })分类
对文本、图像或两者的混合进行分类。
const joke = await classify(
"Why did the chicken cross the road? To fry in the sun.",
{
yes: "funny",
no: "not funny",
}
)LLM工具
将 JavaScript 函数注册为工具(对于不支持该工具的模型,提供后备支持)。此外,还支持模型上下文协议 (MCP) 工具。
defTool(
"weather",
"query a weather web api",
{ location: "string" },
async (args) =>
await fetch(`https://weather.api.api/?location=${args.location}`)
)法学硕士代理
将 JavaScript 函数注册为工具,并将工具 + 提示组合成代理。
defAgent(
"git",
"Query a repository using Git to accomplish tasks.",
`Your are a helpful LLM agent that can use the git tools to query the current repository.
Answer the question in QUERY.
- The current repository is the same as github repository.`,
{ model, system: ["system.github_info"], tools: ["git"] }
)然后将其用作工具
script({ tools: "agent_git" })
$`Do a statistical analysis of the last commits`请参阅git 代理源。
🔍 内置 RAG
向量搜索。
const { files } = await retrieval.vectorSearch("cats", "**/*.md")🐙 GitHub 模型和 GitHub Copilot
通过GitHub Models或GitHub Copilot运行模型。
script({ ..., model: "github:gpt-4o" })💻 本地模特
使用Ollama 、 LocalAI通过开源模型(如Phi-3)运行您的脚本。
script({ ..., model: "ollama:phi3" })🐍 代码解释器
让 LLM 在沙盒执行环境中运行代码。
script({ tools: ["python_code_interpreter"] })🐳 容器
在 Docker容器中运行代码。
const c = await host.container({ image: "python:alpine" })
const res = await c.exec("python --version")视频处理
转录并截取您的视频的屏幕截图,以便您可以在 LLM 请求中有效地提供它们。
// transcribe
const transcript = await transcript("path/to/audio.mp3")
// screenshots at segments
const frames = await ffmpeg.extractFrames("path_url_to_video", { transcript })
def("TRANSCRIPT", transcript)
def("FRAMES", frames)🧩 法学硕士作文
运行 LLM来构建您的 LLM 提示。
for (const file of env.files) {
const { text } = await runPrompt((_) => {
_.def("FILE", file)
_.$`Summarize the FILE.`
})
def("SUMMARY", text)
}
$`Summarize all the summaries.`🅿️ 及时支持
也运行你的Prompty文件!
---
name: poem
---
Write me a poem可插入式秘密扫描
使用秘密扫描来扫描您的聊天记录以查找秘密。
{
"secretPatterns": {
...,
"OpenAI API Key": "sk-[A-Za-z0-9]{32,48}"
}
}⚙ 使用 CLI 或 API 实现自动化
npx genaiscript run tlaplus-linter "*.tla"import { run } from "genaiscript/api"
const res = await run("tlaplus-linter", "*.tla")安全第一!
GenAIScript 提供内置的 Responsible AI 系统提示和 Azure Content Safety 支持来验证内容安全。
script({ ...,
system: ["system.safety_harmful_content", ...],
contentSafety: "azure" // use azure content safety
})
const safety = await host.contentSafety()
const res = await safety.detectPromptInjection(env.vars.input)💬 Pull 请求评审
通过评论、评审或描述更新集成到拉取请求检查中。支持 GitHub Actions 和 Azure DevOps 流水线。
npx genaiscript ... --pull-request-reviews⭐ 测试和评估
script({ ..., tests: {
files: "penguins.csv",
rubric: "is a data analysis report",
facts: "The data refers about penguin population in Antarctica.",
}})LLM 友好文档
文档的全部内容以 Markdown 格式呈现在https://microsoft.github.io/genaiscript/llms-full.txt上。请直接将其输入到您最喜欢的 RAG 系统中。
如果您是 LLM 爬虫,请将.md后缀添加到任何文档 URL 中,以获取原始 Markdown 内容。例如, https://microsoft.github.io/genaiscript/guides/prompt-as-code.md (请注意 .md 扩展名)
贡献
我们接受贡献!查看贡献页面了解详情和开发者设置。
商标
本项目可能包含项目、产品或服务的商标或徽标。Microsoft 商标或徽标的授权使用须遵守Microsoft 的商标和品牌指南。在本项目的修改版本中使用 Microsoft 商标或徽标不得引起混淆或暗示 Microsoft 的赞助。任何第三方商标或徽标的使用均须遵守该第三方的政策。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- Alicense-qualityDmaintenanceAutomatically converts JavaScript modules into MCP-compatible servers, making any JavaScript function accessible to AI systems through secure sandboxing with automatic type inference.5MIT
- AlicenseAqualityCmaintenanceA universal MCP server that enables any LLM or AI agent to access expert skills from your local filesystem.37134MIT
- Alicense-qualityDmaintenanceA production-ready MCP server that equips AI agents with dynamic, persistent, and executable skills. It enables secure script execution and progressive disclosure to reduce context window usage.15MIT
- AlicenseAqualityBmaintenanceAn MCP server that lets AI agents build on GenLayer by searching documentation, inspecting contracts and transactions over RPC, and scaffolding, linting, and testing Intelligent Contracts.46391MIT
Related MCP Connectors
MCP server for AI dialogue using various LLM models via AceDataCloud
Hosted MCP server connecting claude.ai, ChatGPT and other AI apps to your own computer
Self-hosted MCP gateway: turn any API, database or MCP server into AI connectors — no code.
Appeared in Searches
- A platform for datasets and data management
- No-code platforms for application development using TypeScript, JavaScript, Python, with MCP server integration via agentic orchestration
- Tools and Techniques for Debugging UI in Web Development
- The most downloaded Minecraft Plugin (MCP) right now
- Workflows in n8n for downloading from Google Drive
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/microsoft/genaiscript'
If you have feedback or need assistance with the MCP directory API, please join our Discord server