@synsci/cli-darwin-x64 1.1.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/skills/accelerate/SKILL.md +332 -0
- package/bin/skills/accelerate/references/custom-plugins.md +453 -0
- package/bin/skills/accelerate/references/megatron-integration.md +489 -0
- package/bin/skills/accelerate/references/performance.md +525 -0
- package/bin/skills/audiocraft/SKILL.md +564 -0
- package/bin/skills/audiocraft/references/advanced-usage.md +666 -0
- package/bin/skills/audiocraft/references/troubleshooting.md +504 -0
- package/bin/skills/autogpt/SKILL.md +403 -0
- package/bin/skills/autogpt/references/advanced-usage.md +535 -0
- package/bin/skills/autogpt/references/troubleshooting.md +420 -0
- package/bin/skills/awq/SKILL.md +310 -0
- package/bin/skills/awq/references/advanced-usage.md +324 -0
- package/bin/skills/awq/references/troubleshooting.md +344 -0
- package/bin/skills/axolotl/SKILL.md +158 -0
- package/bin/skills/axolotl/references/api.md +5548 -0
- package/bin/skills/axolotl/references/dataset-formats.md +1029 -0
- package/bin/skills/axolotl/references/index.md +15 -0
- package/bin/skills/axolotl/references/other.md +3563 -0
- package/bin/skills/bigcode-evaluation-harness/SKILL.md +405 -0
- package/bin/skills/bigcode-evaluation-harness/references/benchmarks.md +393 -0
- package/bin/skills/bigcode-evaluation-harness/references/custom-tasks.md +424 -0
- package/bin/skills/bigcode-evaluation-harness/references/issues.md +394 -0
- package/bin/skills/bitsandbytes/SKILL.md +411 -0
- package/bin/skills/bitsandbytes/references/memory-optimization.md +521 -0
- package/bin/skills/bitsandbytes/references/qlora-training.md +521 -0
- package/bin/skills/bitsandbytes/references/quantization-formats.md +447 -0
- package/bin/skills/blip-2/SKILL.md +564 -0
- package/bin/skills/blip-2/references/advanced-usage.md +680 -0
- package/bin/skills/blip-2/references/troubleshooting.md +526 -0
- package/bin/skills/chroma/SKILL.md +406 -0
- package/bin/skills/chroma/references/integration.md +38 -0
- package/bin/skills/clip/SKILL.md +253 -0
- package/bin/skills/clip/references/applications.md +207 -0
- package/bin/skills/constitutional-ai/SKILL.md +290 -0
- package/bin/skills/crewai/SKILL.md +498 -0
- package/bin/skills/crewai/references/flows.md +438 -0
- package/bin/skills/crewai/references/tools.md +429 -0
- package/bin/skills/crewai/references/troubleshooting.md +480 -0
- package/bin/skills/deepspeed/SKILL.md +141 -0
- package/bin/skills/deepspeed/references/08.md +17 -0
- package/bin/skills/deepspeed/references/09.md +173 -0
- package/bin/skills/deepspeed/references/2020.md +378 -0
- package/bin/skills/deepspeed/references/2023.md +279 -0
- package/bin/skills/deepspeed/references/assets.md +179 -0
- package/bin/skills/deepspeed/references/index.md +35 -0
- package/bin/skills/deepspeed/references/mii.md +118 -0
- package/bin/skills/deepspeed/references/other.md +1191 -0
- package/bin/skills/deepspeed/references/tutorials.md +6554 -0
- package/bin/skills/dspy/SKILL.md +590 -0
- package/bin/skills/dspy/references/examples.md +663 -0
- package/bin/skills/dspy/references/modules.md +475 -0
- package/bin/skills/dspy/references/optimizers.md +566 -0
- package/bin/skills/faiss/SKILL.md +221 -0
- package/bin/skills/faiss/references/index_types.md +280 -0
- package/bin/skills/flash-attention/SKILL.md +367 -0
- package/bin/skills/flash-attention/references/benchmarks.md +215 -0
- package/bin/skills/flash-attention/references/transformers-integration.md +293 -0
- package/bin/skills/gguf/SKILL.md +427 -0
- package/bin/skills/gguf/references/advanced-usage.md +504 -0
- package/bin/skills/gguf/references/troubleshooting.md +442 -0
- package/bin/skills/gptq/SKILL.md +450 -0
- package/bin/skills/gptq/references/calibration.md +337 -0
- package/bin/skills/gptq/references/integration.md +129 -0
- package/bin/skills/gptq/references/troubleshooting.md +95 -0
- package/bin/skills/grpo-rl-training/README.md +97 -0
- package/bin/skills/grpo-rl-training/SKILL.md +572 -0
- package/bin/skills/grpo-rl-training/examples/reward_functions_library.py +393 -0
- package/bin/skills/grpo-rl-training/templates/basic_grpo_training.py +228 -0
- package/bin/skills/guidance/SKILL.md +572 -0
- package/bin/skills/guidance/references/backends.md +554 -0
- package/bin/skills/guidance/references/constraints.md +674 -0
- package/bin/skills/guidance/references/examples.md +767 -0
- package/bin/skills/hqq/SKILL.md +445 -0
- package/bin/skills/hqq/references/advanced-usage.md +528 -0
- package/bin/skills/hqq/references/troubleshooting.md +503 -0
- package/bin/skills/hugging-face-cli/SKILL.md +191 -0
- package/bin/skills/hugging-face-cli/references/commands.md +954 -0
- package/bin/skills/hugging-face-cli/references/examples.md +374 -0
- package/bin/skills/hugging-face-datasets/SKILL.md +547 -0
- package/bin/skills/hugging-face-datasets/examples/diverse_training_examples.json +239 -0
- package/bin/skills/hugging-face-datasets/examples/system_prompt_template.txt +196 -0
- package/bin/skills/hugging-face-datasets/examples/training_examples.json +176 -0
- package/bin/skills/hugging-face-datasets/scripts/dataset_manager.py +522 -0
- package/bin/skills/hugging-face-datasets/scripts/sql_manager.py +844 -0
- package/bin/skills/hugging-face-datasets/templates/chat.json +55 -0
- package/bin/skills/hugging-face-datasets/templates/classification.json +62 -0
- package/bin/skills/hugging-face-datasets/templates/completion.json +51 -0
- package/bin/skills/hugging-face-datasets/templates/custom.json +75 -0
- package/bin/skills/hugging-face-datasets/templates/qa.json +54 -0
- package/bin/skills/hugging-face-datasets/templates/tabular.json +81 -0
- package/bin/skills/hugging-face-evaluation/SKILL.md +656 -0
- package/bin/skills/hugging-face-evaluation/examples/USAGE_EXAMPLES.md +382 -0
- package/bin/skills/hugging-face-evaluation/examples/artificial_analysis_to_hub.py +141 -0
- package/bin/skills/hugging-face-evaluation/examples/example_readme_tables.md +135 -0
- package/bin/skills/hugging-face-evaluation/examples/metric_mapping.json +50 -0
- package/bin/skills/hugging-face-evaluation/requirements.txt +20 -0
- package/bin/skills/hugging-face-evaluation/scripts/evaluation_manager.py +1374 -0
- package/bin/skills/hugging-face-evaluation/scripts/inspect_eval_uv.py +104 -0
- package/bin/skills/hugging-face-evaluation/scripts/inspect_vllm_uv.py +317 -0
- package/bin/skills/hugging-face-evaluation/scripts/lighteval_vllm_uv.py +303 -0
- package/bin/skills/hugging-face-evaluation/scripts/run_eval_job.py +98 -0
- package/bin/skills/hugging-face-evaluation/scripts/run_vllm_eval_job.py +331 -0
- package/bin/skills/hugging-face-evaluation/scripts/test_extraction.py +206 -0
- package/bin/skills/hugging-face-jobs/SKILL.md +1041 -0
- package/bin/skills/hugging-face-jobs/index.html +216 -0
- package/bin/skills/hugging-face-jobs/references/hardware_guide.md +336 -0
- package/bin/skills/hugging-face-jobs/references/hub_saving.md +352 -0
- package/bin/skills/hugging-face-jobs/references/token_usage.md +546 -0
- package/bin/skills/hugging-face-jobs/references/troubleshooting.md +475 -0
- package/bin/skills/hugging-face-jobs/scripts/cot-self-instruct.py +718 -0
- package/bin/skills/hugging-face-jobs/scripts/finepdfs-stats.py +546 -0
- package/bin/skills/hugging-face-jobs/scripts/generate-responses.py +587 -0
- package/bin/skills/hugging-face-model-trainer/SKILL.md +711 -0
- package/bin/skills/hugging-face-model-trainer/references/gguf_conversion.md +296 -0
- package/bin/skills/hugging-face-model-trainer/references/hardware_guide.md +283 -0
- package/bin/skills/hugging-face-model-trainer/references/hub_saving.md +364 -0
- package/bin/skills/hugging-face-model-trainer/references/reliability_principles.md +371 -0
- package/bin/skills/hugging-face-model-trainer/references/trackio_guide.md +189 -0
- package/bin/skills/hugging-face-model-trainer/references/training_methods.md +150 -0
- package/bin/skills/hugging-face-model-trainer/references/training_patterns.md +203 -0
- package/bin/skills/hugging-face-model-trainer/references/troubleshooting.md +282 -0
- package/bin/skills/hugging-face-model-trainer/scripts/convert_to_gguf.py +424 -0
- package/bin/skills/hugging-face-model-trainer/scripts/dataset_inspector.py +417 -0
- package/bin/skills/hugging-face-model-trainer/scripts/estimate_cost.py +150 -0
- package/bin/skills/hugging-face-model-trainer/scripts/train_dpo_example.py +106 -0
- package/bin/skills/hugging-face-model-trainer/scripts/train_grpo_example.py +89 -0
- package/bin/skills/hugging-face-model-trainer/scripts/train_sft_example.py +122 -0
- package/bin/skills/hugging-face-paper-publisher/SKILL.md +627 -0
- package/bin/skills/hugging-face-paper-publisher/examples/example_usage.md +327 -0
- package/bin/skills/hugging-face-paper-publisher/references/quick_reference.md +216 -0
- package/bin/skills/hugging-face-paper-publisher/scripts/paper_manager.py +508 -0
- package/bin/skills/hugging-face-paper-publisher/templates/arxiv.md +299 -0
- package/bin/skills/hugging-face-paper-publisher/templates/ml-report.md +358 -0
- package/bin/skills/hugging-face-paper-publisher/templates/modern.md +319 -0
- package/bin/skills/hugging-face-paper-publisher/templates/standard.md +201 -0
- package/bin/skills/hugging-face-tool-builder/SKILL.md +115 -0
- package/bin/skills/hugging-face-tool-builder/references/baseline_hf_api.py +57 -0
- package/bin/skills/hugging-face-tool-builder/references/baseline_hf_api.sh +40 -0
- package/bin/skills/hugging-face-tool-builder/references/baseline_hf_api.tsx +57 -0
- package/bin/skills/hugging-face-tool-builder/references/find_models_by_paper.sh +230 -0
- package/bin/skills/hugging-face-tool-builder/references/hf_enrich_models.sh +96 -0
- package/bin/skills/hugging-face-tool-builder/references/hf_model_card_frontmatter.sh +188 -0
- package/bin/skills/hugging-face-tool-builder/references/hf_model_papers_auth.sh +171 -0
- package/bin/skills/hugging-face-trackio/SKILL.md +65 -0
- package/bin/skills/hugging-face-trackio/references/logging_metrics.md +206 -0
- package/bin/skills/hugging-face-trackio/references/retrieving_metrics.md +223 -0
- package/bin/skills/huggingface-tokenizers/SKILL.md +516 -0
- package/bin/skills/huggingface-tokenizers/references/algorithms.md +653 -0
- package/bin/skills/huggingface-tokenizers/references/integration.md +637 -0
- package/bin/skills/huggingface-tokenizers/references/pipeline.md +723 -0
- package/bin/skills/huggingface-tokenizers/references/training.md +565 -0
- package/bin/skills/instructor/SKILL.md +740 -0
- package/bin/skills/instructor/references/examples.md +107 -0
- package/bin/skills/instructor/references/providers.md +70 -0
- package/bin/skills/instructor/references/validation.md +606 -0
- package/bin/skills/knowledge-distillation/SKILL.md +458 -0
- package/bin/skills/knowledge-distillation/references/minillm.md +334 -0
- package/bin/skills/lambda-labs/SKILL.md +545 -0
- package/bin/skills/lambda-labs/references/advanced-usage.md +611 -0
- package/bin/skills/lambda-labs/references/troubleshooting.md +530 -0
- package/bin/skills/langchain/SKILL.md +480 -0
- package/bin/skills/langchain/references/agents.md +499 -0
- package/bin/skills/langchain/references/integration.md +562 -0
- package/bin/skills/langchain/references/rag.md +600 -0
- package/bin/skills/langsmith/SKILL.md +422 -0
- package/bin/skills/langsmith/references/advanced-usage.md +548 -0
- package/bin/skills/langsmith/references/troubleshooting.md +537 -0
- package/bin/skills/litgpt/SKILL.md +469 -0
- package/bin/skills/litgpt/references/custom-models.md +568 -0
- package/bin/skills/litgpt/references/distributed-training.md +451 -0
- package/bin/skills/litgpt/references/supported-models.md +336 -0
- package/bin/skills/litgpt/references/training-recipes.md +619 -0
- package/bin/skills/llama-cpp/SKILL.md +258 -0
- package/bin/skills/llama-cpp/references/optimization.md +89 -0
- package/bin/skills/llama-cpp/references/quantization.md +213 -0
- package/bin/skills/llama-cpp/references/server.md +125 -0
- package/bin/skills/llama-factory/SKILL.md +80 -0
- package/bin/skills/llama-factory/references/_images.md +23 -0
- package/bin/skills/llama-factory/references/advanced.md +1055 -0
- package/bin/skills/llama-factory/references/getting_started.md +349 -0
- package/bin/skills/llama-factory/references/index.md +19 -0
- package/bin/skills/llama-factory/references/other.md +31 -0
- package/bin/skills/llamaguard/SKILL.md +337 -0
- package/bin/skills/llamaindex/SKILL.md +569 -0
- package/bin/skills/llamaindex/references/agents.md +83 -0
- package/bin/skills/llamaindex/references/data_connectors.md +108 -0
- package/bin/skills/llamaindex/references/query_engines.md +406 -0
- package/bin/skills/llava/SKILL.md +304 -0
- package/bin/skills/llava/references/training.md +197 -0
- package/bin/skills/lm-evaluation-harness/SKILL.md +490 -0
- package/bin/skills/lm-evaluation-harness/references/api-evaluation.md +490 -0
- package/bin/skills/lm-evaluation-harness/references/benchmark-guide.md +488 -0
- package/bin/skills/lm-evaluation-harness/references/custom-tasks.md +602 -0
- package/bin/skills/lm-evaluation-harness/references/distributed-eval.md +519 -0
- package/bin/skills/long-context/SKILL.md +536 -0
- package/bin/skills/long-context/references/extension_methods.md +468 -0
- package/bin/skills/long-context/references/fine_tuning.md +611 -0
- package/bin/skills/long-context/references/rope.md +402 -0
- package/bin/skills/mamba/SKILL.md +260 -0
- package/bin/skills/mamba/references/architecture-details.md +206 -0
- package/bin/skills/mamba/references/benchmarks.md +255 -0
- package/bin/skills/mamba/references/training-guide.md +388 -0
- package/bin/skills/megatron-core/SKILL.md +366 -0
- package/bin/skills/megatron-core/references/benchmarks.md +249 -0
- package/bin/skills/megatron-core/references/parallelism-guide.md +404 -0
- package/bin/skills/megatron-core/references/production-examples.md +473 -0
- package/bin/skills/megatron-core/references/training-recipes.md +547 -0
- package/bin/skills/miles/SKILL.md +315 -0
- package/bin/skills/miles/references/api-reference.md +141 -0
- package/bin/skills/miles/references/troubleshooting.md +352 -0
- package/bin/skills/mlflow/SKILL.md +704 -0
- package/bin/skills/mlflow/references/deployment.md +744 -0
- package/bin/skills/mlflow/references/model-registry.md +770 -0
- package/bin/skills/mlflow/references/tracking.md +680 -0
- package/bin/skills/modal/SKILL.md +341 -0
- package/bin/skills/modal/references/advanced-usage.md +503 -0
- package/bin/skills/modal/references/troubleshooting.md +494 -0
- package/bin/skills/model-merging/SKILL.md +539 -0
- package/bin/skills/model-merging/references/evaluation.md +462 -0
- package/bin/skills/model-merging/references/examples.md +428 -0
- package/bin/skills/model-merging/references/methods.md +352 -0
- package/bin/skills/model-pruning/SKILL.md +495 -0
- package/bin/skills/model-pruning/references/wanda.md +347 -0
- package/bin/skills/moe-training/SKILL.md +526 -0
- package/bin/skills/moe-training/references/architectures.md +432 -0
- package/bin/skills/moe-training/references/inference.md +348 -0
- package/bin/skills/moe-training/references/training.md +425 -0
- package/bin/skills/nanogpt/SKILL.md +290 -0
- package/bin/skills/nanogpt/references/architecture.md +382 -0
- package/bin/skills/nanogpt/references/data.md +476 -0
- package/bin/skills/nanogpt/references/training.md +564 -0
- package/bin/skills/nemo-curator/SKILL.md +383 -0
- package/bin/skills/nemo-curator/references/deduplication.md +87 -0
- package/bin/skills/nemo-curator/references/filtering.md +102 -0
- package/bin/skills/nemo-evaluator/SKILL.md +494 -0
- package/bin/skills/nemo-evaluator/references/adapter-system.md +340 -0
- package/bin/skills/nemo-evaluator/references/configuration.md +447 -0
- package/bin/skills/nemo-evaluator/references/custom-benchmarks.md +315 -0
- package/bin/skills/nemo-evaluator/references/execution-backends.md +361 -0
- package/bin/skills/nemo-guardrails/SKILL.md +297 -0
- package/bin/skills/nnsight/SKILL.md +436 -0
- package/bin/skills/nnsight/references/README.md +78 -0
- package/bin/skills/nnsight/references/api.md +344 -0
- package/bin/skills/nnsight/references/tutorials.md +300 -0
- package/bin/skills/openrlhf/SKILL.md +249 -0
- package/bin/skills/openrlhf/references/algorithm-comparison.md +404 -0
- package/bin/skills/openrlhf/references/custom-rewards.md +530 -0
- package/bin/skills/openrlhf/references/hybrid-engine.md +287 -0
- package/bin/skills/openrlhf/references/multi-node-training.md +454 -0
- package/bin/skills/outlines/SKILL.md +652 -0
- package/bin/skills/outlines/references/backends.md +615 -0
- package/bin/skills/outlines/references/examples.md +773 -0
- package/bin/skills/outlines/references/json_generation.md +652 -0
- package/bin/skills/peft/SKILL.md +431 -0
- package/bin/skills/peft/references/advanced-usage.md +514 -0
- package/bin/skills/peft/references/troubleshooting.md +480 -0
- package/bin/skills/phoenix/SKILL.md +475 -0
- package/bin/skills/phoenix/references/advanced-usage.md +619 -0
- package/bin/skills/phoenix/references/troubleshooting.md +538 -0
- package/bin/skills/pinecone/SKILL.md +358 -0
- package/bin/skills/pinecone/references/deployment.md +181 -0
- package/bin/skills/pytorch-fsdp/SKILL.md +126 -0
- package/bin/skills/pytorch-fsdp/references/index.md +7 -0
- package/bin/skills/pytorch-fsdp/references/other.md +4249 -0
- package/bin/skills/pytorch-lightning/SKILL.md +346 -0
- package/bin/skills/pytorch-lightning/references/callbacks.md +436 -0
- package/bin/skills/pytorch-lightning/references/distributed.md +490 -0
- package/bin/skills/pytorch-lightning/references/hyperparameter-tuning.md +556 -0
- package/bin/skills/pyvene/SKILL.md +473 -0
- package/bin/skills/pyvene/references/README.md +73 -0
- package/bin/skills/pyvene/references/api.md +383 -0
- package/bin/skills/pyvene/references/tutorials.md +376 -0
- package/bin/skills/qdrant/SKILL.md +493 -0
- package/bin/skills/qdrant/references/advanced-usage.md +648 -0
- package/bin/skills/qdrant/references/troubleshooting.md +631 -0
- package/bin/skills/ray-data/SKILL.md +326 -0
- package/bin/skills/ray-data/references/integration.md +82 -0
- package/bin/skills/ray-data/references/transformations.md +83 -0
- package/bin/skills/ray-train/SKILL.md +406 -0
- package/bin/skills/ray-train/references/multi-node.md +628 -0
- package/bin/skills/rwkv/SKILL.md +260 -0
- package/bin/skills/rwkv/references/architecture-details.md +344 -0
- package/bin/skills/rwkv/references/rwkv7.md +386 -0
- package/bin/skills/rwkv/references/state-management.md +369 -0
- package/bin/skills/saelens/SKILL.md +386 -0
- package/bin/skills/saelens/references/README.md +70 -0
- package/bin/skills/saelens/references/api.md +333 -0
- package/bin/skills/saelens/references/tutorials.md +318 -0
- package/bin/skills/segment-anything/SKILL.md +500 -0
- package/bin/skills/segment-anything/references/advanced-usage.md +589 -0
- package/bin/skills/segment-anything/references/troubleshooting.md +484 -0
- package/bin/skills/sentence-transformers/SKILL.md +255 -0
- package/bin/skills/sentence-transformers/references/models.md +123 -0
- package/bin/skills/sentencepiece/SKILL.md +235 -0
- package/bin/skills/sentencepiece/references/algorithms.md +200 -0
- package/bin/skills/sentencepiece/references/training.md +304 -0
- package/bin/skills/sglang/SKILL.md +442 -0
- package/bin/skills/sglang/references/deployment.md +490 -0
- package/bin/skills/sglang/references/radix-attention.md +413 -0
- package/bin/skills/sglang/references/structured-generation.md +541 -0
- package/bin/skills/simpo/SKILL.md +219 -0
- package/bin/skills/simpo/references/datasets.md +478 -0
- package/bin/skills/simpo/references/hyperparameters.md +452 -0
- package/bin/skills/simpo/references/loss-functions.md +350 -0
- package/bin/skills/skypilot/SKILL.md +509 -0
- package/bin/skills/skypilot/references/advanced-usage.md +491 -0
- package/bin/skills/skypilot/references/troubleshooting.md +570 -0
- package/bin/skills/slime/SKILL.md +464 -0
- package/bin/skills/slime/references/api-reference.md +392 -0
- package/bin/skills/slime/references/troubleshooting.md +386 -0
- package/bin/skills/speculative-decoding/SKILL.md +467 -0
- package/bin/skills/speculative-decoding/references/lookahead.md +309 -0
- package/bin/skills/speculative-decoding/references/medusa.md +350 -0
- package/bin/skills/stable-diffusion/SKILL.md +519 -0
- package/bin/skills/stable-diffusion/references/advanced-usage.md +716 -0
- package/bin/skills/stable-diffusion/references/troubleshooting.md +555 -0
- package/bin/skills/tensorboard/SKILL.md +629 -0
- package/bin/skills/tensorboard/references/integrations.md +638 -0
- package/bin/skills/tensorboard/references/profiling.md +545 -0
- package/bin/skills/tensorboard/references/visualization.md +620 -0
- package/bin/skills/tensorrt-llm/SKILL.md +187 -0
- package/bin/skills/tensorrt-llm/references/multi-gpu.md +298 -0
- package/bin/skills/tensorrt-llm/references/optimization.md +242 -0
- package/bin/skills/tensorrt-llm/references/serving.md +470 -0
- package/bin/skills/tinker/SKILL.md +362 -0
- package/bin/skills/tinker/references/api-reference.md +168 -0
- package/bin/skills/tinker/references/getting-started.md +157 -0
- package/bin/skills/tinker/references/loss-functions.md +163 -0
- package/bin/skills/tinker/references/models-and-lora.md +139 -0
- package/bin/skills/tinker/references/recipes.md +280 -0
- package/bin/skills/tinker/references/reinforcement-learning.md +212 -0
- package/bin/skills/tinker/references/rendering.md +243 -0
- package/bin/skills/tinker/references/supervised-learning.md +232 -0
- package/bin/skills/tinker-training-cost/SKILL.md +187 -0
- package/bin/skills/tinker-training-cost/scripts/calculate_cost.py +123 -0
- package/bin/skills/torchforge/SKILL.md +433 -0
- package/bin/skills/torchforge/references/api-reference.md +327 -0
- package/bin/skills/torchforge/references/troubleshooting.md +409 -0
- package/bin/skills/torchtitan/SKILL.md +358 -0
- package/bin/skills/torchtitan/references/checkpoint.md +181 -0
- package/bin/skills/torchtitan/references/custom-models.md +258 -0
- package/bin/skills/torchtitan/references/float8.md +133 -0
- package/bin/skills/torchtitan/references/fsdp.md +126 -0
- package/bin/skills/transformer-lens/SKILL.md +346 -0
- package/bin/skills/transformer-lens/references/README.md +54 -0
- package/bin/skills/transformer-lens/references/api.md +362 -0
- package/bin/skills/transformer-lens/references/tutorials.md +339 -0
- package/bin/skills/trl-fine-tuning/SKILL.md +455 -0
- package/bin/skills/trl-fine-tuning/references/dpo-variants.md +227 -0
- package/bin/skills/trl-fine-tuning/references/online-rl.md +82 -0
- package/bin/skills/trl-fine-tuning/references/reward-modeling.md +122 -0
- package/bin/skills/trl-fine-tuning/references/sft-training.md +168 -0
- package/bin/skills/unsloth/SKILL.md +80 -0
- package/bin/skills/unsloth/references/index.md +7 -0
- package/bin/skills/unsloth/references/llms-full.md +16799 -0
- package/bin/skills/unsloth/references/llms-txt.md +12044 -0
- package/bin/skills/unsloth/references/llms.md +82 -0
- package/bin/skills/verl/SKILL.md +391 -0
- package/bin/skills/verl/references/api-reference.md +301 -0
- package/bin/skills/verl/references/troubleshooting.md +391 -0
- package/bin/skills/vllm/SKILL.md +364 -0
- package/bin/skills/vllm/references/optimization.md +226 -0
- package/bin/skills/vllm/references/quantization.md +284 -0
- package/bin/skills/vllm/references/server-deployment.md +255 -0
- package/bin/skills/vllm/references/troubleshooting.md +447 -0
- package/bin/skills/weights-and-biases/SKILL.md +590 -0
- package/bin/skills/weights-and-biases/references/artifacts.md +584 -0
- package/bin/skills/weights-and-biases/references/integrations.md +700 -0
- package/bin/skills/weights-and-biases/references/sweeps.md +847 -0
- package/bin/skills/whisper/SKILL.md +317 -0
- package/bin/skills/whisper/references/languages.md +189 -0
- package/bin/synsc +0 -0
- package/package.json +10 -0
|
@@ -0,0 +1,652 @@
|
|
|
1
|
+
# Comprehensive JSON Generation Guide
|
|
2
|
+
|
|
3
|
+
Complete guide to JSON generation with Outlines using Pydantic models and JSON schemas.
|
|
4
|
+
|
|
5
|
+
## Table of Contents
|
|
6
|
+
- Pydantic Models
|
|
7
|
+
- JSON Schema Support
|
|
8
|
+
- Advanced Patterns
|
|
9
|
+
- Nested Structures
|
|
10
|
+
- Complex Types
|
|
11
|
+
- Validation
|
|
12
|
+
- Performance Optimization
|
|
13
|
+
|
|
14
|
+
## Pydantic Models
|
|
15
|
+
|
|
16
|
+
### Basic Models
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from pydantic import BaseModel
|
|
20
|
+
import outlines
|
|
21
|
+
|
|
22
|
+
class User(BaseModel):
|
|
23
|
+
name: str
|
|
24
|
+
age: int
|
|
25
|
+
email: str
|
|
26
|
+
|
|
27
|
+
model = outlines.models.transformers("microsoft/Phi-3-mini-4k-instruct")
|
|
28
|
+
generator = outlines.generate.json(model, User)
|
|
29
|
+
|
|
30
|
+
user = generator("Generate user: Alice, 25, alice@example.com")
|
|
31
|
+
print(user.name) # "Alice"
|
|
32
|
+
print(user.age) # 25
|
|
33
|
+
print(user.email) # "alice@example.com"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
###
|
|
37
|
+
|
|
38
|
+
Field Constraints
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from pydantic import BaseModel, Field
|
|
42
|
+
|
|
43
|
+
class Product(BaseModel):
|
|
44
|
+
name: str = Field(min_length=1, max_length=100)
|
|
45
|
+
price: float = Field(gt=0, description="Price in USD")
|
|
46
|
+
discount: float = Field(ge=0, le=100, description="Discount percentage")
|
|
47
|
+
quantity: int = Field(ge=0, description="Available quantity")
|
|
48
|
+
sku: str = Field(pattern=r"^[A-Z]{3}-\d{6}$")
|
|
49
|
+
|
|
50
|
+
model = outlines.models.transformers("microsoft/Phi-3-mini-4k-instruct")
|
|
51
|
+
generator = outlines.generate.json(model, Product)
|
|
52
|
+
|
|
53
|
+
product = generator("Generate product: iPhone 15, $999")
|
|
54
|
+
# All fields guaranteed to meet constraints
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Available Constraints:**
|
|
58
|
+
- `min_length`, `max_length`: String length
|
|
59
|
+
- `gt`, `ge`, `lt`, `le`: Numeric comparisons
|
|
60
|
+
- `multiple_of`: Number must be multiple of value
|
|
61
|
+
- `pattern`: Regex pattern for strings
|
|
62
|
+
- `min_items`, `max_items`: List length
|
|
63
|
+
|
|
64
|
+
### Optional Fields
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from typing import Optional
|
|
68
|
+
|
|
69
|
+
class Article(BaseModel):
|
|
70
|
+
title: str # Required
|
|
71
|
+
author: Optional[str] = None # Optional
|
|
72
|
+
published_date: Optional[str] = None # Optional
|
|
73
|
+
tags: list[str] = [] # Default empty list
|
|
74
|
+
view_count: int = 0 # Default value
|
|
75
|
+
|
|
76
|
+
generator = outlines.generate.json(model, Article)
|
|
77
|
+
|
|
78
|
+
# Can generate even if optional fields missing
|
|
79
|
+
article = generator("Title: Introduction to AI")
|
|
80
|
+
print(article.author) # None (not provided)
|
|
81
|
+
print(article.tags) # [] (default)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Default Values
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
class Config(BaseModel):
|
|
88
|
+
debug: bool = False
|
|
89
|
+
max_retries: int = 3
|
|
90
|
+
timeout: float = 30.0
|
|
91
|
+
log_level: str = "INFO"
|
|
92
|
+
|
|
93
|
+
# Generator uses defaults when not specified
|
|
94
|
+
generator = outlines.generate.json(model, Config)
|
|
95
|
+
config = generator("Generate config with debug enabled")
|
|
96
|
+
print(config.debug) # True (from prompt)
|
|
97
|
+
print(config.timeout) # 30.0 (default)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Enums and Literals
|
|
101
|
+
|
|
102
|
+
### Enum Fields
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
from enum import Enum
|
|
106
|
+
|
|
107
|
+
class Status(str, Enum):
|
|
108
|
+
PENDING = "pending"
|
|
109
|
+
APPROVED = "approved"
|
|
110
|
+
REJECTED = "rejected"
|
|
111
|
+
CANCELLED = "cancelled"
|
|
112
|
+
|
|
113
|
+
class Application(BaseModel):
|
|
114
|
+
applicant_name: str
|
|
115
|
+
status: Status # Must be one of enum values
|
|
116
|
+
submitted_date: str
|
|
117
|
+
|
|
118
|
+
generator = outlines.generate.json(model, Application)
|
|
119
|
+
app = generator("Generate application for John Doe")
|
|
120
|
+
|
|
121
|
+
print(app.status) # Status.PENDING (or one of the enum values)
|
|
122
|
+
print(type(app.status)) # <enum 'Status'>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Literal Types
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from typing import Literal
|
|
129
|
+
|
|
130
|
+
class Task(BaseModel):
|
|
131
|
+
title: str
|
|
132
|
+
priority: Literal["low", "medium", "high", "critical"]
|
|
133
|
+
status: Literal["todo", "in_progress", "done"]
|
|
134
|
+
assigned_to: str
|
|
135
|
+
|
|
136
|
+
generator = outlines.generate.json(model, Task)
|
|
137
|
+
task = generator("Create high priority task: Fix bug")
|
|
138
|
+
|
|
139
|
+
print(task.priority) # One of: "low", "medium", "high", "critical"
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Multiple Choice Fields
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
class Survey(BaseModel):
|
|
146
|
+
question: str
|
|
147
|
+
answer: Literal["strongly_disagree", "disagree", "neutral", "agree", "strongly_agree"]
|
|
148
|
+
confidence: Literal["low", "medium", "high"]
|
|
149
|
+
|
|
150
|
+
generator = outlines.generate.json(model, Survey)
|
|
151
|
+
survey = generator("Rate: 'I enjoy using this product'")
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Nested Structures
|
|
155
|
+
|
|
156
|
+
### Nested Models
|
|
157
|
+
|
|
158
|
+
```python
|
|
159
|
+
class Address(BaseModel):
|
|
160
|
+
street: str
|
|
161
|
+
city: str
|
|
162
|
+
state: str
|
|
163
|
+
zip_code: str
|
|
164
|
+
country: str = "USA"
|
|
165
|
+
|
|
166
|
+
class Person(BaseModel):
|
|
167
|
+
name: str
|
|
168
|
+
age: int
|
|
169
|
+
email: str
|
|
170
|
+
address: Address # Nested model
|
|
171
|
+
|
|
172
|
+
model = outlines.models.transformers("microsoft/Phi-3-mini-4k-instruct")
|
|
173
|
+
generator = outlines.generate.json(model, Person)
|
|
174
|
+
|
|
175
|
+
prompt = """
|
|
176
|
+
Extract person:
|
|
177
|
+
Name: Alice Johnson
|
|
178
|
+
Age: 28
|
|
179
|
+
Email: alice@example.com
|
|
180
|
+
Address: 123 Main St, Boston, MA, 02101
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
person = generator(prompt)
|
|
184
|
+
print(person.name) # "Alice Johnson"
|
|
185
|
+
print(person.address.city) # "Boston"
|
|
186
|
+
print(person.address.state) # "MA"
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Deep Nesting
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
class Coordinates(BaseModel):
|
|
193
|
+
latitude: float
|
|
194
|
+
longitude: float
|
|
195
|
+
|
|
196
|
+
class Location(BaseModel):
|
|
197
|
+
name: str
|
|
198
|
+
coordinates: Coordinates
|
|
199
|
+
|
|
200
|
+
class Event(BaseModel):
|
|
201
|
+
title: str
|
|
202
|
+
date: str
|
|
203
|
+
location: Location
|
|
204
|
+
|
|
205
|
+
generator = outlines.generate.json(model, Event)
|
|
206
|
+
event = generator("Generate event: Tech Conference in San Francisco")
|
|
207
|
+
|
|
208
|
+
print(event.title) # "Tech Conference"
|
|
209
|
+
print(event.location.name) # "San Francisco"
|
|
210
|
+
print(event.location.coordinates.latitude) # 37.7749
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### Lists of Nested Models
|
|
214
|
+
|
|
215
|
+
```python
|
|
216
|
+
class Item(BaseModel):
|
|
217
|
+
name: str
|
|
218
|
+
quantity: int
|
|
219
|
+
price: float
|
|
220
|
+
|
|
221
|
+
class Order(BaseModel):
|
|
222
|
+
order_id: str
|
|
223
|
+
customer: str
|
|
224
|
+
items: list[Item] # List of nested models
|
|
225
|
+
total: float
|
|
226
|
+
|
|
227
|
+
generator = outlines.generate.json(model, Order)
|
|
228
|
+
|
|
229
|
+
prompt = """
|
|
230
|
+
Generate order for John:
|
|
231
|
+
- 2x Widget ($10 each)
|
|
232
|
+
- 3x Gadget ($15 each)
|
|
233
|
+
Order ID: ORD-001
|
|
234
|
+
"""
|
|
235
|
+
|
|
236
|
+
order = generator(prompt)
|
|
237
|
+
print(f"Order ID: {order.order_id}")
|
|
238
|
+
for item in order.items:
|
|
239
|
+
print(f"- {item.quantity}x {item.name} @ ${item.price}")
|
|
240
|
+
print(f"Total: ${order.total}")
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
## Complex Types
|
|
244
|
+
|
|
245
|
+
### Union Types
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
from typing import Union
|
|
249
|
+
|
|
250
|
+
class TextContent(BaseModel):
|
|
251
|
+
type: Literal["text"]
|
|
252
|
+
content: str
|
|
253
|
+
|
|
254
|
+
class ImageContent(BaseModel):
|
|
255
|
+
type: Literal["image"]
|
|
256
|
+
url: str
|
|
257
|
+
caption: str
|
|
258
|
+
|
|
259
|
+
class Post(BaseModel):
|
|
260
|
+
title: str
|
|
261
|
+
content: Union[TextContent, ImageContent] # Either type
|
|
262
|
+
|
|
263
|
+
generator = outlines.generate.json(model, Post)
|
|
264
|
+
|
|
265
|
+
# Can generate either text or image content
|
|
266
|
+
post = generator("Generate blog post with image")
|
|
267
|
+
if post.content.type == "text":
|
|
268
|
+
print(post.content.content)
|
|
269
|
+
elif post.content.type == "image":
|
|
270
|
+
print(post.content.url)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Lists and Arrays
|
|
274
|
+
|
|
275
|
+
```python
|
|
276
|
+
class Article(BaseModel):
|
|
277
|
+
title: str
|
|
278
|
+
authors: list[str] # List of strings
|
|
279
|
+
tags: list[str]
|
|
280
|
+
sections: list[dict[str, str]] # List of dicts
|
|
281
|
+
related_ids: list[int]
|
|
282
|
+
|
|
283
|
+
generator = outlines.generate.json(model, Article)
|
|
284
|
+
article = generator("Generate article about AI")
|
|
285
|
+
|
|
286
|
+
print(article.authors) # ["Alice", "Bob"]
|
|
287
|
+
print(article.tags) # ["AI", "Machine Learning", "Technology"]
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### Dictionaries
|
|
291
|
+
|
|
292
|
+
```python
|
|
293
|
+
class Metadata(BaseModel):
|
|
294
|
+
title: str
|
|
295
|
+
properties: dict[str, str] # String keys and values
|
|
296
|
+
counts: dict[str, int] # String keys, int values
|
|
297
|
+
settings: dict[str, Union[str, int, bool]] # Mixed value types
|
|
298
|
+
|
|
299
|
+
generator = outlines.generate.json(model, Metadata)
|
|
300
|
+
meta = generator("Generate metadata")
|
|
301
|
+
|
|
302
|
+
print(meta.properties) # {"author": "Alice", "version": "1.0"}
|
|
303
|
+
print(meta.counts) # {"views": 1000, "likes": 50}
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
### Any Type (Use Sparingly)
|
|
307
|
+
|
|
308
|
+
```python
|
|
309
|
+
from typing import Any
|
|
310
|
+
|
|
311
|
+
class FlexibleData(BaseModel):
|
|
312
|
+
name: str
|
|
313
|
+
structured_field: str
|
|
314
|
+
flexible_field: Any # Can be anything
|
|
315
|
+
|
|
316
|
+
# Note: Any reduces type safety, use only when necessary
|
|
317
|
+
generator = outlines.generate.json(model, FlexibleData)
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## JSON Schema Support
|
|
321
|
+
|
|
322
|
+
### Direct Schema Usage
|
|
323
|
+
|
|
324
|
+
```python
|
|
325
|
+
import outlines
|
|
326
|
+
|
|
327
|
+
model = outlines.models.transformers("microsoft/Phi-3-mini-4k-instruct")
|
|
328
|
+
|
|
329
|
+
# Define JSON schema
|
|
330
|
+
schema = {
|
|
331
|
+
"type": "object",
|
|
332
|
+
"properties": {
|
|
333
|
+
"name": {"type": "string"},
|
|
334
|
+
"age": {"type": "integer", "minimum": 0, "maximum": 120},
|
|
335
|
+
"email": {"type": "string", "format": "email"}
|
|
336
|
+
},
|
|
337
|
+
"required": ["name", "age", "email"]
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
# Generate from schema
|
|
341
|
+
generator = outlines.generate.json(model, schema)
|
|
342
|
+
result = generator("Generate person: Alice, 25, alice@example.com")
|
|
343
|
+
|
|
344
|
+
print(result) # Valid JSON matching schema
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### Schema from Pydantic
|
|
348
|
+
|
|
349
|
+
```python
|
|
350
|
+
class User(BaseModel):
|
|
351
|
+
name: str
|
|
352
|
+
age: int
|
|
353
|
+
email: str
|
|
354
|
+
|
|
355
|
+
# Get JSON schema from Pydantic model
|
|
356
|
+
schema = User.model_json_schema()
|
|
357
|
+
print(schema)
|
|
358
|
+
# {
|
|
359
|
+
# "type": "object",
|
|
360
|
+
# "properties": {
|
|
361
|
+
# "name": {"type": "string"},
|
|
362
|
+
# "age": {"type": "integer"},
|
|
363
|
+
# "email": {"type": "string"}
|
|
364
|
+
# },
|
|
365
|
+
# "required": ["name", "age", "email"]
|
|
366
|
+
# }
|
|
367
|
+
|
|
368
|
+
# Both approaches equivalent:
|
|
369
|
+
generator1 = outlines.generate.json(model, User)
|
|
370
|
+
generator2 = outlines.generate.json(model, schema)
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
## Advanced Patterns
|
|
374
|
+
|
|
375
|
+
### Conditional Fields
|
|
376
|
+
|
|
377
|
+
```python
|
|
378
|
+
class Order(BaseModel):
|
|
379
|
+
order_type: Literal["standard", "express"]
|
|
380
|
+
delivery_date: str
|
|
381
|
+
express_fee: Optional[float] = None # Only for express orders
|
|
382
|
+
|
|
383
|
+
generator = outlines.generate.json(model, Order)
|
|
384
|
+
|
|
385
|
+
# Express order
|
|
386
|
+
order1 = generator("Create express order for tomorrow")
|
|
387
|
+
print(order1.express_fee) # 25.0
|
|
388
|
+
|
|
389
|
+
# Standard order
|
|
390
|
+
order2 = generator("Create standard order")
|
|
391
|
+
print(order2.express_fee) # None
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### Recursive Models
|
|
395
|
+
|
|
396
|
+
```python
|
|
397
|
+
from typing import Optional, List
|
|
398
|
+
|
|
399
|
+
class TreeNode(BaseModel):
|
|
400
|
+
value: str
|
|
401
|
+
children: Optional[List['TreeNode']] = None
|
|
402
|
+
|
|
403
|
+
# Enable forward references
|
|
404
|
+
TreeNode.model_rebuild()
|
|
405
|
+
|
|
406
|
+
generator = outlines.generate.json(model, TreeNode)
|
|
407
|
+
tree = generator("Generate file tree with subdirectories")
|
|
408
|
+
|
|
409
|
+
print(tree.value) # "root"
|
|
410
|
+
print(tree.children[0].value) # "subdir1"
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
### Model with Validation
|
|
414
|
+
|
|
415
|
+
```python
|
|
416
|
+
from pydantic import field_validator
|
|
417
|
+
|
|
418
|
+
class DateRange(BaseModel):
|
|
419
|
+
start_date: str
|
|
420
|
+
end_date: str
|
|
421
|
+
|
|
422
|
+
@field_validator('end_date')
|
|
423
|
+
def end_after_start(cls, v, info):
|
|
424
|
+
"""Ensure end_date is after start_date."""
|
|
425
|
+
if 'start_date' in info.data:
|
|
426
|
+
from datetime import datetime
|
|
427
|
+
start = datetime.strptime(info.data['start_date'], '%Y-%m-%d')
|
|
428
|
+
end = datetime.strptime(v, '%Y-%m-%d')
|
|
429
|
+
if end < start:
|
|
430
|
+
raise ValueError('end_date must be after start_date')
|
|
431
|
+
return v
|
|
432
|
+
|
|
433
|
+
generator = outlines.generate.json(model, DateRange)
|
|
434
|
+
# Validation happens after generation
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
## Multiple Objects
|
|
438
|
+
|
|
439
|
+
### Generate List of Objects
|
|
440
|
+
|
|
441
|
+
```python
|
|
442
|
+
class Person(BaseModel):
|
|
443
|
+
name: str
|
|
444
|
+
age: int
|
|
445
|
+
|
|
446
|
+
class Team(BaseModel):
|
|
447
|
+
team_name: str
|
|
448
|
+
members: list[Person]
|
|
449
|
+
|
|
450
|
+
generator = outlines.generate.json(model, Team)
|
|
451
|
+
|
|
452
|
+
team = generator("Generate engineering team with 5 members")
|
|
453
|
+
print(f"Team: {team.team_name}")
|
|
454
|
+
for member in team.members:
|
|
455
|
+
print(f"- {member.name}, {member.age}")
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
### Batch Generation
|
|
459
|
+
|
|
460
|
+
```python
|
|
461
|
+
def generate_batch(prompts: list[str], schema: type[BaseModel]):
|
|
462
|
+
"""Generate structured outputs for multiple prompts."""
|
|
463
|
+
model = outlines.models.transformers("microsoft/Phi-3-mini-4k-instruct")
|
|
464
|
+
generator = outlines.generate.json(model, schema)
|
|
465
|
+
|
|
466
|
+
results = []
|
|
467
|
+
for prompt in prompts:
|
|
468
|
+
result = generator(prompt)
|
|
469
|
+
results.append(result)
|
|
470
|
+
|
|
471
|
+
return results
|
|
472
|
+
|
|
473
|
+
class Product(BaseModel):
|
|
474
|
+
name: str
|
|
475
|
+
price: float
|
|
476
|
+
|
|
477
|
+
prompts = [
|
|
478
|
+
"Product: iPhone 15, $999",
|
|
479
|
+
"Product: MacBook Pro, $2499",
|
|
480
|
+
"Product: AirPods, $179"
|
|
481
|
+
]
|
|
482
|
+
|
|
483
|
+
products = generate_batch(prompts, Product)
|
|
484
|
+
for product in products:
|
|
485
|
+
print(f"{product.name}: ${product.price}")
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
## Performance Optimization
|
|
489
|
+
|
|
490
|
+
### Caching Generators
|
|
491
|
+
|
|
492
|
+
```python
|
|
493
|
+
from functools import lru_cache
|
|
494
|
+
|
|
495
|
+
@lru_cache(maxsize=10)
|
|
496
|
+
def get_generator(model_name: str, schema_hash: int):
|
|
497
|
+
"""Cache generators for reuse."""
|
|
498
|
+
model = outlines.models.transformers(model_name)
|
|
499
|
+
return outlines.generate.json(model, schema)
|
|
500
|
+
|
|
501
|
+
# First call: creates generator
|
|
502
|
+
gen1 = get_generator("microsoft/Phi-3-mini-4k-instruct", hash(User))
|
|
503
|
+
|
|
504
|
+
# Second call: returns cached generator (fast!)
|
|
505
|
+
gen2 = get_generator("microsoft/Phi-3-mini-4k-instruct", hash(User))
|
|
506
|
+
```
|
|
507
|
+
|
|
508
|
+
### Batch Processing
|
|
509
|
+
|
|
510
|
+
```python
|
|
511
|
+
# Process multiple items efficiently
|
|
512
|
+
model = outlines.models.transformers("microsoft/Phi-3-mini-4k-instruct")
|
|
513
|
+
generator = outlines.generate.json(model, User)
|
|
514
|
+
|
|
515
|
+
texts = ["User: Alice, 25", "User: Bob, 30", "User: Carol, 35"]
|
|
516
|
+
|
|
517
|
+
# Reuse generator (model stays loaded)
|
|
518
|
+
users = [generator(text) for text in texts]
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
### Minimize Schema Complexity
|
|
522
|
+
|
|
523
|
+
```python
|
|
524
|
+
# ✅ Good: Simple, flat structure (faster)
|
|
525
|
+
class SimplePerson(BaseModel):
|
|
526
|
+
name: str
|
|
527
|
+
age: int
|
|
528
|
+
city: str
|
|
529
|
+
|
|
530
|
+
# ⚠️ Slower: Deep nesting
|
|
531
|
+
class ComplexPerson(BaseModel):
|
|
532
|
+
personal_info: PersonalInfo
|
|
533
|
+
address: Address
|
|
534
|
+
employment: Employment
|
|
535
|
+
# ... many nested levels
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
## Error Handling
|
|
539
|
+
|
|
540
|
+
### Handle Missing Fields
|
|
541
|
+
|
|
542
|
+
```python
|
|
543
|
+
from pydantic import ValidationError
|
|
544
|
+
|
|
545
|
+
class User(BaseModel):
|
|
546
|
+
name: str
|
|
547
|
+
age: int
|
|
548
|
+
email: str
|
|
549
|
+
|
|
550
|
+
try:
|
|
551
|
+
user = generator("Generate user") # May not include all fields
|
|
552
|
+
except ValidationError as e:
|
|
553
|
+
print(f"Validation error: {e}")
|
|
554
|
+
# Handle gracefully
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
### Fallback with Optional Fields
|
|
558
|
+
|
|
559
|
+
```python
|
|
560
|
+
class RobustUser(BaseModel):
|
|
561
|
+
name: str # Required
|
|
562
|
+
age: Optional[int] = None # Optional
|
|
563
|
+
email: Optional[str] = None # Optional
|
|
564
|
+
|
|
565
|
+
# More likely to succeed even with incomplete data
|
|
566
|
+
user = generator("Generate user: Alice")
|
|
567
|
+
print(user.name) # "Alice"
|
|
568
|
+
print(user.age) # None (not provided)
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
## Best Practices
|
|
572
|
+
|
|
573
|
+
### 1. Use Specific Types
|
|
574
|
+
|
|
575
|
+
```python
|
|
576
|
+
# ✅ Good: Specific types
|
|
577
|
+
class Product(BaseModel):
|
|
578
|
+
name: str
|
|
579
|
+
price: float # Not Any or str
|
|
580
|
+
quantity: int # Not str
|
|
581
|
+
in_stock: bool # Not int
|
|
582
|
+
|
|
583
|
+
# ❌ Bad: Generic types
|
|
584
|
+
class Product(BaseModel):
|
|
585
|
+
name: Any
|
|
586
|
+
price: str # Should be float
|
|
587
|
+
quantity: str # Should be int
|
|
588
|
+
```
|
|
589
|
+
|
|
590
|
+
### 2. Add Descriptions
|
|
591
|
+
|
|
592
|
+
```python
|
|
593
|
+
# ✅ Good: Clear descriptions
|
|
594
|
+
class Article(BaseModel):
|
|
595
|
+
title: str = Field(description="Article title, 10-100 characters")
|
|
596
|
+
content: str = Field(description="Main article content in paragraphs")
|
|
597
|
+
tags: list[str] = Field(description="List of relevant topic tags")
|
|
598
|
+
|
|
599
|
+
# Descriptions help the model understand expected output
|
|
600
|
+
```
|
|
601
|
+
|
|
602
|
+
### 3. Use Constraints
|
|
603
|
+
|
|
604
|
+
```python
|
|
605
|
+
# ✅ Good: With constraints
|
|
606
|
+
class Age(BaseModel):
|
|
607
|
+
value: int = Field(ge=0, le=120, description="Age in years")
|
|
608
|
+
|
|
609
|
+
# ❌ Bad: No constraints
|
|
610
|
+
class Age(BaseModel):
|
|
611
|
+
value: int # Could be negative or > 120
|
|
612
|
+
```
|
|
613
|
+
|
|
614
|
+
### 4. Prefer Enums Over Strings
|
|
615
|
+
|
|
616
|
+
```python
|
|
617
|
+
# ✅ Good: Enum for fixed set
|
|
618
|
+
class Priority(str, Enum):
|
|
619
|
+
LOW = "low"
|
|
620
|
+
MEDIUM = "medium"
|
|
621
|
+
HIGH = "high"
|
|
622
|
+
|
|
623
|
+
class Task(BaseModel):
|
|
624
|
+
priority: Priority # Guaranteed valid
|
|
625
|
+
|
|
626
|
+
# ❌ Bad: Free-form string
|
|
627
|
+
class Task(BaseModel):
|
|
628
|
+
priority: str # Could be "urgent", "ASAP", "!!", etc.
|
|
629
|
+
```
|
|
630
|
+
|
|
631
|
+
### 5. Test Your Models
|
|
632
|
+
|
|
633
|
+
```python
|
|
634
|
+
# Test models work as expected
|
|
635
|
+
def test_product_model():
|
|
636
|
+
product = Product(
|
|
637
|
+
name="Test Product",
|
|
638
|
+
price=19.99,
|
|
639
|
+
quantity=10,
|
|
640
|
+
in_stock=True
|
|
641
|
+
)
|
|
642
|
+
assert product.price == 19.99
|
|
643
|
+
assert isinstance(product, Product)
|
|
644
|
+
|
|
645
|
+
# Run tests before using in production
|
|
646
|
+
```
|
|
647
|
+
|
|
648
|
+
## Resources
|
|
649
|
+
|
|
650
|
+
- **Pydantic Docs**: https://docs.pydantic.dev
|
|
651
|
+
- **JSON Schema**: https://json-schema.org
|
|
652
|
+
- **Outlines GitHub**: https://github.com/outlines-dev/outlines
|