使用OpenAI结构化输出来自用户请求动态生成HTML页面
中级
这是一个AI, IT Ops领域的自动化工作流,包含 7 个节点。主要使用 Html, Webhook, HttpRequest, OpenAi, RespondToWebhook 等节点,结合人工智能技术实现智能自动化。 使用OpenAI结构化输出根据用户请求动态生成网页
前置要求
- •HTTP Webhook 端点(n8n 会自动生成)
- •可能需要目标 API 的认证凭证
- •OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "eXiaTDyKfXpMeyLh",
"meta": {
"instanceId": "f4f5d195bb2162a0972f737368404b18be694648d365d6c6771d7b4909d28167",
"templateCredsSetupCompleted": true
},
"name": "使用 OpenAI 结构化输出来自用户请求动态生成 HTML 页面",
"tags": [],
"nodes": [
{
"id": "b1d9659f-4cd0-4f87-844d-32b2af1dcf13",
"name": "响应 Webhook",
"type": "n8n-nodes-base.respondToWebhook",
"position": [
2160,
380
],
"parameters": {
"options": {
"responseHeaders": {
"entries": [
{
"name": "Content-Type",
"value": "text/html; charset=UTF-8"
}
]
}
},
"respondWith": "text",
"responseBody": "={{ $json.html }}"
},
"typeVersion": 1.1
},
{
"id": "5ca8ad3e-7702-4f07-af24-d38e94fdc4ec",
"name": "OpenAI - 使用结构化输出",
"type": "n8n-nodes-base.httpRequest",
"position": [
1240,
380
],
"parameters": {
"url": "https://api.openai.com/v1/chat/completions",
"method": "POST",
"options": {},
"jsonBody": "={\n \"model\": \"gpt-4o-2024-08-06\",\n \"messages\": [\n {\n \"role\": \"system\",\n \"content\": \"You are a user interface designer and copy writter. Your job is to help users visualize their website ideas. You design elegant and simple webs, with professional text. You use Tailwind framework\"\n },\n {\n \"role\": \"user\",\n \"content\": \"{{ $json.query.query }}\"\n }\n ],\n \"response_format\":\n{\n \"type\": \"json_schema\",\n \"json_schema\": {\n \"name\": \"ui\",\n \"description\": \"Dynamically generated UI\",\n \"strict\": true,\n \"schema\": {\n \"type\": \"object\",\n \"properties\": {\n \"type\": {\n \"type\": \"string\",\n \"description\": \"The type of the UI component\",\n \"enum\": [\n \"div\",\n \"span\",\n \"a\",\n \"p\",\n \"h1\",\n \"h2\",\n \"h3\",\n \"h4\",\n \"h5\",\n \"h6\",\n \"ul\",\n \"ol\",\n \"li\",\n \"img\",\n \"button\",\n \"input\",\n \"textarea\",\n \"select\",\n \"option\",\n \"label\",\n \"form\",\n \"table\",\n \"thead\",\n \"tbody\",\n \"tr\",\n \"th\",\n \"td\",\n \"nav\",\n \"header\",\n \"footer\",\n \"section\",\n \"article\",\n \"aside\",\n \"main\",\n \"figure\",\n \"figcaption\",\n \"blockquote\",\n \"q\",\n \"hr\",\n \"code\",\n \"pre\",\n \"iframe\",\n \"video\",\n \"audio\",\n \"canvas\",\n \"svg\",\n \"path\",\n \"circle\",\n \"rect\",\n \"line\",\n \"polyline\",\n \"polygon\",\n \"g\",\n \"use\",\n \"symbol\"\n]\n },\n \"label\": {\n \"type\": \"string\",\n \"description\": \"The label of the UI component, used for buttons or form fields\"\n },\n \"children\": {\n \"type\": \"array\",\n \"description\": \"Nested UI components\",\n \"items\": {\n \"$ref\": \"#\"\n }\n },\n \"attributes\": {\n \"type\": \"array\",\n \"description\": \"Arbitrary attributes for the UI component, suitable for any element using Tailwind framework\",\n \"items\": {\n \"type\": \"object\",\n \"properties\": {\n \"name\": {\n \"type\": \"string\",\n \"description\": \"The name of the attribute, for example onClick or className\"\n },\n \"value\": {\n \"type\": \"string\",\n \"description\": \"The value of the attribute using the Tailwind framework classes\"\n }\n },\n \"additionalProperties\": false,\n \"required\": [\"name\", \"value\"]\n }\n }\n },\n \"required\": [\"type\", \"label\", \"children\", \"attributes\"],\n \"additionalProperties\": false\n }\n }\n}\n}",
"sendBody": true,
"sendHeaders": true,
"specifyBody": "json",
"authentication": "predefinedCredentialType",
"headerParameters": {
"parameters": [
{
"name": "Content-Type",
"value": "application/json"
}
]
},
"nodeCredentialType": "openAiApi"
},
"credentials": {
"openAiApi": {
"id": "WqzqjezKh8VtxdqA",
"name": "OpenAi account - Baptiste"
}
},
"typeVersion": 4.2
},
{
"id": "24e5ca73-a3b3-4096-8c66-d84838d89b0c",
"name": "OpenAI - JSON 转 HTML",
"type": "@n8n/n8n-nodes-langchain.openAi",
"position": [
1420,
380
],
"parameters": {
"modelId": {
"__rl": true,
"mode": "list",
"value": "gpt-4o-mini",
"cachedResultName": "GPT-4O-MINI"
},
"options": {
"temperature": 0.2
},
"messages": {
"values": [
{
"role": "system",
"content": "You convert a JSON to HTML. \nThe JSON output has the following fields:\n- html: the page HTML\n- title: the page title"
},
{
"content": "={{ $json.choices[0].message.content }}"
}
]
},
"jsonOutput": true
},
"credentials": {
"openAiApi": {
"id": "WqzqjezKh8VtxdqA",
"name": "OpenAi account - Baptiste"
}
},
"typeVersion": 1.3
},
{
"id": "c50bdc84-ba59-4f30-acf7-496cee25068d",
"name": "格式化 HTML 结果",
"type": "n8n-nodes-base.html",
"position": [
1940,
380
],
"parameters": {
"html": "<!DOCTYPE html>\n\n<html>\n<head>\n <meta charset=\"UTF-8\" />\n <script src=\"https://cdn.tailwindcss.com\"></script>\n <title>{{ $json.message.content.title }}</title>\n</head>\n<body>\n{{ $json.message.content.html }}\n</body>\n</html>"
},
"typeVersion": 1.2
},
{
"id": "193093f4-b1ce-4964-ab10-c3208e343c69",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
1134,
62
],
"parameters": {
"color": 7,
"width": 638,
"height": 503,
"content": "## 根据用户查询生成 HTML"
},
"typeVersion": 1
},
{
"id": "0371156a-211f-4d92-82b1-f14fe60d4b6b",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
0,
60
],
"parameters": {
"color": 7,
"width": 768,
"height": 503,
"content": "## 工作流:使用 OpenAI 结构化输出来自用户请求动态生成 HTML 页面"
},
"typeVersion": 1
},
{
"id": "06380781-5189-4d99-9ecd-d8913ce40fd5",
"name": "Webhook",
"type": "n8n-nodes-base.webhook",
"position": [
820,
380
],
"webhookId": "d962c916-6369-431a-9d80-af6e6a50fdf5",
"parameters": {
"path": "d962c916-6369-431a-9d80-af6e6a50fdf5",
"options": {
"allowedOrigins": "*"
},
"responseMode": "responseNode"
},
"typeVersion": 2
}
],
"active": true,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "d2307a2a-5427-4769-94a6-10eab703a788",
"connections": {
"Webhook": {
"main": [
[
{
"node": "Open AI - Using Structured Output",
"type": "main",
"index": 0
}
]
]
},
"OpenAI - JSON to HTML": {
"main": [
[
{
"node": "Format the HTML result",
"type": "main",
"index": 0
}
]
]
},
"Format the HTML result": {
"main": [
[
{
"node": "Respond to Webhook",
"type": "main",
"index": 0
}
]
]
},
"Open AI - Using Structured Output": {
"main": [
[
{
"node": "OpenAI - JSON to HTML",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 人工智能, IT 运维
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
连接Retell语音代理至自定义函数
连接Retell语音代理至自定义函数
Set
Webhook
Respond To Webhook
+1
7 节点Agent Studio
客户支持
使用GPT-4.1、Outlook和Mem.ai自动化Microsoft Teams会议分析
使用GPT-4.1、Outlook和Mem.ai自动化Microsoft Teams会议分析
If
Set
Code
+19
61 节点Wayne Simpson
人力资源
使用GPT-4o AI分析和多格式报告运行完整技术SEO审计
使用GPT-4o AI分析和多格式报告运行完整技术SEO审计
Set
Xml
Code
+14
45 节点Oriol Seguí Rotllant
人工智能
Selenium终极爬虫工作流
n8n终极爬虫工作流
If
Set
Code
+10
63 节点Pablo
人工智能
使用OpenAI和Quickchart.io可视化SQL代理查询
使用OpenAI和Quickchart.io可视化SQL代理查询
Set
Http Request
Agent
+7
16 节点Agent Studio
工程
高级预约预订AI助手
使用GPT-4、VAPI.ai和GHL自动化AI电话预订与CRM更新
If
Webhook
Email Send
+6
23 节点Sam Yassine
客户支持
工作流信息
难度等级
中级
节点数量7
分类2
节点类型6
作者
Agent Studio
@agentstudioWe are a product studio that helps organizations leverage no-code and generative AI to automate internal processes and launch new digital products.
外部链接
在 n8n.io 查看 →
分享此工作流