Generate static MD tip files for Drupal development tips using various LLM providers
Project description
Drupal Tip Generator
Generate static MD tip files for the drupal-tip skill using various LLM providers.
Setup
1. Create Virtual Environment
cd ~/.claude/skills/drupal-tip
python3 -m venv .venv
source .venv/bin/activate
pip install openai anthropic
2. Configure API Keys
Copy the example environment file and add your keys:
cp .env.example .env
Edit .env with your API keys (use TIPGEN_ prefix):
TIPGEN_ANTHROPIC_API_KEY=sk-ant-...
TIPGEN_OPENAI_API_KEY=sk-...
TIPGEN_OPENROUTER_API_KEY=sk-or-...
Usage
Get a Random Existing Tip (FAST!)
Get a tip from the pre-generated database instantly — no API call needed:
.venv/bin/python tip_generator.py --random-tip
.venv/bin/python tip_generator.py --random-tip --tip-category core-service
.venv/bin/python tip_generator.py --list-existing
List Available Categories
.venv/bin/python tip_generator.py --list-categories
Generate Tips
Using Anthropic:
.venv/bin/python tip_generator.py -c 35 -n 5 -p anthropic
Using OpenAI (batch mode - 50% cheaper):
.venv/bin/python tip_generator.py -c 35 -n 5 -p openai
Using OpenRouter:
.venv/bin/python tip_generator.py -c 35 -n 5 -p openrouter
Arguments
| Argument | Description |
|---|---|
-c, --category |
Category number(s) or all |
-n, --count |
Number of tips per category (default: 5) |
-p, --provider |
LLM provider: anthropic, openai, openrouter |
-m, --model |
Override default model |
-u, --api-url |
Custom API URL for OpenAI/Anthropic-compatible endpoints |
-t, --max-tokens |
Maximum tokens for response (default: 4096) |
--tips-dir |
Custom tips directory (or set TIPGEN_TIPS_DIR env var or tips_dir in config.json) |
--save-truncated |
Save tips even if truncated (use with caution) |
--no-wait |
Don't wait for batch completion |
--dry-run |
Show what would be done without calling API |
--list-categories |
List all available categories |
--random-tip |
Get a random existing tip (fast, no API) |
--list-existing |
List categories with existing tips |
--tip-category |
Filter random tip by category name |
--validate |
Enable validation mode |
--validate-file |
Validate a specific tip file |
--validate-category |
Validate all tips in a category |
--validate-all |
Validate all tips across all categories |
Examples
# Generate 3 tips for category 35 (core-service)
.venv/bin/python tip_generator.py -c 35 -n 3 -p openrouter
# Generate 5 tips for multiple categories
.venv/bin/python tip_generator.py -c 35,36,37 -n 5 -p openrouter
# Generate 1 tip for ALL categories
.venv/bin/python tip_generator.py -c all -n 1 -p openrouter
# Use a specific model
.venv/bin/python tip_generator.py -c 35 -n 5 -p openrouter -m anthropic/claude-opus-4
# Use a custom API URL (e.g., Together.xyz, local LLM server)
.venv/bin/python tip_generator.py -c 35 -n 5 -p openai -u https://api.together.xyz/v1
# Increase max tokens for longer responses (avoid truncation)
.venv/bin/python tip_generator.py -c 60 -n 20 -p openai --max-tokens 8192
# Save tips even if truncated (use with caution)
.venv/bin/python tip_generator.py -c 35 -n 5 -p openai --save-truncated
Batch API Notes
| Provider | Batch Support | Discount | Notes |
|---|---|---|---|
| Anthropic | Yes | 50% | Uses message-batches-2024-09-24 beta |
| OpenAI | Yes | 50% | Results within 24h |
| OpenRouter | ⚠️ Sync only | - | Batch API not supported |
Check Batch Status
If you ran batch mode with --no-wait:
.venv/bin/python tip_generator.py --check-batch BATCH_ID -p anthropic
.venv/bin/python tip_generator.py --check-batch BATCH_ID -p openai --save-results
Output
Tips are saved to tips/{category-name}/{uuid}.md with 8-character random IDs:
tips/
├── core-service/
│ ├── a1b2c3d4.md
│ └── e5f6g7h8.md
└── rare-drush-command/
└── 9i0j1k2l.md
Each file has frontmatter:
---
category: core-service
title: [Generated title]
---
[Tip content]
Configuration
Categories and the prompt template are defined in config.json:
{
"prompt_template": "Generate a Drupal tip for category #{cat_id}: {cat_desc}...",
"code_language": "php",
"tips_dir": "/path/to/custom/tips",
"categories": {
"1": {"name": "proposed-new-module", "desc": "Proposed new module"},
"35": {"name": "core-service", "desc": "Lesser-known core service"}
}
}
Tips Directory Configuration
The tips directory can be configured via (in priority order):
- CLI argument:
--tips-dir /path/to/tips - Environment variable:
TIPGEN_TIPS_DIR=/path/to/tips - Config file:
"tips_dir": "/path/to/tips"inconfig.json - Default:
tips/folder in the package directory
To add or modify categories, edit config.json directly - no code changes needed.
Development
Running Tests
# Dry run to verify configuration
.venv/bin/python tip_generator.py -c 35 -n 1 -p openrouter --dry-run
Validation
Validate generated tips for formatting issues, truncation, and quality:
# Validate a single file
.venv/bin/python tip_generator.py --validate --validate-file tips/core-service/a1b2c3d4.md
# Validate all tips in a category
.venv/bin/python tip_generator.py --validate --validate-category core-service
# Validate ALL tips across all categories
.venv/bin/python tip_generator.py --validate --validate-all
Validation Checks
- Formatting: Frontmatter structure, code block balance, line counts
- Completeness: Truncation patterns (trailing
...,[TODO], incomplete code blocks) - Quality: Generic openings, placeholder text, excessive code ratio
- Fake Content: Non-existent Drupal APIs, hallucinated functions, wrong service names
Web Viewer
A simple web UI to browse tips:
pip install flask
python tip_viewer.py # http://localhost:5000
python tip_viewer.py --port 8080 # Custom port
python tip_viewer.py --host 0.0.0.0 # Public access
python tip_viewer.py --debug # Debug mode
Features:
- Filter tips by category
- Get random tip with one click
- View all tips or browse by category
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drupaltools_tip_generator-0.1.0.tar.gz.
File metadata
- Download URL: drupaltools_tip_generator-0.1.0.tar.gz
- Upload date:
- Size: 42.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
008d4f7efa9cceb8cfbc96e44bebd395ba63aba4314db871244aa3e67dee875c
|
|
| MD5 |
751cce83de73093be9bd156279633e05
|
|
| BLAKE2b-256 |
5a65f6d05573b21037056d689f533430e0d4f829c52448156e305fc5c518a563
|
File details
Details for the file drupaltools_tip_generator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: drupaltools_tip_generator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 30.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c21b484798b3a68f332c70380eafc568d05eadc26a6ec267927a9cc2692b1c93
|
|
| MD5 |
37f5b7f169acfab66936708bf6aee93a
|
|
| BLAKE2b-256 |
82994c0db66ff660d11c018eee059f410a837cb1f362129fa8c80b2509499264
|