System schematów w NLP2CMD pozwala na ekstrakcję, przechowywanie i wykorzystanie metadanych poleceń do generowania precyzyjnych komend z naturalnego języka.
Schema opisuje strukturę polecenia:
{
"command": "docker",
"version": "1.0",
"description": "Docker container management",
"category": "container",
"parameters": [
{
"name": "image",
"type": "string",
"required": true,
"description": "Container image"
}
],
"templates": [
"docker run {image}",
"docker run -d {image}"
]
}
src/nlp2cmd/schema_extraction/)Ekstrakcja schematów z różnych źródeł:
man pages--help outputKey Classes:
from nlp2cmd.schema_extraction import SchemaRegistry
registry = SchemaRegistry(
use_per_command_storage=True,
storage_dir="./command_schemas"
)
# Extract from command help
schema = registry.register_shell_help("docker")
# Extract from OpenAPI
schema = registry.register_openapi_schema("https://api.example.com/openapi.json")
src/nlp2cmd/storage/)Przechowywanie schematów w command_schemas/:
categories/index.jsonStructure:
command_schemas/
├── commands/ # Individual command schemas (per-command storage)
├── categories/ # Schema categories index
├── index.json # Master index of all schemas
└── *.json # Schema files (docker.json, nginx.json, etc.)
src/nlp2cmd/generation/schema/)Note: Module przeniesiony z schema_based/ do generation/schema/ jako shims.
Generowanie komend na podstawie schematów:
# Historical API (deprecated shim)
from nlp2cmd.generation.schema import SchemaBasedGenerator
generator = SchemaBasedGenerator(llm_config)
command = generator.generate_command('find', {'path': '/home', 'pattern': '*.py'})
1. User Input (NL)
↓
2. Schema Registry Lookup
↓
3. Schema-Based Generation
↓
4. Command Output
Note: Wersjonowanie schematów jest obecnie ograniczone do wersji “1.0”.
Planowane wsparcie dla wersjonowania:
{
"command": "docker",
"version": "1.0",
"migration_notes": "v1→v2: --rm moved to run options (planned)"
}
Current State: Schematy są częściowo zintegrowane z pipeline NLP2CMD:
SchemaRegistry ekstrahuje schematy z różnych źródełPerCommandSchemaStore przechowuje schematySchemaBasedGenerator używany w nielicznych miejscachPlanned Integration:
# Schema extraction config
llm_config = {
"model": "ollama/qwen2.5-coder:7b",
"api_base": "http://localhost:11434",
"temperature": 0.1,
"max_tokens": 512,
}
# Registry config
registry_config = {
"use_per_command_storage": True,
"storage_dir": "./command_schemas",
"use_llm": False # Optional LLM extraction
}
schema_based/ → generation/schema/ (shims)