@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,740 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: instructor
|
|
3
|
+
description: Extract structured data from LLM responses with Pydantic validation, retry failed extractions automatically, parse complex JSON with type safety, and stream partial results with Instructor - battle-tested structured output library
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
author: Synthetic Sciences
|
|
6
|
+
license: MIT
|
|
7
|
+
tags: [Prompt Engineering, Instructor, Structured Output, Pydantic, Data Extraction, JSON Parsing, Type Safety, Validation, Streaming, OpenAI, Anthropic]
|
|
8
|
+
dependencies: [instructor, pydantic, openai, anthropic]
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# Instructor: Structured LLM Outputs
|
|
12
|
+
|
|
13
|
+
## When to Use This Skill
|
|
14
|
+
|
|
15
|
+
Use Instructor when you need to:
|
|
16
|
+
- **Extract structured data** from LLM responses reliably
|
|
17
|
+
- **Validate outputs** against Pydantic schemas automatically
|
|
18
|
+
- **Retry failed extractions** with automatic error handling
|
|
19
|
+
- **Parse complex JSON** with type safety and validation
|
|
20
|
+
- **Stream partial results** for real-time processing
|
|
21
|
+
- **Support multiple LLM providers** with consistent API
|
|
22
|
+
|
|
23
|
+
**GitHub Stars**: 15,000+ | **Battle-tested**: 100,000+ developers
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
# Base installation
|
|
29
|
+
pip install instructor
|
|
30
|
+
|
|
31
|
+
# With specific providers
|
|
32
|
+
pip install "instructor[anthropic]" # Anthropic Claude
|
|
33
|
+
pip install "instructor[openai]" # OpenAI
|
|
34
|
+
pip install "instructor[all]" # All providers
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Quick Start
|
|
38
|
+
|
|
39
|
+
### Basic Example: Extract User Data
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
import instructor
|
|
43
|
+
from pydantic import BaseModel
|
|
44
|
+
from anthropic import Anthropic
|
|
45
|
+
|
|
46
|
+
# Define output structure
|
|
47
|
+
class User(BaseModel):
|
|
48
|
+
name: str
|
|
49
|
+
age: int
|
|
50
|
+
email: str
|
|
51
|
+
|
|
52
|
+
# Create instructor client
|
|
53
|
+
client = instructor.from_anthropic(Anthropic())
|
|
54
|
+
|
|
55
|
+
# Extract structured data
|
|
56
|
+
user = client.messages.create(
|
|
57
|
+
model="claude-sonnet-4-5-20250929",
|
|
58
|
+
max_tokens=1024,
|
|
59
|
+
messages=[{
|
|
60
|
+
"role": "user",
|
|
61
|
+
"content": "John Doe is 30 years old. His email is john@example.com"
|
|
62
|
+
}],
|
|
63
|
+
response_model=User
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
print(user.name) # "John Doe"
|
|
67
|
+
print(user.age) # 30
|
|
68
|
+
print(user.email) # "john@example.com"
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### With OpenAI
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from openai import OpenAI
|
|
75
|
+
|
|
76
|
+
client = instructor.from_openai(OpenAI())
|
|
77
|
+
|
|
78
|
+
user = client.chat.completions.create(
|
|
79
|
+
model="gpt-4o-mini",
|
|
80
|
+
response_model=User,
|
|
81
|
+
messages=[{"role": "user", "content": "Extract: Alice, 25, alice@email.com"}]
|
|
82
|
+
)
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Core Concepts
|
|
86
|
+
|
|
87
|
+
### 1. Response Models (Pydantic)
|
|
88
|
+
|
|
89
|
+
Response models define the structure and validation rules for LLM outputs.
|
|
90
|
+
|
|
91
|
+
#### Basic Model
|
|
92
|
+
|
|
93
|
+
```python
|
|
94
|
+
from pydantic import BaseModel, Field
|
|
95
|
+
|
|
96
|
+
class Article(BaseModel):
|
|
97
|
+
title: str = Field(description="Article title")
|
|
98
|
+
author: str = Field(description="Author name")
|
|
99
|
+
word_count: int = Field(description="Number of words", gt=0)
|
|
100
|
+
tags: list[str] = Field(description="List of relevant tags")
|
|
101
|
+
|
|
102
|
+
article = client.messages.create(
|
|
103
|
+
model="claude-sonnet-4-5-20250929",
|
|
104
|
+
max_tokens=1024,
|
|
105
|
+
messages=[{
|
|
106
|
+
"role": "user",
|
|
107
|
+
"content": "Analyze this article: [article text]"
|
|
108
|
+
}],
|
|
109
|
+
response_model=Article
|
|
110
|
+
)
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
**Benefits:**
|
|
114
|
+
- Type safety with Python type hints
|
|
115
|
+
- Automatic validation (word_count > 0)
|
|
116
|
+
- Self-documenting with Field descriptions
|
|
117
|
+
- IDE autocomplete support
|
|
118
|
+
|
|
119
|
+
#### Nested Models
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
class Address(BaseModel):
|
|
123
|
+
street: str
|
|
124
|
+
city: str
|
|
125
|
+
country: str
|
|
126
|
+
|
|
127
|
+
class Person(BaseModel):
|
|
128
|
+
name: str
|
|
129
|
+
age: int
|
|
130
|
+
address: Address # Nested model
|
|
131
|
+
|
|
132
|
+
person = client.messages.create(
|
|
133
|
+
model="claude-sonnet-4-5-20250929",
|
|
134
|
+
max_tokens=1024,
|
|
135
|
+
messages=[{
|
|
136
|
+
"role": "user",
|
|
137
|
+
"content": "John lives at 123 Main St, Boston, USA"
|
|
138
|
+
}],
|
|
139
|
+
response_model=Person
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
print(person.address.city) # "Boston"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
#### Optional Fields
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from typing import Optional
|
|
149
|
+
|
|
150
|
+
class Product(BaseModel):
|
|
151
|
+
name: str
|
|
152
|
+
price: float
|
|
153
|
+
discount: Optional[float] = None # Optional
|
|
154
|
+
description: str = Field(default="No description") # Default value
|
|
155
|
+
|
|
156
|
+
# LLM doesn't need to provide discount or description
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### Enums for Constraints
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
from enum import Enum
|
|
163
|
+
|
|
164
|
+
class Sentiment(str, Enum):
|
|
165
|
+
POSITIVE = "positive"
|
|
166
|
+
NEGATIVE = "negative"
|
|
167
|
+
NEUTRAL = "neutral"
|
|
168
|
+
|
|
169
|
+
class Review(BaseModel):
|
|
170
|
+
text: str
|
|
171
|
+
sentiment: Sentiment # Only these 3 values allowed
|
|
172
|
+
|
|
173
|
+
review = client.messages.create(
|
|
174
|
+
model="claude-sonnet-4-5-20250929",
|
|
175
|
+
max_tokens=1024,
|
|
176
|
+
messages=[{
|
|
177
|
+
"role": "user",
|
|
178
|
+
"content": "This product is amazing!"
|
|
179
|
+
}],
|
|
180
|
+
response_model=Review
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
print(review.sentiment) # Sentiment.POSITIVE
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### 2. Validation
|
|
187
|
+
|
|
188
|
+
Pydantic validates LLM outputs automatically. If validation fails, Instructor retries.
|
|
189
|
+
|
|
190
|
+
#### Built-in Validators
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
from pydantic import Field, EmailStr, HttpUrl
|
|
194
|
+
|
|
195
|
+
class Contact(BaseModel):
|
|
196
|
+
name: str = Field(min_length=2, max_length=100)
|
|
197
|
+
age: int = Field(ge=0, le=120) # 0 <= age <= 120
|
|
198
|
+
email: EmailStr # Validates email format
|
|
199
|
+
website: HttpUrl # Validates URL format
|
|
200
|
+
|
|
201
|
+
# If LLM provides invalid data, Instructor retries automatically
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
#### Custom Validators
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
from pydantic import field_validator
|
|
208
|
+
|
|
209
|
+
class Event(BaseModel):
|
|
210
|
+
name: str
|
|
211
|
+
date: str
|
|
212
|
+
attendees: int
|
|
213
|
+
|
|
214
|
+
@field_validator('date')
|
|
215
|
+
def validate_date(cls, v):
|
|
216
|
+
"""Ensure date is in YYYY-MM-DD format."""
|
|
217
|
+
import re
|
|
218
|
+
if not re.match(r'\d{4}-\d{2}-\d{2}', v):
|
|
219
|
+
raise ValueError('Date must be YYYY-MM-DD format')
|
|
220
|
+
return v
|
|
221
|
+
|
|
222
|
+
@field_validator('attendees')
|
|
223
|
+
def validate_attendees(cls, v):
|
|
224
|
+
"""Ensure positive attendees."""
|
|
225
|
+
if v < 1:
|
|
226
|
+
raise ValueError('Must have at least 1 attendee')
|
|
227
|
+
return v
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
#### Model-Level Validation
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
from pydantic import model_validator
|
|
234
|
+
|
|
235
|
+
class DateRange(BaseModel):
|
|
236
|
+
start_date: str
|
|
237
|
+
end_date: str
|
|
238
|
+
|
|
239
|
+
@model_validator(mode='after')
|
|
240
|
+
def check_dates(self):
|
|
241
|
+
"""Ensure end_date is after start_date."""
|
|
242
|
+
from datetime import datetime
|
|
243
|
+
start = datetime.strptime(self.start_date, '%Y-%m-%d')
|
|
244
|
+
end = datetime.strptime(self.end_date, '%Y-%m-%d')
|
|
245
|
+
|
|
246
|
+
if end < start:
|
|
247
|
+
raise ValueError('end_date must be after start_date')
|
|
248
|
+
return self
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### 3. Automatic Retrying
|
|
252
|
+
|
|
253
|
+
Instructor retries automatically when validation fails, providing error feedback to the LLM.
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
# Retries up to 3 times if validation fails
|
|
257
|
+
user = client.messages.create(
|
|
258
|
+
model="claude-sonnet-4-5-20250929",
|
|
259
|
+
max_tokens=1024,
|
|
260
|
+
messages=[{
|
|
261
|
+
"role": "user",
|
|
262
|
+
"content": "Extract user from: John, age unknown"
|
|
263
|
+
}],
|
|
264
|
+
response_model=User,
|
|
265
|
+
max_retries=3 # Default is 3
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
# If age can't be extracted, Instructor tells the LLM:
|
|
269
|
+
# "Validation error: age - field required"
|
|
270
|
+
# LLM tries again with better extraction
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**How it works:**
|
|
274
|
+
1. LLM generates output
|
|
275
|
+
2. Pydantic validates
|
|
276
|
+
3. If invalid: Error message sent back to LLM
|
|
277
|
+
4. LLM tries again with error feedback
|
|
278
|
+
5. Repeats up to max_retries
|
|
279
|
+
|
|
280
|
+
### 4. Streaming
|
|
281
|
+
|
|
282
|
+
Stream partial results for real-time processing.
|
|
283
|
+
|
|
284
|
+
#### Streaming Partial Objects
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
from instructor import Partial
|
|
288
|
+
|
|
289
|
+
class Story(BaseModel):
|
|
290
|
+
title: str
|
|
291
|
+
content: str
|
|
292
|
+
tags: list[str]
|
|
293
|
+
|
|
294
|
+
# Stream partial updates as LLM generates
|
|
295
|
+
for partial_story in client.messages.create_partial(
|
|
296
|
+
model="claude-sonnet-4-5-20250929",
|
|
297
|
+
max_tokens=1024,
|
|
298
|
+
messages=[{
|
|
299
|
+
"role": "user",
|
|
300
|
+
"content": "Write a short sci-fi story"
|
|
301
|
+
}],
|
|
302
|
+
response_model=Story
|
|
303
|
+
):
|
|
304
|
+
print(f"Title: {partial_story.title}")
|
|
305
|
+
print(f"Content so far: {partial_story.content[:100]}...")
|
|
306
|
+
# Update UI in real-time
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
#### Streaming Iterables
|
|
310
|
+
|
|
311
|
+
```python
|
|
312
|
+
class Task(BaseModel):
|
|
313
|
+
title: str
|
|
314
|
+
priority: str
|
|
315
|
+
|
|
316
|
+
# Stream list items as they're generated
|
|
317
|
+
tasks = client.messages.create_iterable(
|
|
318
|
+
model="claude-sonnet-4-5-20250929",
|
|
319
|
+
max_tokens=1024,
|
|
320
|
+
messages=[{
|
|
321
|
+
"role": "user",
|
|
322
|
+
"content": "Generate 10 project tasks"
|
|
323
|
+
}],
|
|
324
|
+
response_model=Task
|
|
325
|
+
)
|
|
326
|
+
|
|
327
|
+
for task in tasks:
|
|
328
|
+
print(f"- {task.title} ({task.priority})")
|
|
329
|
+
# Process each task as it arrives
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
## Provider Configuration
|
|
333
|
+
|
|
334
|
+
### Anthropic Claude
|
|
335
|
+
|
|
336
|
+
```python
|
|
337
|
+
import instructor
|
|
338
|
+
from anthropic import Anthropic
|
|
339
|
+
|
|
340
|
+
client = instructor.from_anthropic(
|
|
341
|
+
Anthropic(api_key="your-api-key")
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
# Use with Claude models
|
|
345
|
+
response = client.messages.create(
|
|
346
|
+
model="claude-sonnet-4-5-20250929",
|
|
347
|
+
max_tokens=1024,
|
|
348
|
+
messages=[...],
|
|
349
|
+
response_model=YourModel
|
|
350
|
+
)
|
|
351
|
+
```
|
|
352
|
+
|
|
353
|
+
### OpenAI
|
|
354
|
+
|
|
355
|
+
```python
|
|
356
|
+
from openai import OpenAI
|
|
357
|
+
|
|
358
|
+
client = instructor.from_openai(
|
|
359
|
+
OpenAI(api_key="your-api-key")
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
response = client.chat.completions.create(
|
|
363
|
+
model="gpt-4o-mini",
|
|
364
|
+
response_model=YourModel,
|
|
365
|
+
messages=[...]
|
|
366
|
+
)
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### Local Models (Ollama)
|
|
370
|
+
|
|
371
|
+
```python
|
|
372
|
+
from openai import OpenAI
|
|
373
|
+
|
|
374
|
+
# Point to local Ollama server
|
|
375
|
+
client = instructor.from_openai(
|
|
376
|
+
OpenAI(
|
|
377
|
+
base_url="http://localhost:11434/v1",
|
|
378
|
+
api_key="ollama" # Required but ignored
|
|
379
|
+
),
|
|
380
|
+
mode=instructor.Mode.JSON
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
response = client.chat.completions.create(
|
|
384
|
+
model="llama3.1",
|
|
385
|
+
response_model=YourModel,
|
|
386
|
+
messages=[...]
|
|
387
|
+
)
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## Common Patterns
|
|
391
|
+
|
|
392
|
+
### Pattern 1: Data Extraction from Text
|
|
393
|
+
|
|
394
|
+
```python
|
|
395
|
+
class CompanyInfo(BaseModel):
|
|
396
|
+
name: str
|
|
397
|
+
founded_year: int
|
|
398
|
+
industry: str
|
|
399
|
+
employees: int
|
|
400
|
+
headquarters: str
|
|
401
|
+
|
|
402
|
+
text = """
|
|
403
|
+
Tesla, Inc. was founded in 2003. It operates in the automotive and energy
|
|
404
|
+
industry with approximately 140,000 employees. The company is headquartered
|
|
405
|
+
in Austin, Texas.
|
|
406
|
+
"""
|
|
407
|
+
|
|
408
|
+
company = client.messages.create(
|
|
409
|
+
model="claude-sonnet-4-5-20250929",
|
|
410
|
+
max_tokens=1024,
|
|
411
|
+
messages=[{
|
|
412
|
+
"role": "user",
|
|
413
|
+
"content": f"Extract company information from: {text}"
|
|
414
|
+
}],
|
|
415
|
+
response_model=CompanyInfo
|
|
416
|
+
)
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### Pattern 2: Classification
|
|
420
|
+
|
|
421
|
+
```python
|
|
422
|
+
class Category(str, Enum):
|
|
423
|
+
TECHNOLOGY = "technology"
|
|
424
|
+
FINANCE = "finance"
|
|
425
|
+
HEALTHCARE = "healthcare"
|
|
426
|
+
EDUCATION = "education"
|
|
427
|
+
OTHER = "other"
|
|
428
|
+
|
|
429
|
+
class ArticleClassification(BaseModel):
|
|
430
|
+
category: Category
|
|
431
|
+
confidence: float = Field(ge=0.0, le=1.0)
|
|
432
|
+
keywords: list[str]
|
|
433
|
+
|
|
434
|
+
classification = client.messages.create(
|
|
435
|
+
model="claude-sonnet-4-5-20250929",
|
|
436
|
+
max_tokens=1024,
|
|
437
|
+
messages=[{
|
|
438
|
+
"role": "user",
|
|
439
|
+
"content": "Classify this article: [article text]"
|
|
440
|
+
}],
|
|
441
|
+
response_model=ArticleClassification
|
|
442
|
+
)
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
### Pattern 3: Multi-Entity Extraction
|
|
446
|
+
|
|
447
|
+
```python
|
|
448
|
+
class Person(BaseModel):
|
|
449
|
+
name: str
|
|
450
|
+
role: str
|
|
451
|
+
|
|
452
|
+
class Organization(BaseModel):
|
|
453
|
+
name: str
|
|
454
|
+
industry: str
|
|
455
|
+
|
|
456
|
+
class Entities(BaseModel):
|
|
457
|
+
people: list[Person]
|
|
458
|
+
organizations: list[Organization]
|
|
459
|
+
locations: list[str]
|
|
460
|
+
|
|
461
|
+
text = "Tim Cook, CEO of Apple, announced at the event in Cupertino..."
|
|
462
|
+
|
|
463
|
+
entities = client.messages.create(
|
|
464
|
+
model="claude-sonnet-4-5-20250929",
|
|
465
|
+
max_tokens=1024,
|
|
466
|
+
messages=[{
|
|
467
|
+
"role": "user",
|
|
468
|
+
"content": f"Extract all entities from: {text}"
|
|
469
|
+
}],
|
|
470
|
+
response_model=Entities
|
|
471
|
+
)
|
|
472
|
+
|
|
473
|
+
for person in entities.people:
|
|
474
|
+
print(f"{person.name} - {person.role}")
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### Pattern 4: Structured Analysis
|
|
478
|
+
|
|
479
|
+
```python
|
|
480
|
+
class SentimentAnalysis(BaseModel):
|
|
481
|
+
overall_sentiment: Sentiment
|
|
482
|
+
positive_aspects: list[str]
|
|
483
|
+
negative_aspects: list[str]
|
|
484
|
+
suggestions: list[str]
|
|
485
|
+
score: float = Field(ge=-1.0, le=1.0)
|
|
486
|
+
|
|
487
|
+
review = "The product works well but setup was confusing..."
|
|
488
|
+
|
|
489
|
+
analysis = client.messages.create(
|
|
490
|
+
model="claude-sonnet-4-5-20250929",
|
|
491
|
+
max_tokens=1024,
|
|
492
|
+
messages=[{
|
|
493
|
+
"role": "user",
|
|
494
|
+
"content": f"Analyze this review: {review}"
|
|
495
|
+
}],
|
|
496
|
+
response_model=SentimentAnalysis
|
|
497
|
+
)
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### Pattern 5: Batch Processing
|
|
501
|
+
|
|
502
|
+
```python
|
|
503
|
+
def extract_person(text: str) -> Person:
|
|
504
|
+
return client.messages.create(
|
|
505
|
+
model="claude-sonnet-4-5-20250929",
|
|
506
|
+
max_tokens=1024,
|
|
507
|
+
messages=[{
|
|
508
|
+
"role": "user",
|
|
509
|
+
"content": f"Extract person from: {text}"
|
|
510
|
+
}],
|
|
511
|
+
response_model=Person
|
|
512
|
+
)
|
|
513
|
+
|
|
514
|
+
texts = [
|
|
515
|
+
"John Doe is a 30-year-old engineer",
|
|
516
|
+
"Jane Smith, 25, works in marketing",
|
|
517
|
+
"Bob Johnson, age 40, software developer"
|
|
518
|
+
]
|
|
519
|
+
|
|
520
|
+
people = [extract_person(text) for text in texts]
|
|
521
|
+
```
|
|
522
|
+
|
|
523
|
+
## Advanced Features
|
|
524
|
+
|
|
525
|
+
### Union Types
|
|
526
|
+
|
|
527
|
+
```python
|
|
528
|
+
from typing import Union
|
|
529
|
+
|
|
530
|
+
class TextContent(BaseModel):
|
|
531
|
+
type: str = "text"
|
|
532
|
+
content: str
|
|
533
|
+
|
|
534
|
+
class ImageContent(BaseModel):
|
|
535
|
+
type: str = "image"
|
|
536
|
+
url: HttpUrl
|
|
537
|
+
caption: str
|
|
538
|
+
|
|
539
|
+
class Post(BaseModel):
|
|
540
|
+
title: str
|
|
541
|
+
content: Union[TextContent, ImageContent] # Either type
|
|
542
|
+
|
|
543
|
+
# LLM chooses appropriate type based on content
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
### Dynamic Models
|
|
547
|
+
|
|
548
|
+
```python
|
|
549
|
+
from pydantic import create_model
|
|
550
|
+
|
|
551
|
+
# Create model at runtime
|
|
552
|
+
DynamicUser = create_model(
|
|
553
|
+
'User',
|
|
554
|
+
name=(str, ...),
|
|
555
|
+
age=(int, Field(ge=0)),
|
|
556
|
+
email=(EmailStr, ...)
|
|
557
|
+
)
|
|
558
|
+
|
|
559
|
+
user = client.messages.create(
|
|
560
|
+
model="claude-sonnet-4-5-20250929",
|
|
561
|
+
max_tokens=1024,
|
|
562
|
+
messages=[...],
|
|
563
|
+
response_model=DynamicUser
|
|
564
|
+
)
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
### Custom Modes
|
|
568
|
+
|
|
569
|
+
```python
|
|
570
|
+
# For providers without native structured outputs
|
|
571
|
+
client = instructor.from_anthropic(
|
|
572
|
+
Anthropic(),
|
|
573
|
+
mode=instructor.Mode.JSON # JSON mode
|
|
574
|
+
)
|
|
575
|
+
|
|
576
|
+
# Available modes:
|
|
577
|
+
# - Mode.ANTHROPIC_TOOLS (recommended for Claude)
|
|
578
|
+
# - Mode.JSON (fallback)
|
|
579
|
+
# - Mode.TOOLS (OpenAI tools)
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
### Context Management
|
|
583
|
+
|
|
584
|
+
```python
|
|
585
|
+
# Single-use client
|
|
586
|
+
with instructor.from_anthropic(Anthropic()) as client:
|
|
587
|
+
result = client.messages.create(
|
|
588
|
+
model="claude-sonnet-4-5-20250929",
|
|
589
|
+
max_tokens=1024,
|
|
590
|
+
messages=[...],
|
|
591
|
+
response_model=YourModel
|
|
592
|
+
)
|
|
593
|
+
# Client closed automatically
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
## Error Handling
|
|
597
|
+
|
|
598
|
+
### Handling Validation Errors
|
|
599
|
+
|
|
600
|
+
```python
|
|
601
|
+
from pydantic import ValidationError
|
|
602
|
+
|
|
603
|
+
try:
|
|
604
|
+
user = client.messages.create(
|
|
605
|
+
model="claude-sonnet-4-5-20250929",
|
|
606
|
+
max_tokens=1024,
|
|
607
|
+
messages=[...],
|
|
608
|
+
response_model=User,
|
|
609
|
+
max_retries=3
|
|
610
|
+
)
|
|
611
|
+
except ValidationError as e:
|
|
612
|
+
print(f"Failed after retries: {e}")
|
|
613
|
+
# Handle gracefully
|
|
614
|
+
|
|
615
|
+
except Exception as e:
|
|
616
|
+
print(f"API error: {e}")
|
|
617
|
+
```
|
|
618
|
+
|
|
619
|
+
### Custom Error Messages
|
|
620
|
+
|
|
621
|
+
```python
|
|
622
|
+
class ValidatedUser(BaseModel):
|
|
623
|
+
name: str = Field(description="Full name, 2-100 characters")
|
|
624
|
+
age: int = Field(description="Age between 0 and 120", ge=0, le=120)
|
|
625
|
+
email: EmailStr = Field(description="Valid email address")
|
|
626
|
+
|
|
627
|
+
class Config:
|
|
628
|
+
# Custom error messages
|
|
629
|
+
json_schema_extra = {
|
|
630
|
+
"examples": [
|
|
631
|
+
{
|
|
632
|
+
"name": "John Doe",
|
|
633
|
+
"age": 30,
|
|
634
|
+
"email": "john@example.com"
|
|
635
|
+
}
|
|
636
|
+
]
|
|
637
|
+
}
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
## Best Practices
|
|
641
|
+
|
|
642
|
+
### 1. Clear Field Descriptions
|
|
643
|
+
|
|
644
|
+
```python
|
|
645
|
+
# ❌ Bad: Vague
|
|
646
|
+
class Product(BaseModel):
|
|
647
|
+
name: str
|
|
648
|
+
price: float
|
|
649
|
+
|
|
650
|
+
# ✅ Good: Descriptive
|
|
651
|
+
class Product(BaseModel):
|
|
652
|
+
name: str = Field(description="Product name from the text")
|
|
653
|
+
price: float = Field(description="Price in USD, without currency symbol")
|
|
654
|
+
```
|
|
655
|
+
|
|
656
|
+
### 2. Use Appropriate Validation
|
|
657
|
+
|
|
658
|
+
```python
|
|
659
|
+
# ✅ Good: Constrain values
|
|
660
|
+
class Rating(BaseModel):
|
|
661
|
+
score: int = Field(ge=1, le=5, description="Rating from 1 to 5 stars")
|
|
662
|
+
review: str = Field(min_length=10, description="Review text, at least 10 chars")
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
### 3. Provide Examples in Prompts
|
|
666
|
+
|
|
667
|
+
```python
|
|
668
|
+
messages = [{
|
|
669
|
+
"role": "user",
|
|
670
|
+
"content": """Extract person info from: "John, 30, engineer"
|
|
671
|
+
|
|
672
|
+
Example format:
|
|
673
|
+
{
|
|
674
|
+
"name": "John Doe",
|
|
675
|
+
"age": 30,
|
|
676
|
+
"occupation": "engineer"
|
|
677
|
+
}"""
|
|
678
|
+
}]
|
|
679
|
+
```
|
|
680
|
+
|
|
681
|
+
### 4. Use Enums for Fixed Categories
|
|
682
|
+
|
|
683
|
+
```python
|
|
684
|
+
# ✅ Good: Enum ensures valid values
|
|
685
|
+
class Status(str, Enum):
|
|
686
|
+
PENDING = "pending"
|
|
687
|
+
APPROVED = "approved"
|
|
688
|
+
REJECTED = "rejected"
|
|
689
|
+
|
|
690
|
+
class Application(BaseModel):
|
|
691
|
+
status: Status # LLM must choose from enum
|
|
692
|
+
```
|
|
693
|
+
|
|
694
|
+
### 5. Handle Missing Data Gracefully
|
|
695
|
+
|
|
696
|
+
```python
|
|
697
|
+
class PartialData(BaseModel):
|
|
698
|
+
required_field: str
|
|
699
|
+
optional_field: Optional[str] = None
|
|
700
|
+
default_field: str = "default_value"
|
|
701
|
+
|
|
702
|
+
# LLM only needs to provide required_field
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
## Comparison to Alternatives
|
|
706
|
+
|
|
707
|
+
| Feature | Instructor | Manual JSON | LangChain | DSPy |
|
|
708
|
+
|---------|------------|-------------|-----------|------|
|
|
709
|
+
| Type Safety | ✅ Yes | ❌ No | ⚠️ Partial | ✅ Yes |
|
|
710
|
+
| Auto Validation | ✅ Yes | ❌ No | ❌ No | ⚠️ Limited |
|
|
711
|
+
| Auto Retry | ✅ Yes | ❌ No | ❌ No | ✅ Yes |
|
|
712
|
+
| Streaming | ✅ Yes | ❌ No | ✅ Yes | ❌ No |
|
|
713
|
+
| Multi-Provider | ✅ Yes | ⚠️ Manual | ✅ Yes | ✅ Yes |
|
|
714
|
+
| Learning Curve | Low | Low | Medium | High |
|
|
715
|
+
|
|
716
|
+
**When to choose Instructor:**
|
|
717
|
+
- Need structured, validated outputs
|
|
718
|
+
- Want type safety and IDE support
|
|
719
|
+
- Require automatic retries
|
|
720
|
+
- Building data extraction systems
|
|
721
|
+
|
|
722
|
+
**When to choose alternatives:**
|
|
723
|
+
- DSPy: Need prompt optimization
|
|
724
|
+
- LangChain: Building complex chains
|
|
725
|
+
- Manual: Simple, one-off extractions
|
|
726
|
+
|
|
727
|
+
## Resources
|
|
728
|
+
|
|
729
|
+
- **Documentation**: https://python.useinstructor.com
|
|
730
|
+
- **GitHub**: https://github.com/jxnl/instructor (15k+ stars)
|
|
731
|
+
- **Cookbook**: https://python.useinstructor.com/examples
|
|
732
|
+
- **Discord**: Community support available
|
|
733
|
+
|
|
734
|
+
## See Also
|
|
735
|
+
|
|
736
|
+
- `references/validation.md` - Advanced validation patterns
|
|
737
|
+
- `references/providers.md` - Provider-specific configuration
|
|
738
|
+
- `references/examples.md` - Real-world use cases
|
|
739
|
+
|
|
740
|
+
|