算法艺术创作
algorithmic-art
通过代码和可调参数创作生成艺术与交互式视觉效果。
structured-generation【设计与创意】Design and troubleshoot Outlines constrained-generation output types, generators, backends, and logits processors.
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Use this sub-skill when the task is to make an Outlines model return a specific structure: JSON, a Pydantic/dataclass/TypedDict schema, a Literal/Enum/Choice, a regular expression, or a context-free grammar. It also covers the Generator contract, backend selection, raw-output parsing, batch/stream behavior, and custom logits processors.
Route model setup elsewhere:
../local-models/SKILL.md.../remote-providers/SKILL.md.Application, Chat, images, and workflow orchestration -> ../prompt-workflows/SKILL.md.Choose the output language. Use Python types for simple data, Literal/Enum/Choice for finite choices, a Pydantic/dataclass/TypedDict/GenSON/JsonSchema for JSON, Regex for a regular language, or CFG for Lark-style grammars.
Pick a compatible model route. Local steerable models compile output types into logits processors. Server/black-box providers support only the structured-output formats their SDK/server exposes.
Call directly or reuse a generator. A model call and a generator call are equivalent in shape:
response = model(prompt, OutputType, max_new_tokens=200)
generator = outlines.Generator(model, OutputType)
response = generator(prompt, max_new_tokens=200)
Parse the raw string yourself. Outlines v1 returns text. For Pydantic schemas, call Schema.model_validate_json(response) after generation.
Set the backend only for steerable models. Defaults are JSON schema=outlines_core, regex=outlines_core, CFG=llguidance. Override with backend="llguidance" or backend="xgrammar" only after checking support.
Use a custom processor only with steerable models. Generator(model, processor=processor) is mutually exclusive with output_type; server models raise NotImplementedError for processors.
Validate before generation. Check a JSON schema/regex/grammar against representative samples before spending tokens or running a model.
references/api-reference.md: constructor signatures, output-type conversion rules, direct model calls, Generator, batch/stream, and parsing contracts.references/backends.md: default and selectable backends, model compatibility, unsupported cases, and logits-processor flow.references/workflows.md: schema-first and regex/CFG iteration patterns, Pydantic parsing, and structured workflow recipes.references/troubleshooting.md: symptoms, causes, and recovery for output-type, backend, parsing, and processor failures.Use scripts/validate_structure.py for local, no-model validation of JSON samples against JSON Schema or text samples against a regex before you wire the structure into an Outlines call.
Examples:
python scripts/validate_structure.py json --schema '{"type":"object","required":["name"],"properties":{"name":{"type":"string"}}}' --data '{"name":"Ada"}'
python scripts/validate_structure.py regex --pattern '[0-9]{3}' --text '123'
The script does not import provider clients, download models, or call a network service.
backend="outlines_core" for CFG; use llguidance or xgrammar with a compatible steerable model.JsonSchema(..., whitespace_pattern=...) with llguidance or xgrammar; use outlines_core if whitespace control is required.