用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/OthmanAdi/openui-forge --skill openui-forge-langchain命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | openui-forge-langchain |
| description | OpenUI generative UI with LangChain/LangGraph backend. Supports ChatOpenAI and ChatAnthropic. |
| version | 1.2.0 |
| author | OthmanAdi |
Build generative UI apps with OpenUI + LangChain. Stream from ChatOpenAI or ChatAnthropic, convert to OpenAI NDJSON.
OPENAI_API_KEY or ANTHROPIC_API_KEY setnpm install @openuidev/react-ui @openuidev/react-headless @openuidev/react-lang lucide-react zod @langchain/openai @langchain/core
# For Anthropic: npm install @langchain/anthropic
app/layout.tsx:import "@openuidev/react-ui/components.css";
npm run dev and testapp/api/chat/route.tsimport { openuiChatLibrary } from "@openuidev/react-ui/genui-lib";
import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage, SystemMessage, AIMessage } from "@langchain/core/messages";
const model = new ChatOpenAI({ model: process.env.OPENAI_MODEL ?? "gpt-5.5", streaming: true });
export async function POST(req: Request) {
const { messages } = await req.json();
const systemPrompt = openuiChatLibrary.prompt({
preamble: "You are a helpful assistant that generates interactive UIs.",
});
const lcMessages = [
new SystemMessage(systemPrompt),
...messages.map((m: { role: string; content: string }) =>
m.role === "user" ? new HumanMessage(m.content) : new (m.)
),
];
stream = model.(lcMessages);
encoder = ();
id = ;
readableStream = ({
() {
( chunk stream) {
text = chunk. === ? chunk. : ;
(!text) ;
payload = {
id,
: ,
: [{ : , : { : text }, : }],
};
controller.(encoder.());
}
done = {
id,
: ,
: [{ : , : {}, : }],
};
controller.(encoder.());
controller.(encoder.());
controller.();
},
});
(readableStream, {
: { : },
});
}
app/api/chat/route.tsReplace the model initialization and import:
import { ChatAnthropic } from "@langchain/anthropic";
const model = new ChatAnthropic({
model: process.env.ANTHROPIC_MODEL ?? "claude-sonnet-4-6",
maxTokens: 4096,
streaming: true,
});
Everything else (message mapping, stream conversion, response) stays identical.
app/chat/page.tsx"use client";
import { FullScreen } from "@openuidev/react-ui";
import { openuiChatLibrary } from "@openuidev/react-ui/genui-lib";
import {
openAIAdapter,
openAIMessageFormat,
} from "@openuidev/react-headless";
export default function ChatPage() {
return (
<FullScreen
componentLibrary={openuiChatLibrary}
streamProtocol={openAIAdapter()}
messageFormat={openAIMessageFormat}
apiUrl="/api/chat"
/>
);
}
The backend emits SSE (
data: {json}\n\n). Pair it withopenAIAdapter()on the frontend. (langGraphAdapteris also exported from@openuidev/react-headlessif you stream LangGraph events natively rather than converting to OpenAI shape.)
import { defineComponent } from "@openuidev/react-lang";
import { z } from "zod";
export const MetricCard = defineComponent({
name: "MetricCard",
description: "Displays a metric with label, value, and optional trend",
props: z.object({
label: z.string().describe("Metric name"),
value: z.number().describe("Current metric value"),
trend: z.enum(["up", "down", "flat"]).optional().describe("Trend direction"),
}),
component: ({ props }) => (
<div style={{ padding: 16, border: "1px solid #e5e7eb", borderRadius: 8 }}>
<div style={{ fontSize: 14, color: "#" }}>{props.label}
{props.value}
{props.trend && {props.trend === "up" ? "+" : props.trend === "down" ? "-" : "="}}
),
});
npx @openuidev/cli generate ./src/lib/library.ts --out src/generated/system-prompt.txt
@langchain/openai or @langchain/anthropic installeddata: prefixfinish_reason: "stop" and ends with data: [DONE]streamProtocol={openAIAdapter()} and openAIMessageFormat| Error | Cause | Fix |
|---|---|---|
| Empty chunks in stream | LangChain AIMessageChunk content may be empty | Skip chunks where text is empty |
| Type error on messages | Wrong LangChain message class | Map user to HumanMessage, assistant to AIMessage |
| Module not found | Missing LangChain provider package | Install @langchain/openai or @langchain/anthropic |
| Stream hangs | Missing [DONE] sentinel | Always send final stop chunk and [DONE] |
| CORS error | Cross-origin frontend | Add CORS headers if frontend/backend are split |