Team Ai
Modelpublic

Nishan30/n8n-workflow-generator

sourceHugging Faceapache-2.0updated 10mo agoView on Hugging Face
0likes40downloads
Model Card

๐Ÿš€ n8n Workflow Generator v1.0

A fine-tuned Qwen2.5-Coder-1.5B model that generates n8n workflows using TypeScript DSL.

๐Ÿ“Š Performance (Comprehensive Testing)

Overall Score: 91.8% โœจ (24 diverse test cases)

Detailed Results by Category:

CategoryScoreTests
Simple Webhook92.2%3
Conditional Routing93.3%3
Scheduled Tasks95.6%3
Form Processing93.3%2
Multi-Service Integration83.3%3
Data Processing93.3%3
Error Handling88.9%3
Complex Multi-Step91.7%2
Manual & Email Triggers96.7%2

Test Score Breakdown:

  • โ€”Basic Checks: 98% (syntax, structure, node types)
  • โ€”Structural Checks: 83% (connections, flow logic)
  • โ€”N8N-Specific: 97% (valid nodes, DSL conventions)

Grade Distribution:

  • โ€”๐ŸŸข A (Excellent): 83% of test cases
  • โ€”๐ŸŸก B (Good): 13% of test cases
  • โ€”๐Ÿ”ด D (Poor): 4% of test cases

๐ŸŽฏ What It Does

Converts natural language descriptions into production-ready n8n workflows:

Input: "Create a webhook that sends data to Slack"

Output:

typescript
const workflow = new Workflow('Webhook to Slack');
const webhook = workflow.add('n8n-nodes-base.webhook', {{
  path: '/data',
  method: 'POST'
}});
const slack = workflow.add('n8n-nodes-base.slack', {{
  channel: '#general',
  text: '={{{{ $json.message }}}}'
}});
webhook.to(slack);

๐Ÿš€ Quick Start

Option 1: Using LoRA Adapter (Recommended)

python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch

# Load base model
base_model = AutoModelForCausalLM.from_pretrained(
    "Qwen/Qwen2.5-Coder-1.5B-Instruct",
    torch_dtype=torch.float16,
    device_map="auto"
)

# Load fine-tuned adapter
model = PeftModel.from_pretrained(base_model, "Nishan30/n8n-workflow-generator")
tokenizer = AutoTokenizer.from_pretrained("Nishan30/n8n-workflow-generator")

# System prompt
system_prompt = """You are an expert n8n workflow generator. Given a user's request, you generate clean, functional TypeScript code using the @n8n-generator/core DSL.

Your output should:
- Only contain the code, no explanations
- Use the Workflow class from @n8n-generator/core
- Use workflow.add() to create nodes
- Use .to() or workflow.connect() for connections
- Be ready to compile directly to n8n JSON"""

# Generate
user_request = "Create a webhook that sends data to Slack"
messages = [
    {{"role": "system", "content": system_prompt}},
    {{"role": "user", "content": user_request}}
]

text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)

outputs = model.generate(
    **inputs,
    max_new_tokens=512,
    temperature=0.3,
    do_sample=True,
    top_p=0.9,
    repetition_penalty=1.1
)

result = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(result)

Option 2: Using Transformers Pipeline

python
from transformers import pipeline

generator = pipeline(
    "text-generation",
    model="Nishan30/n8n-workflow-generator",
    device_map="auto"
)

prompt = "Create a scheduled workflow that fetches data daily and sends to Slack"
result = generator(prompt, max_new_tokens=512, temperature=0.3)
print(result[0]['generated_text'])

๐ŸŒŸ Supported Workflow Patterns

โœ… Triggers

  • โ€”webhook - HTTP endpoints
  • โ€”scheduleTrigger - Cron-based scheduling
  • โ€”manualTrigger - Manual execution
  • โ€”formTrigger - Form submissions
  • โ€”emailTrigger - Email-based triggers

โœ… Actions & Integrations

  • โ€”slack, discord, telegram - Messaging
  • โ€”gmail, email - Email sending
  • โ€”httpRequest - API calls
  • โ€”googleSheets, airtable, notion - Databases
  • โ€”And more...

โœ… Data Processing

  • โ€”if, switch - Conditional logic
  • โ€”set, filter, merge - Data transformation
  • โ€”code - Custom JavaScript/Python
  • โ€”stopAndError - Error handling

๐Ÿ“ˆ Training Details

Dataset

  • โ€”Total Examples: 2,736 workflows
  • โ€”Training Set: 2,462 examples
  • โ€”Validation Set: 274 examples
  • โ€”Pattern Coverage: 7 major workflow patterns
  • โ€”Quality: Curated from production n8n workflows

Training Configuration

  • โ€”Base Model: Qwen/Qwen2.5-Coder-1.5B-Instruct
  • โ€”Method: LoRA (Low-Rank Adaptation)
  • โ€”LoRA Rank: 16
  • โ€”LoRA Alpha: 16
  • โ€”Learning Rate: 2e-4
  • โ€”Batch Size: 2 (effective: 8 with gradient accumulation)
  • โ€”Epochs: 10
  • โ€”Hardware: NVIDIA Tesla T4 GPU (16GB)
  • โ€”Framework: Transformers + Unsloth

Optimization

  • โ€”โœ… 4-bit quantization for memory efficiency
  • โ€”โœ… Gradient checkpointing
  • โ€”โœ… Flash Attention 2
  • โ€”โœ… Early stopping based on validation loss

๐ŸŽจ Example Workflows

1. Simple Webhook to Slack

User: "Create a webhook that posts to Slack"
Model: [Generates complete TypeScript DSL code]

2. Scheduled Data Sync

User: "Daily workflow that fetches API data and stores in database"
Model: [Generates schedule trigger + HTTP request + database storage]

3. Form Processing

User: "Contact form that validates and sends email"
Model: [Generates form trigger + validation + email sending]

4. Conditional Routing

User: "Route high-priority items to #urgent, others to #general"
Model: [Generates webhook + if condition + dual Slack outputs]

๐ŸŒ Try It Online

Hugging Face Space: [Coming Soon]

๐Ÿ“Š Benchmark Comparison

ModelSizeAccuracySpeedUse Case
n8n-workflow-generator1.5B91.8%FastProduction-ready
GPT-3.5 (baseline)175B~85%SlowGeneral purpose
CodeLlama-7B7B~88%MediumCode generation

๐Ÿ”ง Advanced Usage

Custom System Prompt

python
custom_prompt = """You are a workflow expert. Generate n8n workflows with:
- Error handling for all HTTP requests
- Descriptive node names
- Production-ready configurations
"""

Batch Generation

python
requests = [
    "webhook to slack",
    "daily email report",
    "form to database"
]

for req in requests:
    workflow = generate_workflow(req)
    print(workflow)

Integration with n8n

python
import json
from n8n_generator import compile_to_json

# Generate DSL
dsl_code = model.generate(prompt)

# Compile to n8n JSON
workflow_json = compile_to_json(dsl_code)

# Import to n8n
# POST to http://your-n8n-instance/api/v1/workflows

๐Ÿ“ Limitations

  • โ€”Complex Logic: May struggle with very complex multi-branch workflows (>10 nodes)
  • โ€”Custom Nodes: Only supports built-in n8n nodes
  • โ€”Edge Cases: Occasionally generates invalid node names (~8% of cases)

Mitigation: Add post-processing validation layer (see documentation)

๐Ÿšง Roadmap

  • โ€”[ ] v1.1: Expand to 7B model for better accuracy (target: 95%+)
  • โ€”[ ] v1.2: Add support for custom n8n nodes
  • โ€”[ ] v1.3: Multi-language support (Python, JavaScript execution nodes)
  • โ€”[ ] v2.0: Fine-tune on user feedback data

๐Ÿ“„ License

Apache 2.0

๐Ÿ™ Acknowledgments

Built with:

๐Ÿ“ง Contact


โญ Star this model if you find it useful!

Last updated: December 2024