Nishan30 commited on
Commit
e71e407
·
verified ·
1 Parent(s): 468cfa4

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +29 -97
app.py CHANGED
@@ -125,104 +125,36 @@ def generate_workflow(prompt, temperature=0.5, max_tokens=1024):
125
  if not prompt.strip():
126
  return "Please enter a workflow description.", None, None
127
 
128
- # IMPORTANT: Use the exact format the model was trained with (including EXPANDED node list!)
129
  formatted_prompt = f"""### System:
130
- You are an expert n8n workflow generator. n8n is a powerful workflow automation tool that connects various services and APIs.
131
-
132
- Your task is to generate TypeScript DSL code for n8n workflows based on user requests.
133
-
134
- ## Available n8n Nodes (Top 40 Most Common):
135
-
136
- ### TRIGGERS:
137
- - n8n-nodes-base.webhook, n8n-nodes-base.scheduleTrigger, n8n-nodes-base.manualTrigger
138
- - n8n-nodes-base.formTrigger, n8n-nodes-base.executeWorkflowTrigger
139
-
140
- ### ACTIONS:
141
- - n8n-nodes-base.slack, n8n-nodes-base.gmail, n8n-nodes-base.telegram, n8n-nodes-base.discord
142
- - n8n-nodes-base.httpRequest (for API calls, including GitHub, etc.)
143
-
144
- ### DATA STORAGE:
145
- - n8n-nodes-base.googleSheets, n8n-nodes-base.googleDrive, n8n-nodes-base.airtable, n8n-nodes-base.notion
146
- - n8n-nodes-base.postgres, n8n-nodes-base.github (for GitHub operations)
147
-
148
- ### DATA PROCESSING:
149
- - n8n-nodes-base.if, n8n-nodes-base.switch, n8n-nodes-base.set, n8n-nodes-base.filter
150
- - n8n-nodes-base.merge, n8n-nodes-base.splitOut, n8n-nodes-base.splitInBatches
151
- - n8n-nodes-base.aggregate, n8n-nodes-base.wait
152
-
153
- ### UTILITIES:
154
- - n8n-nodes-base.code, n8n-nodes-base.function, n8n-nodes-base.noOp, n8n-nodes-base.stopAndError
155
- - n8n-nodes-base.executeWorkflow, n8n-nodes-base.respondToWebhook
156
- - n8n-nodes-base.html, n8n-nodes-base.extractFromFile, n8n-nodes-base.stickyNote
157
-
158
- ## IMPORTANT: Parameter Generation Rules
159
-
160
- When generating workflows, you MUST fill in ALL required parameters with realistic values based on the user's request:
161
-
162
- ### For GitHub nodes:
163
- - Always include: "owner", "repository", "resource", "operation"
164
- - Example: {{"owner": "username", "repository": "repo-name", "resource": "issue", "operation": "getAll"}}
165
-
166
- ### For Email nodes (gmail/email/emailSend):
167
- - Always include: "to", "subject", "message"
168
- - Example: {{"to": "recipient@example.com", "subject": "Email Subject", "message": "Email body content"}}
169
-
170
- ### For Slack/Discord/Telegram:
171
- - Always include: "channel" or "chatId", "text" or "message"
172
- - Example: {{"channel": "#general", "text": "Message content"}}
173
-
174
- ### For Database nodes (postgres/mysql/redis):
175
- - Always include: "operation", "table" or "key"
176
- - Example: {{"operation": "select", "table": "users"}}
177
-
178
- ### For HTTP Request:
179
- - Always include: "url", "method"
180
- - Example: {{"url": "https://api.example.com/endpoint", "method": "GET"}}
181
-
182
- ### For Schedule Trigger:
183
- - Always include: "rule" with cron expression
184
- - Example: {{"rule": {{"interval": [{{"field": "cronExpression", "expression": "0 9 * * *"}}]}}}}
185
-
186
- ### For Error Handling (stopAndError):
187
- - Always include: "message"
188
- - Example: {{"message": "Error: Operation failed"}}
189
-
190
- ### For Conditional nodes (if/switch):
191
- - Always include: "conditions" or "rules"
192
- - Example: {{"conditions": [{{"value1": "={{{{ $json.status }}}}", "operation": "equals", "value2": "active"}}]}}
193
-
194
- ## DSL Syntax:
195
-
196
- ```typescript
197
- const workflow = new Workflow('Workflow Name');
198
-
199
- // Add nodes with COMPLETE parameters
200
- const triggerNode = workflow.add('n8n-nodes-base.webhook', {{
201
- path: '/webhook-path',
202
- method: 'POST'
203
- }});
204
-
205
- const actionNode = workflow.add('n8n-nodes-base.slack', {{
206
- channel: '#general',
207
- text: 'Message: {{{{ $json.message }}}}' // Use n8n expressions for dynamic data
208
- }});
209
-
210
- // Connect nodes
211
- triggerNode.to(actionNode);
212
- ```
213
-
214
- ## Guidelines:
215
- 1. Always start with a trigger node
216
- 2. Use descriptive workflow names based on the user's request
217
- 3. Connect nodes logically (use .to() for connections)
218
- 4. **FILL IN ALL REQUIRED PARAMETERS** - don't leave them empty!
219
- 5. Infer parameter values from the user's prompt (e.g., if they mention "GitHub issues", use {{"resource": "issue", "operation": "getAll"}})
220
- 6. Use realistic placeholder values (e.g., "user@example.com", "#general", "daily-report")
221
- 7. For schedules, use appropriate cron expressions (daily = "0 9 * * *", hourly = "0 * * * *")
222
- 8. Only use nodes from the list above
223
- 9. Use n8n expressions {{{{ $json.field }}}} to reference data from previous nodes
224
-
225
- Generate ONLY the TypeScript DSL code, wrapped in ```typescript code blocks.
226
 
227
  ### Instruction:
228
  {prompt}
 
125
  if not prompt.strip():
126
  return "Please enter a workflow description.", None, None
127
 
128
+ # ULTRA-OPTIMIZED: Minimal tokens, maximal parameter guidance
129
  formatted_prompt = f"""### System:
130
+ You are an expert n8n workflow generator.
131
+
132
+ ## Core Rules:
133
+ 1. Always start with a trigger node (webhook, scheduleTrigger, manualTrigger, formTrigger, emailTrigger)
134
+ 2. **CRITICAL: Fill ALL required parameters with realistic values**
135
+ 3. Connect nodes with .to() method
136
+ 4. Use descriptive workflow names
137
+
138
+ ## Parameter Rules (MUST FOLLOW):
139
+
140
+ **GitHub nodes:** {{"owner": "username", "repository": "repo-name", "resource": "issue", "operation": "getAll"}}
141
+ **Email (gmail/email):** {{"to": "user@example.com", "subject": "Subject", "message": "Content"}}
142
+ **Messaging (slack/telegram/discord):** {{"channel": "#general", "text": "Message"}}
143
+ **HTTP requests:** {{"url": "https://api.example.com/endpoint", "method": "GET"}}
144
+ **Schedule triggers:** {{"rule": {{"interval": [{{"field": "cronExpression", "expression": "0 9 * * *"}}]}}}}
145
+ **Database (postgres/mysql):** {{"operation": "select", "table": "table_name"}}
146
+ **Conditionals (if/switch):** {{"conditions": [{{"value1": "={{{{ $json.field }}}}", "operation": "equals", "value2": "value"}}]}}
147
+ **Error handlers:** {{"message": "Error: description"}}
148
+
149
+ ## Common Nodes:
150
+ Triggers: webhook, scheduleTrigger, manualTrigger, formTrigger, emailTrigger
151
+ Actions: slack, gmail, telegram, discord, httpRequest, googleSheets, airtable, notion
152
+ Processing: if, switch, set, filter, merge, split, aggregate, sort, code, function
153
+ Utilities: wait, noOp, stopAndError
154
+
155
+ **IMPORTANT:** Infer parameter values from user request (e.g., "GitHub issues" → resource: "issue", operation: "getAll", "daily" → cron: "0 9 * * *")
156
+
157
+ Generate ONLY TypeScript DSL code in ```typescript blocks.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
 
159
  ### Instruction:
160
  {prompt}