gauthierlmd commited on
Commit
7bc002e
·
verified ·
1 Parent(s): 40a7eec

Delete Book Sales AI Analyst (4) (1).json

Browse files
Files changed (1) hide show
  1. Book Sales AI Analyst (4) (1).json +0 -182
Book Sales AI Analyst (4) (1).json DELETED
@@ -1,182 +0,0 @@
1
- {
2
- "name": "Book Sales AI Analyst",
3
- "nodes": [
4
- {
5
- "parameters": {
6
- "httpMethod": "POST",
7
- "path": "ai-analyst",
8
- "responseMode": "responseNode",
9
- "options": {}
10
- },
11
- "id": "85a90776-f2df-4c3f-8a55-ae8316972b26",
12
- "name": "Webhook Trigger",
13
- "type": "n8n-nodes-base.webhook",
14
- "typeVersion": 2,
15
- "position": [
16
- 0,
17
- 0
18
- ],
19
- "webhookId": "ai-analyst"
20
- },
21
- {
22
- "parameters": {
23
- "jsCode": "const question = $input.first().json.body?.question || $input.first().json.question || \"No question provided\";\n\nconst dataSummary = {\n total_books: 1000,\n total_months: 18,\n total_units_sold: 2847500,\n avg_monthly_sales: 158194,\n sentiment_split: \"42% positive, 31% neutral, 27% negative\",\n top_sellers: [\n \"Sapiens: A Brief History of Humankind (14,580 units)\",\n \"Sharp Objects (11,890 units)\",\n \"Tipping the Velvet (10,230 units)\"\n ],\n available_charts: [\"sales\", \"sentiment\", \"top_sellers\"]\n};\n\nreturn [{ json: { question, dataSummary } }];"
24
- },
25
- "id": "13e1b70f-3b3c-4fd4-a5d3-e05747056e4b",
26
- "name": "Prepare Data Context",
27
- "type": "n8n-nodes-base.code",
28
- "typeVersion": 2,
29
- "position": [
30
- 224,
31
- 0
32
- ]
33
- },
34
- {
35
- "parameters": {
36
- "jsCode": "const question = $input.first().json.question;\nconst data = $input.first().json.dataSummary;\n\nconst prompt = `You are a data analyst assistant for a book sales analytics project.\n\nHere is a summary of the dataset:\n- ${data.total_books} book titles tracked over ${data.total_months} months\n- ${data.total_units_sold.toLocaleString()} total units sold (avg ${data.avg_monthly_sales.toLocaleString()}/month)\n- Review sentiment: ${data.sentiment_split}\n- Top sellers: ${data.top_sellers.join(\"; \")}\n- Available charts: ${data.available_charts.join(\", \")}\n\nThe user asks: \"${question}\"\n\nGive a concise answer (2-3 sentences). Then on a new line, write CHART: followed by the single most relevant chart name from this list: sales, sentiment, top_sellers. If no chart fits, write CHART: none`;\n\nreturn [{ json: { prompt, question } }];"
37
- },
38
- "id": "ae8645d7-9bef-4313-be5a-6faad9c9487c",
39
- "name": "Build Prompt",
40
- "type": "n8n-nodes-base.code",
41
- "typeVersion": 2,
42
- "position": [
43
- 448,
44
- 0
45
- ]
46
- },
47
- {
48
- "parameters": {
49
- "method": "POST",
50
- "url": "https://router.huggingface.co/v1/chat/completions",
51
- "authentication": "genericCredentialType",
52
- "genericAuthType": "httpBearerAuth",
53
- "sendHeaders": true,
54
- "headerParameters": {
55
- "parameters": [
56
- {
57
- "name": "Content-Type",
58
- "value": "application/json"
59
- }
60
- ]
61
- },
62
- "sendBody": true,
63
- "specifyBody": "json",
64
- "jsonBody": "={\n \"model\": \"meta-llama/Llama-3.3-70B-Instruct\",\n \"messages\": [\n {\"role\": \"user\", \"content\": {{ JSON.stringify($json.prompt) }}}\n ],\n \"max_tokens\": 300,\n \"temperature\": 0.3\n}",
65
- "options": {}
66
- },
67
- "id": "d40da31a-4d83-4f2e-9556-5a09b4170fa8",
68
- "name": "Call HuggingFace LLM",
69
- "type": "n8n-nodes-base.httpRequest",
70
- "typeVersion": 4.2,
71
- "position": [
72
- 672,
73
- 0
74
- ],
75
- "credentials": {
76
- "httpHeaderAuth": {
77
- "id": "w8CYYaIhgcY9ICOp",
78
- "name": "Header Auth account 2"
79
- },
80
- "httpBearerAuth": {
81
- "id": "jsEGNzN4KBKKjkL7",
82
- "name": "Bearer Auth account"
83
- }
84
- }
85
- },
86
- {
87
- "parameters": {
88
- "jsCode": "const response = $input.first().json;\n\n// Extract text from the LLM response\nlet text = \"\";\ntry {\n text = response.choices[0].message.content;\n} catch (e) {\n text = response.generated_text || response.text || JSON.stringify(response);\n}\n\n// Extract the CHART: directive\nconst chartMatch = text.match(/CHART:\\s*(\\w+)/i);\nconst chart = chartMatch ? chartMatch[1].toLowerCase() : \"none\";\n\n// Validate chart name against known options\nconst validCharts = [\"sales\", \"sentiment\", \"top_sellers\", \"none\"];\nconst finalChart = validCharts.includes(chart) ? chart : \"none\";\n\n// Remove the CHART: line from the displayed answer\nconst answer = text.replace(/CHART:.*$/im, \"\").trim();\n\nreturn [{ json: { answer, chart: finalChart, status: \"ok\" } }];"
89
- },
90
- "id": "678e59c0-aba1-45b3-8669-bc89153fffc4",
91
- "name": "Parse Response",
92
- "type": "n8n-nodes-base.code",
93
- "typeVersion": 2,
94
- "position": [
95
- 896,
96
- 0
97
- ]
98
- },
99
- {
100
- "parameters": {
101
- "options": {}
102
- },
103
- "id": "ebfe7af0-90e4-4c3f-a364-8a3c7a2aa880",
104
- "name": "Respond to Webhook",
105
- "type": "n8n-nodes-base.respondToWebhook",
106
- "typeVersion": 1.1,
107
- "position": [
108
- 1120,
109
- 0
110
- ]
111
- }
112
- ],
113
- "pinData": {},
114
- "connections": {
115
- "Webhook Trigger": {
116
- "main": [
117
- [
118
- {
119
- "node": "Prepare Data Context",
120
- "type": "main",
121
- "index": 0
122
- }
123
- ]
124
- ]
125
- },
126
- "Prepare Data Context": {
127
- "main": [
128
- [
129
- {
130
- "node": "Build Prompt",
131
- "type": "main",
132
- "index": 0
133
- }
134
- ]
135
- ]
136
- },
137
- "Build Prompt": {
138
- "main": [
139
- [
140
- {
141
- "node": "Call HuggingFace LLM",
142
- "type": "main",
143
- "index": 0
144
- }
145
- ]
146
- ]
147
- },
148
- "Call HuggingFace LLM": {
149
- "main": [
150
- [
151
- {
152
- "node": "Parse Response",
153
- "type": "main",
154
- "index": 0
155
- }
156
- ]
157
- ]
158
- },
159
- "Parse Response": {
160
- "main": [
161
- [
162
- {
163
- "node": "Respond to Webhook",
164
- "type": "main",
165
- "index": 0
166
- }
167
- ]
168
- ]
169
- }
170
- },
171
- "active": true,
172
- "settings": {
173
- "executionOrder": "v1",
174
- "binaryMode": "separate"
175
- },
176
- "versionId": "4edfa7dc-ca35-4720-b411-b944c0a66365",
177
- "meta": {
178
- "instanceId": "2a478a068d7524147d373a734d03976d66e0db58736dfc88729d101c6bb158da"
179
- },
180
- "id": "Og27xYenkIOL8s6H",
181
- "tags": []
182
- }