fchis/laravel-buildspec-training
收藏资源简介:
--- license: mit language: - en - php tags: - laravel - php - code-generation - fine-tuning - buildspec task_categories: - text-generation pretty_name: Laravel 13.x BuildSpec → Code Training Dataset size_categories: - n<1K --- # Laravel 13.x BuildSpec → Code Training Dataset Training data for fine-tuning code generation models to convert structured **BuildSpec JSON** objects into Laravel 13.x PHP files. This dataset was used to train [fchis/Laravel-13x-Qwen2.5-Coder-7B-Instruct-LoRA-Spec](https://huggingface.co/fchis/Laravel-13x-Qwen2.5-Coder-7B-Instruct-LoRA-Spec). ## What is BuildSpec? BuildSpec is a structured JSON format that unambiguously describes a single Laravel artifact (model, migration, controller, resource, form_request, or pest_test). Instead of asking the model to interpret natural language, you give it an exact specification: ```json { "laravel_version": "13.x", "artifact": "model", "class": "Subscriber", "namespace": "App\\Models", "table": "subscribers", "has_factory": true, "soft_deletes": false, "fillable": ["email", "name", "status", "subscribed_at"], "casts": {"subscribed_at": "datetime"}, "relationships": [], "scopes": [ {"name": "active", "column": "status", "value": "active"} ] } ``` The model outputs the complete PHP file — no markdown, no explanations. ## Why BuildSpec? The spec approach **shifts error type** from semantic hallucinations (hard to fix) to specification gaps (compiler-catchable): | Approach | Error type | Fix method | |----------|-----------|-----------| | Natural language prompt | Model invents things not asked for | Runtime debugging | | BuildSpec JSON | Wrong field names, missing spec fields | Spec compiler validates before generation | ## Dataset Statistics | Split | Examples | Artifacts | |-------|----------|-----------| | train | 49 | model(14), resource(8), controller(8), form_request(10), pest_test(5), migration(4) | | valid | 5 | mixed | ## Format Each example uses the OpenAI chat format: ```json { "messages": [ {"role": "system", "content": "You are a Laravel 13.x PHP code generator..."}, {"role": "user", "content": "{...BuildSpec JSON...}"}, {"role": "assistant", "content": "<?php\nnamespace App\\Models;\n..."} ] } ``` ## Artifact Reference ### model ```json { "artifact": "model", "class": "Post", "namespace": "App\\Models", "table": "posts", "has_factory": true, "soft_deletes": false, "fillable": ["title", "body", "user_id"], "casts": {"published_at": "datetime"}, "relationships": [ {"type": "BelongsTo", "model": "User", "method": "author", "foreign_key": "user_id"}, {"type": "HasMany", "model": "Comment", "method": "comments"}, {"type": "BelongsToMany", "model": "Tag", "method": "tags"} ], "scopes": [ {"name": "published", "column": "status", "value": "published"} ] } ``` ### controller ```json { "artifact": "controller", "class": "PostController", "namespace": "App\\Http\\Controllers\\Api", "model": "Post", "resource": "PostResource", "form_request": "StorePostRequest", "validation_mode": "form_request", "eager_load": ["author", "tags"], "paginate": 15, "filters": ["status"], "many_to_many": {"relation": "tags", "input_key": "tag_ids"} } ``` ### form_request (with conditional rules) ```json { "artifact": "form_request", "class": "StoreEventRequest", "namespace": "App\\Http\\Requests", "rules": { "title": ["required", "string", "max:255"], "venue_id": [], "event_date": ["required", "date"] }, "conditional_rules": { "venue_id": { "POST": ["required", "integer", "exists:venues,id"], "PUT": ["sometimes", "integer", "exists:venues,id"] }, "event_date": { "POST": ["after:now"] } } } ``` **Important**: Never use literal conditional tokens like `"required_on_post"` in `rules[]`. Use `conditional_rules{}` instead. The [spec compiler](https://github.com/florinel-chis/laravel-ai-gen) rejects them. ### resource ```json { "artifact": "resource", "class": "PostResource", "namespace": "App\\Http\\Resources", "fields": [ {"key": "id", "source": "id"}, {"key": "title", "source": "title"}, {"key": "created_at", "source": "created_at"} ], "loaded_relations": [ {"key": "author", "resource": "AuthorResource", "type": "make"}, {"key": "tags", "resource": "TagResource", "type": "collection"} ] } ``` ### pest_test ```json { "artifact": "pest_test", "class": "Post", "namespace": "Tests\\Feature", "model": "App\\Models\\Post", "endpoints": [ {"method": "GET", "path": "/api/posts", "action": "index"}, {"method": "POST", "path": "/api/posts", "action": "store"}, {"method": "GET", "path": "/api/posts/{id}", "action": "show"}, {"method": "PUT", "path": "/api/posts/{id}", "action": "update"}, {"method": "DELETE", "path": "/api/posts/{id}", "action": "destroy"} ], "required_on_create": ["title", "body"] } ``` ## Full Pipeline See [laravel-ai-gen](https://github.com/florinel-chis/laravel-ai-gen) for the complete pipeline: ```bash # NL → specs → compile → generate PHP files python3 pipeline_spec.py "Create a REST API for managing blog posts with tags" ``` Pipeline stages: 1. **Planner** (`planner.py`): NL description → BuildSpec JSON array (few-shot) 2. **Compiler** (`spec_compiler.py`): validates + normalizes each spec 3. **Generator**: each spec → PHP file (this model) 4. **Syntax check**: `php -l` on all written files ## Training Details - **Base model**: `Qwen2.5-Coder-7B-Instruct` (4-bit quantized via MLX) - **Method**: LoRA (rank 8, `--num-layers 8`) - **Training framework**: `mlx-lm` - **Hardware**: Apple M2 Pro 16GB - **Iterations**: 225 cumulative (5 rounds: 100+25+25+25+50) - **Final val_loss**: 0.065 - **Command**: ```bash mlx_lm.lora \ --model mlx-community/Qwen2.5-Coder-7B-Instruct-4bit \ --train \ --data data_spec \ --adapter-path adapters_spec \ --batch-size 1 --iters 100 \ --learning-rate 1e-5 \ --num-layers 8 \ --max-seq-length 1400 ``` ## Results Tested on a 3-app benchmark (Subscriber API, Book Library, Event Management): | Metric | Score | |--------|-------| | PHP syntax valid | 26/26 (100%) | | Eval perfect (0 bugs) | 26/26 (100%) | | Pest tests pass | 20/20 (100%) | | Manual fixes needed | 3 (SoftDeletes trait, JsonResource import, repetition loop) | ## Citation ```bibtex @misc{laravel-buildspec-2026, author = {Florinel Chis}, title = {Laravel 13.x BuildSpec to Code Training Dataset}, year = {2026}, publisher = {Hugging Face}, url = {https://huggingface.co/datasets/fchis/laravel-buildspec-training} } ```





