Upload app.py with huggingface_hub
Browse files
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 |
-
#
|
| 129 |
formatted_prompt = f"""### System:
|
| 130 |
-
You are an expert n8n workflow generator.
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 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}
|