OpenAI的应用程序SDK – 工作原理

1作者: zachpark大约 1 个月前原帖
简要概述: OpenAI 刚刚发布了其应用程序 SDK——ChatGPT “应用”的真实基础设施。该 SDK 基于模型上下文协议(MCP),使任何人都可以创建与大型语言模型(LLM)直接对话的交互式用户界面小部件。可以理解为 AI 的应用商店时刻。 核心架构: 每个 ChatGPT 应用由两个部分组成: - MCP 服务器——定义工具和逻辑。 - 小部件——编译为 JavaScript 的网页应用,嵌入在 ChatGPT 的 iframe 中。 当你说“在 Zillow 上显示房屋”时,LLM 会: → 调用 MCP 工具 → 获取链接的 UI 资源 → 将其加载到 iframe 中 这是一个完整的全栈应用,运行在 ChatGPT 内部。 项目结构: OpenAI 建议: ``` app/ server/ # MCP 逻辑和工具 web/ # React/Svelte 小部件,编译为 JavaScript ``` 服务器只需提供嵌入你 JavaScript 包的 HTML。框架无关,灵活——如果需要,可以分别托管服务器和小部件。 MCP 服务器的思维方式: 应用 SDK 服务器的功能类似于普通的 MCP 服务器,但增加了 UI 识别能力。每个工具映射到一个小部件资源(如 ui://widget/...)。当被调用时,LLM 会提取该资源并进行渲染。 服务器可以返回“structuredContent”——基本上是用于填充小部件 UI 的 JSON 属性。 秘密武器:window.openai 每个小部件都有一个内置的 API 桥接:window.openai。这使得你的前端可以直接与 ChatGPT 客户端进行通信。 你可以: - 从服务器读取数据(toolOutput) - 持久化本地 UI 状态(setWidgetState) - 直接调用工具(callTool) - 向 ChatGPT 发送消息(sendFollowUpMessage) 小部件不是静态的——它们是与模型循环连接的活跃代理。 总结: OpenAI 的应用 SDK 模糊了应用、API 和 AI 模型之间的界限。这是一个用于对话式 UI 的新运行时——一种构建微型应用的方法,这些应用存在于 ChatGPT 内部。这可能是开发者开始将 ChatGPT 视为操作系统而非聊天机器人的时刻。 我需要你的反馈: 因此我构建了 FastApps——唯一一个可以零样板、即时设置构建 ChatGPT 应用的 Python 框架。 ``` fastapps init my-app ``` 这个单一命令会启动一个全栈应用——Python 后端 + React UI——准备在 ChatGPT 内部运行。 价值: 1. 即时设置——一个命令启动,无需手动配置。 2. 零样板——一个文件用于你的工具,一个用于你的 UI。就是这样。 3. 包含认证——内置 OAuth2,支持 Auth0、Clerk 或你自己的提供者。 4. 自动连接——将工具放在 /server/tools/ 下,它会立即生效。 “ChatGPT 中的应用”时代刚刚开始。借助 FastApps,你可以利用 ChatGPT 的 8 亿周活跃用户(WAU),你的应用可以在 ChatGPT 和新的 Atlas 浏览器中无缝运行。 GitHub: [https://github.com/DooiLabs/FastApps](https://github.com/DooiLabs/FastApps)
查看原文
TL;DR OpenAI just shipped its Apps SDK — the real infrastructure behind ChatGPT “apps.” Built on top of the Model Context Protocol (MCP), it lets anyone create interactive UI widgets that talk directly to the LLM. Think: the App Store moment for AI.<p>CORE ARCHITECTURE Every ChatGPT app has two halves:<p>The MCP server — defines tools and logic.<p>The widget — a web app compiled to JS and rendered inside ChatGPT’s iframe.<p>When you say “Show me homes on Zillow,” the LLM: → Calls the MCP tool → Fetches the linked UI resource → Loads it into an iframe<p>It’s a full-stack app living inside ChatGPT.<p>PROJECT STRUCTURE OpenAI suggests:<p>app&#x2F; server&#x2F; # MCP logic and tools web&#x2F; # React&#x2F;Svelte widget, compiled to JS<p>The server just needs to serve HTML embedding your JS bundle. Framework-agnostic, flexible — even host server and widget separately if needed.<p>HOW MCP SERVERS THINK An Apps SDK server acts like a normal MCP server, but adds UI awareness. Each tool maps to a widget resource (like ui:&#x2F;&#x2F;widget&#x2F;...). When invoked, the LLM pulls that resource and renders it.<p>Servers can return “structuredContent” — basically JSON props that hydrate the widget UI.<p>THE SECRET SAUCE: WINDOW.OPENAI Every widget gets a built-in API bridge: window.openai. This lets your frontend talk directly to the ChatGPT client.<p>You can:<p>Read data from the server (toolOutput)<p>Persist local UI state (setWidgetState)<p>Call tools directly (callTool)<p>Send messages back to ChatGPT (sendFollowUpMessage)<p>Widgets aren’t static — they’re living agents wired into the model loop.<p>TAKEAWAY OpenAI’s Apps SDK blurs the line between app, API, and AI model. It’s a new runtime for conversational UI — a way to build micro-apps that live inside ChatGPT.<p>This might be the moment developers start treating ChatGPT like an OS, not a chatbot.<p>I NEED YOUR FEEDBACKS FOR IT<p>so I built FastApps — the only python framework for building chatgpt apps with zero boilerplate and instant setup<p>fastapps init my-app<p>That single command spins up a full-stack app — Python backend + React UI — ready to run inside ChatGPT.<p>VALUES 1. Instant setup – One command to start. No manual config. 2. Zero boilerplate – One file for your tool, one for your UI. That’s it. 3. Auth included – Built-in OAuth2 with Auth0, Clerk, or your own provider. 4. Auto-wiring – Drop a tool under &#x2F;server&#x2F;tools&#x2F; and it’s instantly live.<p>The“Apps in ChatGPT”era is just beginning. With FastApps, you can tap into ChatGPT’s 800M WAU and your app runs seamlessly both inside ChatGPT and in the new Atlas browser.<p>Github: https:&#x2F;&#x2F;github.com&#x2F;DooiLabs&#x2F;FastApps