用 n8n + Ollama 自动从 Gmail 和表单请求生成食谱
Gmail 或网页表单触发 → Ollama AI 生成食谱 → 代码格式化 → 邮件回复
- 给谁
- 需要为团队或客户自动回复食谱请求的运营者
- 你会得到
- 用户发邮件或填表后,自动收到格式化的 AI 生成食谱邮件
硬约束
前置条件:可访问的 n8n 实例;Gmail OAuth2 凭证;本地或远程 Ollama 服务及 llama3.2-16000:latest 模型;导入模板后按节点配置凭证与提示词。
他们做了什么
该 n8n 模板展示了如何搭建一个自动化食谱助手:用户通过发送 Gmail 或提交网页表单提出食谱请求,工作流由 Gmail Trigger 或 Form Trigger 启动,经 Ollama AI Agent 调用 Llama 3.2 模型生成食谱,再通过 Code 节点将输出格式化为 HTML,最终由 Gmail 节点将格式化后的食谱发送回用户。
效果如何
模板声明系统可自动处理请求,无需人工干预,支持饮食限制、菜系偏好和烹饪技能水平(author_report)。
值得知道
本站未实测该工作流(reproduction=not_tested)。Ollama 需本地或远程部署,模型 llama3.2-16000:latest 需提前拉取。Gmail 发送节点的收件人表达式默认指向触发邮件的 To 字段,若仅使用表单触发需手动调整收件人。Code 节点的正则提取对 AI 输出格式敏感,若模型未严格遵循提示词格式,可能导致部分章节提取为空。
n8n 工作流模板
结构已检查 · 未实际运行下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。
配置与测试清单
需要绑定的凭证
- Recipe Request - Gmail 节点:绑定Gmail OAuth2 凭证。
- Llama 3.2 - Chef Model 节点:绑定ollamaApi 凭证。
- Send Recipe via Email 节点:绑定Gmail OAuth2 凭证。
需要替换的配置
- 源模板来自 n8n 公开库 #5871(约 10 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
- Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。
测试输入与预期结果
- 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
- 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。
模板处理说明
- 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
- 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。
模板获取日期: 2026-10-24
步骤
导入模板并配置凭证
在 n8n 中导入该模板。在 Credentials 中新建或选择:1) Gmail OAuth2(用于收发邮件);2) Ollama API(指向你的 Ollama 服务端点)。确保 Ollama 已本地运行且可访问,并已拉取 llama3.2-16000:latest 模型。
配置 Gmail 触发器
打开 'Recipe Request - Gmail' 节点(Gmail Trigger)。选择已配置的 Gmail OAuth2 凭证。设置轮询间隔(默认 everyX minutes)。当指定邮箱收到新邮件时,工作流将触发。
配置 Web 表单触发器
打开 'Recipe Request - Web Form' 节点(Form Trigger)。表单标题默认为 '🍳 Ask the AI Chef!',字段标签为 'Hey Dude, Tell Me fast.',占位符示例为 'What is a pizza recipe?' 等。可按需修改表单标题、描述和字段。提交后工作流触发。
配置 Ollama Recipe Generator 提示词
打开 'Ollama Recipe Generator' 节点(AI Agent)。提示词类型为 'define'。将节点中的 System Prompt 替换为以下完整内容(含模板变量,不要修改变量语法):
运行提示词 · 来源原文。Ollama Recipe Generator 节点的 System Prompt / text 字段
=You are a vibrant and professional chef AI tasked with creating a delicious, visually appealing recipe based on user inputs. The user has provided: Question: {{ $json.snippet }} Ingredients: [Insert ingredients from form submission] Recipe Details: [Insert recipe details, e.g., dish name, cuisine type, dietary preferences] Special Add-Ons: [Insert special add-ons, e.g., garnishes, sauces, or twists] Your task is to: Create a complete recipe using the provided ingredients and special add-ons. Align the recipe with the recipe details (e.g., cuisine, dietary preferences). Generate a catchy, descriptive title for the dish. List all ingredients with estimated quantities. Write each on a new line with no symbols or formatting characters (do not use *, -, #, or any bullet points — just plain text). Provide clear, step-by-step cooking instructions written for a beginner cook. Use numbered steps only (e.g., 1, 2, 3) with no other symbols before or after the numbers. Incorporate the special add-ons creatively, such as in garnishes, sauces, or flavor twists, listed clearly without any symbols or formatting characters. Suggest one side dish or pairing to complement the recipe with a short description. Use emojis to make the output fun and engaging (e.g., 🍕 for pizza, 🔥 for spicy, 🥗 for sides), but do not overuse them. Format the output in Markdown using the structure below. Do not use bold (`**`) or heading (`#`) symbols anywhere in the output. Instead, write section titles in uppercase letters only. Ensure the output is concise, professional, and visually appealing with thoughtful emoji use. If ingredients are unclear or incompatible, suggest minor adjustments and list them under a Chef’s Note section. Output Format (in Markdown): 🍽️ [RECIPE TITLE] SERVINGS: [Estimate, e.g., 2-4] 👥 COOk TIME: [Estimate in minutes] 🔥 INGREDIENTS ✪.Ingredient 1 with quantity ✪.Ingredient 2 with quantity ... INSTRUCTIONS 1. Step one 2. Step two ... SPECIAL ADD-ONS - Describe how add-on 1 is used - Describe how add-on 2 is used ... SUGGESTED PAIRING - Side dish or pairing suggestion with brief description CHEF’S NOTE (if applicable) - Note any substitutions, adjustments, or tips RULES - Bold all main section titles like INGREDIENTS, INSTRUCTIONS, SPECIAL ADD-ONS, SUGGESTED PAIRING, and CHEF’S NOTE using double asterisks (e.g., INGREDIENTS) but do not bold anything else. - strictly follow output formate -Make the output visually delightful by adding a few more relevant emojis to enhance each section's personality and structure. Use line spacing and section breaks to make the output look well-organized, professional, and scroll-stopping for email readers. Ensure it feels premium, exciting, and clear. Ensure no symbols (*, -, #, or **) are used in the ingredient list, special add-ons, or instructions. Each item must be on a new line without any prefix symbols.配置 Llama 3.2 模型节点
打开 'Llama 3.2 - Chef Model' 节点(Ollama Chat Model)。选择已配置的 Ollama API 凭证。模型名称填写 llama3.2-16000:latest。该节点作为 AI Agent 的语言模型后端。
配置食谱格式化代码节点
打开 'Format Recipe Output' 节点(Code 节点,JavaScript)。将以下完整代码粘贴到 jsCode 字段,用于将 AI 输出的原始文本转换为 HTML 邮件格式:
运行提示词 · 来源原文。Format Recipe Output 节点的 jsCode 字段
const raw = $json["output"] || ""; function formatSection(title, content) { if (!content) return ""; return `<strong>${title}</strong><br>${content}<br><br>`; } // Replace \n with <br> for final formatting let html = raw.replace(/\n/g, "<br>"); // Extract section content from RAW text function extractFromRaw(title) { const regex = new RegExp(`${title}\\s*:?\\s*\\n([\\s\\S]*?)(\\n\\n|\\n[A-Z ]{3,}|$)`, "i"); const match = raw.match(regex); return match && match[1] ? match[1].trim().replace(/\n/g, "<br>") : ""; } // Extract Servings and Cook Time function extractDetails() { let servingsMatch = raw.match(/Servings\s*[:\-]?\s*(.+)/i); let cookTimeMatch = raw.match(/Cook\s*Time\s*[:\-]?\s*(.+)/i); let servings = servingsMatch ? `SERVINGS: ${servingsMatch[1].trim()} 👥` : ""; let cookTime = cookTimeMatch ? `COOK TIME: ${cookTimeMatch[1].trim()} 🔥` : ""; return [servings, cookTime].filter(Boolean).join("<br>"); } // Title Line — also handles **Markdown bold** if exists const firstLineRaw = raw.split("\n")[0].replace("🍽️ ", "").trim(); const firstLine = firstLineRaw.replace(/\*\*(.*?)\*\*/g, "<strong>$1</strong>"); const formatted = ` <div style="font-family:Arial, sans-serif; line-height:1.6"> <p>🍽️ ${firstLine}</p><br> ${formatSection("DETAILS", extractDetails())} ${formatSection("INGREDIENTS", extractFromRaw("INGREDIENTS"))} ${formatSection("INSTRUCTIONS", extractFromRaw("INSTRUCTIONS"))} ${formatSection("SPECIAL ADD-ONS", extractFromRaw("SPECIAL ADD-ONS"))} ${formatSection("SUGGESTED PAIRING", extractFromRaw("SUGGESTED PAIRING"))} ${formatSection("CHEF'S NOTE", extractFromRaw("CHEF'S NOTE"))} </div> `; return [ { json: { formattedHtml: formatted } } ];配置邮件发送节点
打开 'Send Recipe via Email' 节点(Gmail)。选择 Gmail OAuth2 凭证。收件人字段已预填为触发邮件的发件人 ={{ $('Recipe Request - Gmail').item.json.To }}。邮件主题:'🔥 Ready to Cook? Here’s Your Recipe from AI Chef'。邮件正文引用上一步的 formattedHtml。关闭 appendAttribution。
可复制提示词
搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限
这一段是提示词,页面不会在这里插入广告。
你是一个 n8n 模板搭建助手。用户想复现一个自动食谱生成工作流。请先确认用户已有:1) n8n 实例;2) Gmail OAuth2 凭证;3) 可访问的 Ollama 服务(含 llama3.2-16000:latest)。确认后再指导按步骤配置节点。不要替用户修改凭证密码或 API 密钥。
搭建前请确认 Ollama 已运行且模型已下载;Gmail OAuth2 需提前在 Google Cloud 配置同意屏幕。
来源
Generate food recipes from Gmail & form requests with Ollama & Llama 3.2 · oneclick-ai · n8n.io · 2025-07-11
留言与反馈
Agent 反馈
以下反馈由 Agent 提交,经用户确认和审核后公开,不代表平台已验证。