Update README with training data and usage instructions
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159---license: gemmabase_model: google/functiongemma-270m-ittags:- function-calling- litert- on-device- gemma- infrastructure- LiteRT-LMdatasets:- customlanguage:- enpipeline_tag: text-generation---# FunctionGemma Infrastructure LiteRT-LMA fine-tuned [FunctionGemma-270M](https://huggingface.co/google/functiongemma-270m-it) model converted to LiteRT-LM format for on-device inference. Designed for self-healing infrastructure and automatic error remediation.## Model Details| Property | Value ||----------|-------|| Base Model | google/functiongemma-270m-it || Format | LiteRT-LM (.litertlm) || Quantization | Dynamic INT8 || File Size | 272 MB || Parameters | 270M |## Intended UseThis model is designed for [dad-express](https://github.com/anthropics/dad-express), a self-healing gateway that monitors HTTP traffic and automatically fixes infrastructure configuration issues by calling the appropriate tools.## Supported ToolsThe model was fine-tuned on 9 infrastructure tools:| Tool | Description | Parameters ||------|-------------|------------|| `addProxyRoute` | Add reverse proxy route | path, upstream, port || `addCorsHeaders` | Configure CORS headers | origin, credentials || `configureSsl` | Configure SSL certificate | hostname, selfSigned || `setEnvVariable` | Set environment variable | name, value || `exposePort` | Expose port in Docker/firewall | service, port || `addHostEntry` | Add hostname to /etc/hosts | hostname, ip || `restartService` | Restart a service | service || `clearCache` | Clear cache | cacheType || `modifyConfig` | Modify config file | file, key, value |## Training Details### Dataset- **Total Examples**: 10,216- **Train/Eval Split**: 90/10 (9,194 train, 1,022 eval)- **Format**: Prompt-completion pairs using FunctionGemma chat template- **Distribution**: ~1,000-1,200 examples per tool (balanced)### Training ConfigurationTrained following [Google's official FunctionGemma fine-tuning notebook](https://colab.research.google.com/github/google-gemini/gemma-cookbook/blob/main/FunctionGemma/%5BFunctionGemma%5DFinetune_FunctionGemma_270M_for_Mobile_Actions_with_Hugging_Face.ipynb):```pythonSFTConfig(num_train_epochs=2,per_device_train_batch_size=4,gradient_accumulation_steps=8,learning_rate=1e-5,lr_scheduler_type="cosine",gradient_checkpointing=True,packing=False,optim="adamw_torch_fused",bf16=True,completion_only_loss=True, # Critical: only train on completion tokens)```### Hardware- **GPU**: NVIDIA L4 (24GB)- **Training Time**: ~23 minutes- **Conversion Time**: ~10 minutes### Performance Metrics| Metric | Value ||--------|-------|| Final Eval Loss | 0.034 || Token Accuracy | 98.6% || Training Steps | 576 |## LiteRT-LM ConversionConverted using [ai-edge-torch](https://github.com/google-ai-edge/ai-edge-torch):```pythonconverter.convert_to_litert(pytorch_model,prefill_seq_len=256,kv_cache_max_len=1024,quantize="dynamic_int8",output_format="litertlm",)```### LLM Metadata```protobufstart_token: { token_ids: { ids: [ 2 ] } }stop_tokens: { token_str: "<end_of_turn>" }stop_tokens: { token_str: "<start_function_response>" }llm_model_type: { function_gemma: {} }```## Usage### With LiteRT-LM Runtime```typescriptimport { LiteRTLM } from 'litert-lm';const model = await LiteRTLM.load('functiongemma-infrastructure_q8_ekv1024.litertlm');const response = await model.generate(prompt);```### Example Input/Output**Input:**```Error: CORS - No 'Access-Control-Allow-Origin' header from http://localhost:3000```**Output:**```<start_function_call>call:addCorsHeaders{origin:<escape>http://localhost:3000<escape>,credentials:<escape>true<escape>}<end_function_call><start_function_response>```## Dependencies- Python 3.11+- transformers==4.57.1- trl==0.25.1- datasets==4.4.1- ai-edge-torch-nightly- ai-edge-litert-nightly## LicenseThis model inherits the [Gemma Terms of Use](https://ai.google.dev/gemma/terms).## Citation```bibtex@misc{functiongemma-infrastructure-litertlm,title={FunctionGemma Infrastructure LiteRT-LM},author={dad-express contributors},year={2024},publisher={Hugging Face},url={https://huggingface.co/macmacmacmac/functiongemma-infrastructure-litertlm}}```123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219---license: gemmalanguage:- enbase_model:- google/functiongemma-270m-itpipeline_tag: text-generationtags:- function-calling- infrastructure- devops- litertlm---# FunctionGemma Infrastructure Tools v8A fine-tuned [FunctionGemma 270M](https://huggingface.co/google/functiongemma-270m-it) model for infrastructure error diagnosis and remediation. Achieves **100% accuracy** on 7 infrastructure tools when using the correct tool definitions.## Model Details- **Base Model**: google/functiongemma-270m-it- **Format**: LiteRT-LM (.litertlm) - optimized for on-device inference- **Quantization**: INT8 (Q8)- **Size**: ~271MB- **Training**: 50 epochs on 10,500 examples (1,500 per tool)## Supported Tools| Tool | Description | Use Case ||------|-------------|----------|| `enableCors` | Enable CORS for a specific origin | CORS policy errors, blocked cross-origin requests || `updateConnectionUrl` | Update service connection URL | ECONNREFUSED errors, localhost connection issues in containers || `setEnvVar` | Set environment variable | Missing configuration, undefined env vars || `addHostMapping` | Add hostname to IP mapping | DNS resolution (ENOTFOUND) errors || `increaseMemory` | Increase memory limit | OOMKilled errors, out of memory crashes || `increaseTimeout` | Increase timeout value | 504 Gateway Timeout, connection timeout errors || `restartService` | Restart a service | Stuck processes, stale data after deployment |## Usage with LiteRT-LM### Download the Model```bash# Using huggingface-clihuggingface-cli download macmacmacmac/functiongemma-nextjs functiongemma-infra-v8_q8_ekv1024.litertlm# Or using Pythonfrom huggingface_hub import hf_hub_downloadmodel_path = hf_hub_download(repo_id="macmacmacmac/functiongemma-nextjs",filename="functiongemma-infra-v8_q8_ekv1024.litertlm")```### Required Tool Definitions**Important**: You must use these exact tool definitions for optimal accuracy. The model was trained with these specific descriptions.```javascriptconst tools = [{type: "function",function: {name: "enableCors",description: "Enable CORS for a specific origin to fix blocked cross-origin requests.",parameters: {type: "object",properties: {origin: { type: "string", description: "The origin to allow (e.g., http://localhost:3000)" },methods: { type: "string", description: "Allowed HTTP methods (e.g., GET,POST,PUT,DELETE)" }},required: ["origin"]}}},{type: "function",function: {name: "updateConnectionUrl",description: "Update a service connection URL to fix ECONNREFUSED errors, typically changing localhost to the correct service hostname.",parameters: {type: "object",properties: {service: { type: "string", description: "The service to update (e.g., database, redis, api)" },hostname: { type: "string", description: "The correct hostname to connect to" },port: { type: "integer", description: "The port number to connect to" }},required: ["service", "hostname", "port"]}}},{type: "function",function: {name: "setEnvVar",description: "Set an environment variable to fix missing configuration errors.",parameters: {type: "object",properties: {name: { type: "string", description: "Environment variable name (e.g., DATABASE_URL, API_KEY)" },value: { type: "string", description: "The value to set" }},required: ["name", "value"]}}},{type: "function",function: {name: "addHostMapping",description: "Add a hostname to IP mapping to fix DNS resolution (ENOTFOUND) errors.",parameters: {type: "object",properties: {hostname: { type: "string", description: "The hostname to map" },ip: { type: "string", description: "The IP address to map to" }},required: ["hostname", "ip"]}}},{type: "function",function: {name: "increaseMemory",description: "Increase memory limit for a service to fix OOMKilled errors.",parameters: {type: "object",properties: {service: { type: "string", description: "The service/container/pod name" },memoryMb: { type: "integer", description: "Memory limit in megabytes" }},required: ["service", "memoryMb"]}}},{type: "function",function: {name: "increaseTimeout",description: "Increase timeout value to fix 504 Gateway Timeout or connection timeout errors.",parameters: {type: "object",properties: {service: { type: "string", description: "The service to configure" },timeoutMs: { type: "integer", description: "Timeout value in milliseconds" }},required: ["service", "timeoutMs"]}}},{type: "function",function: {name: "restartService",description: "Restart a service to apply configuration changes or fix a stuck process.",parameters: {type: "object",properties: {service: { type: "string", description: "The service/container/pod name to restart" }},required: ["service"]}}}];```### Example Usage with dad-express```javascriptconst { FunctionGemmaEngine } = require('dad-express');const engine = new FunctionGemmaEngine({modelPath: './functiongemma-infra-v8_q8_ekv1024.litertlm',tools: JSON.stringify(tools)});// Diagnose an errorconst result = await engine.call('Container api was OOMKilled - out of memory');console.log(result.tool_calls[0].function);// { name: 'increaseMemory', arguments: { service: 'api', memoryMb: 1024 } }```## Training DataThe model was trained on 10,500 synthetic examples covering common infrastructure errors:| Error Pattern | Tool | Examples ||--------------|------|----------|| CORS policy errors | enableCors | 1,500 || ECONNREFUSED errors | updateConnectionUrl | 1,500 || Missing env vars | setEnvVar | 1,500 || DNS/ENOTFOUND errors | addHostMapping | 1,500 || OOMKilled errors | increaseMemory | 1,500 || Timeout errors | increaseTimeout | 1,500 || Stuck services | restartService | 1,500 |### Sample Training Examples```"CORS error: No 'Access-Control-Allow-Origin' header from http://localhost:3000" → enableCors"Error: connect ECONNREFUSED 127.0.0.1:5432 - database connection failed" → updateConnectionUrl"Missing required environment variable: DATABASE_URL" → setEnvVar"getaddrinfo ENOTFOUND db" → addHostMapping"Container api was OOMKilled" → increaseMemory"504 Gateway Timeout from backend" → increaseTimeout"nginx container is not responding" → restartService```## Limitations- Optimized for the 7 specific infrastructure tools listed above- Requires exact tool definitions for best accuracy- May not generalize well to error patterns not seen in training## LicenseThis model inherits the [Gemma license](https://ai.google.dev/gemma/terms) from the base model.
README.md+185-125