Skip to content

Instantly share code, notes, and snippets.

@gryzinsky
Created March 6, 2024 17:42
Show Gist options
  • Save gryzinsky/91ceed939435fa818e448c5255cbf6dc to your computer and use it in GitHub Desktop.
Save gryzinsky/91ceed939435fa818e448c5255cbf6dc to your computer and use it in GitHub Desktop.
AIExample.json
{
"id": "Z6TY8mQOfbIvN86d",
"meta": {
"instanceId": "d7d7b1e232b4091cbd27b67d20aa4c7ff54b11591e8e3f22d5db8387cc91fe3c"
},
"name": "AI Competition – Small Business Problems – Rebound Email",
"tags": [],
"nodes": [
{
"id": "12ef13ef-1634-4baa-88c5-2794d10cca5d",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"position": [
-240,
220
],
"parameters": {},
"typeVersion": 1
},
{
"id": "c4d1116c-70e9-4161-a28a-821e91dca5c1",
"name": "Download Dummy Data",
"type": "n8n-nodes-base.httpRequest",
"notes": "uargh.. excel",
"position": [
-20,
220
],
"parameters": {
"url": "https://let-the-work-flow.com/dummy/n8n-contest-merch.xlsx",
"options": {}
},
"notesInFlow": true,
"typeVersion": 4.1
},
{
"id": "df8f6536-fa39-4d41-86b9-cafd57699089",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-300,
120
],
"parameters": {
"width": 715.3278290432247,
"height": 315.32782904322477,
"content": "## Get and prepare Dummy Data"
},
"typeVersion": 1
},
{
"id": "4c5e8173-46b4-44b9-8ee8-bd6938594de8",
"name": "Html Template for our Email",
"type": "n8n-nodes-base.html",
"position": [
2700,
-120
],
"parameters": {
"html": "<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"UTF-8\" />\n <title>{{ $json['Headline'] }}</title>\n</head>\n<body>\n <div class=\"container\">\n <img class=\"logo\" src=\"https://img.logoipsum.com/264.svg\"/>\n <h1>Hey {{ $json['Custome Name'] ? $json['Custome Name']+', ' : '!' }}</h1>\n <p>{{ $json['Body'] }}</p>\n \n <div class=\"footer\">\n <p>\n Definitely not a real company Lmt.<br>\n Also not a real street 123<br>\n Unreal Town\n </p> \n</div> \n </div>\n \n \n</body>\n</html>\n\n<style>\n.logo {\n margin-top: 20px;\n }\n.container {\n background-color: #ffffff;\n font-family: sans-serif;\n padding: 16px;\n border-radius: 8px;\n}\n\nh1 {\n color: #ff6d5a;\n font-size: 24px;\n font-weight: bold;\n margin-top: 30px;\n}\n\np {\n color: #606060;\n line-height: 1.6;\n}\n\nh2 {\n color: #909399;\n font-size: 20px;\n font-weight: bold;\n padding: 8px;\n}\n\n.footer {\n margin-top: 30px;\n}\n\n.footer > p {\n font-size: 14px;\n color: #ccc;\n }\n\n</style>"
},
"typeVersion": 1
},
{
"id": "541739f8-08c6-4e11-96bc-970d0bc2d81a",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
740,
-359.54268546006915
],
"parameters": {
"width": 520.9323109877616,
"height": 577.5426854600692,
"content": "## Let GPT do the heavy work\n\nFor the prompt we follow the one-shot'ish principle. Also I've decided to **_NOT_** give the AI the personal data. Keeps it simpler regarding data privacy.\n\nThe AI-Chain will generate a **Headline** and the **Text** for the Email and even **decides** if we should send the user a **Coupon**."
},
"typeVersion": 1
},
{
"id": "c09e5357-f6da-465f-a1e8-36da5a04923d",
"name": "Basic LLM Chain",
"type": "@n8n/n8n-nodes-langchain.chainLlm",
"position": [
860,
-160
],
"parameters": {
"prompt": "=Determine the sentiment of the given product feedback. Then generate a Headline and Text without salutation or any greeting for a personalized Email Campagin after a User gave a product review. If the user seems not happy, tell them that you have a Coupon for them. The User finds the Coupon Code below this E-mail. \nThe target of the campagin: {{ $json['Campaign Target'] }}.\nRemember: {{ $json['Flavour'] }}. Avoid any greeting.",
"messages": {
"messageValues": [
{
"type": "HumanMessagePromptTemplate",
"message": "=Item Purchased: {{ $json['Item Purchased'] }} \nFeedback: {{ $json.Feedback }}\nShould we send a coupon to make the customer happy? Yes/No"
}
]
}
},
"typeVersion": 1
},
{
"id": "c2374357-b601-4b65-a01b-670960cbe5f5",
"name": "Structured Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
1100,
60
],
"parameters": {
"jsonSchema": "{\n \"type\": \"object\",\n \"properties\": {\n \"Headline\": {\n \"type\": \"string\"\n },\n \"Body\": {\n \"type\": \"string\"\n },\n \"SendCoupon\": {\n \"type\": \"boolean\"\n }\n }\n}"
},
"typeVersion": 1
},
{
"id": "8e29fd9f-7328-497c-ab23-af28d888bb01",
"name": "OpenAI Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
820,
60
],
"parameters": {
"model": "gpt-4",
"options": {
"temperature": 0.7
}
},
"credentials": {
"openAiApi": {
"id": "RL1de6Is2rfDFoYu",
"name": "Let the work flow"
}
},
"typeVersion": 1
},
{
"id": "01ef334e-c6be-4e3b-a9f5-2aaccef5d6ec",
"name": "Some Options for the Campagin",
"type": "n8n-nodes-base.set",
"position": [
520,
220
],
"parameters": {
"fields": {
"values": [
{
"name": "Campaign Target",
"stringValue": "Engage the Customer"
},
{
"name": "Flavour",
"stringValue": "be friendly and witty but also cool and direct. Critique is valuable and embrace the feedback."
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "e994b6c1-156d-450f-8473-d7dc64d5c4d0",
"name": "make that excel to something usuable",
"type": "n8n-nodes-base.spreadsheetFile",
"position": [
200,
220
],
"parameters": {
"options": {}
},
"typeVersion": 2
},
{
"id": "8647f374-a145-4d83-b6b4-4a4c354c3402",
"name": "AI Output + Prev Data",
"type": "n8n-nodes-base.merge",
"position": [
1380,
200
],
"parameters": {
"mode": "combine",
"options": {},
"combinationMode": "mergeByPosition"
},
"typeVersion": 2.1
},
{
"id": "7d1f6a8a-7fd5-4b3e-9d0c-15dd4d19481e",
"name": "Is the result valid?",
"type": "n8n-nodes-base.if",
"position": [
1580,
197
],
"parameters": {
"conditions": {
"string": [
{
"value1": "Headline",
"operation": "isNotEmpty"
},
{
"value1": "Body",
"operation": "isNotEmpty"
}
]
}
},
"typeVersion": 1
},
{
"id": "cbebe7a7-6cbd-457a-a8b7-d583927284f4",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
2620,
-240
],
"parameters": {
"width": 277.60143175948906,
"height": 324.32159412507656,
"content": "## HTML Email-Template without Coupon"
},
"typeVersion": 1
},
{
"id": "3f363757-a769-49b0-8652-b80457981f4a",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1540,
60
],
"parameters": {
"width": 367.0616804273918,
"height": 405.4881010199125,
"content": "## Make sure we have what we need\nWe do not want to sent empty messages to our customers"
},
"typeVersion": 1
},
{
"id": "e7c01ae6-cc39-4e3e-b5c3-b99752e339ea",
"name": "AI did fail us",
"type": "n8n-nodes-base.stopAndError",
"position": [
1760,
296
],
"parameters": {
"errorMessage": "Unexpected Langchain Output"
},
"typeVersion": 1
},
{
"id": "5e49f4a2-e186-475d-bce1-c10b6a2fa5bd",
"name": "Coupon them or not to Coupon them",
"type": "n8n-nodes-base.if",
"position": [
1980,
180
],
"parameters": {
"conditions": {
"boolean": [
{
"value1": "={{ $json.SendCoupon }}"
}
]
}
},
"typeVersion": 1
},
{
"id": "ccc5d0c2-fc52-4989-8107-ad2d1463d26f",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
2600,
320
],
"parameters": {
"width": 369.917435648372,
"height": 330.56011245057107,
"content": "## HTML Email-Template with Coupon"
},
"typeVersion": 1
},
{
"id": "31210e6c-c7e0-444a-9c83-6ce96a2fcf4f",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
2238,
320
],
"parameters": {
"width": 319.84249777513367,
"height": 330.6656654860422,
"content": "## Mocked: Fake a Coupon Code\nFor a real life scenario add the automated coupon generation here"
},
"typeVersion": 1
},
{
"id": "e5ca2ba0-40e1-4600-9e67-0c92527a7a3e",
"name": "Fake Coupon",
"type": "n8n-nodes-base.set",
"position": [
2318,
460
],
"parameters": {
"fields": {
"values": [
{
"name": "Coupon",
"stringValue": "F4k3ItT1llY0uM4k3It"
},
{
"name": "Coupon Value",
"stringValue": "20% of any purchase"
},
{
"name": "Coupon Terms",
"stringValue": "=Valid until {{ $today.plus({days: 14}).format(\"d. MMM. y\") }} | minimum purchase amount: 20$ "
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "402c73b1-b8f3-41d5-8e75-a0feb4b38619",
"name": "Sticky Note6",
"type": "n8n-nodes-base.stickyNote",
"position": [
-300,
-485
],
"parameters": {
"width": 534.1315466553021,
"height": 566.556517486655,
"content": "# Documentation\n\nThis Workflow is for the n8n AI / Langchain Competition.\n\nIt solves the Problem: Personalizing marketing emails based on customer purchase history.\n\nI've found it a bit ambiguous and decided to go the \"Convert unhappy customers with a Coupon\"-Route.\n\nSo this workflow utilizes the new LangChain Node for generating personalized E-Mail campaigns and decide if the user might need a coupon to be satisfied. Classic Rebound stuff. \n\nThere is also a Node \"Some Options...\" which can be adjusted to quickly change the direction this Campaign should go.\n\nAdditionally we use n8n to generate the HTML Mails by two different Templates. One with simple text and another for that Coupon handling.\n\n![Image](https://let-the-work-flow.com/logo-64.png)\nEnjoy the Workflow! ❤️ \nhttps://let-the-work-flow.com\n"
},
"typeVersion": 1
},
{
"id": "b9e32086-95ca-43e2-87c2-59335e822985",
"name": "Html Template for our Email with a Coupon",
"type": "n8n-nodes-base.html",
"position": [
2738,
460
],
"parameters": {
"html": "<!DOCTYPE html>\n<html>\n<head>\n <meta charset=\"UTF-8\" />\n <title>{{ $json['Headline'] }}</title>\n</head>\n<body>\n <div class=\"container\">\n <img class=\"logo\" src=\"https://img.logoipsum.com/264.svg\"/>\n <h1>Hey {{ $json['Custome Name'] ? $json['Custome Name']+', ' : '!' }}</h1>\n <p>{{ $json['Body'] }}</p>\n \n <div class=\"coupon\">\n <h3>Here's a Coupon for you!<br>\n {{ $json['Coupon Value'] }}</h3>\n <h4 class=\"code\">{{ $json['Coupon'] }}</h4>\n <p>{{ $json['Coupon Terms'] }}</p>\n </div>\n <div class=\"footer\">\n <p>\n Definitely not a real company Lmt.<br>\n Also not a real street 123<br>\n Unreal Town\n </p> \n</div> \n </div>\n \n \n</body>\n</html>\n\n<style>\n.logo {\n margin-top: 20px;\n }\n.container {\n background-color: #ffffff;\n font-family: sans-serif;\n padding: 16px;\n border-radius: 8px;\n}\n\nh1 {\n color: #ff6d5a;\n font-size: 24px;\n font-weight: bold;\n margin-top: 30px;\n}\n\np {\n color: #606060;\n line-height: 1.6;\n}\n\nh2 {\n color: #909399;\n font-size: 20px;\n font-weight: bold;\n padding: 8px;\n}\n\n.coupon {\n background: #ff6d5a;\n color: #fff;\n padding: 20px;\n}\n.coupon p {\n color: #fff;\n}\n \n.coupon .code {\n font-weight: bold;\n font-size: 24px;\n font-family: monospace;\n }\n\n.footer {\n margin-top: 30px;\n}\n\n.footer > p {\n font-size: 14px;\n color: #ccc;\n }\n\n</style>"
},
"typeVersion": 1
},
{
"id": "ff529bdf-8253-487b-88ee-c5356ea2d102",
"name": "Send Email",
"type": "n8n-nodes-base.emailSend",
"position": [
3540,
136
],
"parameters": {
"html": "={{ $json.html }}",
"options": {},
"subject": "={{ $json.Headline }}",
"toEmail": "={{ $json.Email }}",
"fromEmail": "n8n@myemail.com"
},
"credentials": {
"smtp": {
"id": "H6ImGYBa9W6FLvMH",
"name": "SMTP account"
}
},
"typeVersion": 2.1
},
{
"id": "e003ea38-f4c1-43d3-9c4e-8c8d74f6dd9b",
"name": "Sticky Note7",
"type": "n8n-nodes-base.stickyNote",
"position": [
3440,
-80
],
"parameters": {
"width": 326.9476248855971,
"height": 414.15459581943776,
"content": "## Send the Email to the Customer\n\nAlthough it's cool that n8n allows sending emails via SMPT I would recommend to stick to your newsletter tool for that to keep track of opt-outs and stuff."
},
"typeVersion": 1
},
{
"id": "8f84a6e8-5a8f-45de-b732-32ba6b084075",
"name": "The composed E-Mail + Prev Data",
"type": "n8n-nodes-base.merge",
"position": [
3120,
40
],
"parameters": {
"mode": "combine",
"options": {},
"combinationMode": "mergeByPosition"
},
"typeVersion": 2.1
},
{
"id": "e29bd936-4e34-4a34-b666-3a0c6f0684f4",
"name": "The composed E-Mail with Coupon + Prev Data",
"type": "n8n-nodes-base.merge",
"position": [
3120,
220
],
"parameters": {
"mode": "combine",
"options": {},
"combinationMode": "mergeByPosition"
},
"typeVersion": 2.1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "d50fed44-149e-43eb-a691-3d1de4b8b33c",
"connections": {
"Fake Coupon": {
"main": [
[
{
"node": "Html Template for our Email with a Coupon",
"type": "main",
"index": 0
}
]
]
},
"Basic LLM Chain": {
"main": [
[
{
"node": "AI Output + Prev Data",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "Basic LLM Chain",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Download Dummy Data": {
"main": [
[
{
"node": "make that excel to something usuable",
"type": "main",
"index": 0
}
]
]
},
"Is the result valid?": {
"main": [
[
{
"node": "Coupon them or not to Coupon them",
"type": "main",
"index": 0
}
],
[
{
"node": "AI did fail us",
"type": "main",
"index": 0
}
]
]
},
"AI Output + Prev Data": {
"main": [
[
{
"node": "Is the result valid?",
"type": "main",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "Basic LLM Chain",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Html Template for our Email": {
"main": [
[
{
"node": "The composed E-Mail + Prev Data",
"type": "main",
"index": 0
}
]
]
},
"Some Options for the Campagin": {
"main": [
[
{
"node": "Basic LLM Chain",
"type": "main",
"index": 0
},
{
"node": "AI Output + Prev Data",
"type": "main",
"index": 1
}
]
]
},
"The composed E-Mail + Prev Data": {
"main": [
[
{
"node": "Send Email",
"type": "main",
"index": 0
}
]
]
},
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Download Dummy Data",
"type": "main",
"index": 0
}
]
]
},
"Coupon them or not to Coupon them": {
"main": [
[
{
"node": "Html Template for our Email",
"type": "main",
"index": 0
},
{
"node": "The composed E-Mail + Prev Data",
"type": "main",
"index": 1
}
],
[
{
"node": "Fake Coupon",
"type": "main",
"index": 0
},
{
"node": "The composed E-Mail with Coupon + Prev Data",
"type": "main",
"index": 0
}
]
]
},
"make that excel to something usuable": {
"main": [
[
{
"node": "Some Options for the Campagin",
"type": "main",
"index": 0
}
]
]
},
"Html Template for our Email with a Coupon": {
"main": [
[
{
"node": "The composed E-Mail with Coupon + Prev Data",
"type": "main",
"index": 1
}
]
]
},
"The composed E-Mail with Coupon + Prev Data": {
"main": [
[
{
"node": "Send Email",
"type": "main",
"index": 0
}
]
]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment