The schema-based generation system uses dynamically extracted command schemas to generate accurate shell commands.
from nlp2cmd.schema_based.generator import SchemaBasedGenerator
generator = SchemaDrivenGenerator()
generator.learn_from_schema(schema)
command = generator.generate_command("find", {"pattern": "*.py"})
from nlp2cmd.schema_based.adapter import SchemaDrivenAppSpecAdapter
adapter = SchemaDrivenAppSpecAdapter(schema_registry=registry)
nlp = NLP2CMD(adapter=adapter)
result = nlp.transform("list containers")
Each command schema is stored in its own JSON file:
{
"command": "docker",
"version": "2.0.0",
"description": "Docker container management",
"template": "docker {subcommand} {options}",
"parameters": [...],
"examples": [...]
}
from nlp2cmd.storage.versioned_store import VersionedSchemaStore
store = VersionedSchemaStore("./schemas")
store.store_schema_version(schema, "2.1.0", make_active=True)
versions = store.list_versions("docker")
The system detects command versions and adapts syntax:
from nlp2cmd.intelligent.version_aware_generator import VersionAwareCommandGenerator
generator = VersionAwareCommandGenerator(schema_store)
command, metadata = generator.generate_command("list containers")
# Automatically detects Docker version and uses appropriate schema
from nlp2cmd.intelligent.command_detector import CommandDetector
detector = CommandDetector()
command = detector.detect_command("show all running containers")
# Returns: "docker"
registry = DynamicSchemaRegistry(
use_per_command_storage=True,
storage_dir="./schemas",
use_llm=True,
llm_config={...}
)
# Register schemas
schema = registry.register_shell_help("docker")
schema = registry.register_appspec("appspec.yaml")
schemas = registry.register_dynamic_export("export.json")
# Get schemas
schema = registry.get_command_by_name("docker")
matches = registry.find_matching_commands("list containers")
@dataclass
class CommandSchema:
name: str
description: str
category: str
parameters: List[CommandParameter]
examples: List[str]
patterns: List[str]
source_type: str
metadata: Dict[str, Any]
template: Optional[str]
@dataclass
class ExtractedSchema:
source: str
source_type: str
commands: List[CommandSchema]
metadata: Dict[str, Any]
from nlp2cmd import NLP2CMD
from nlp2cmd.adapters.dynamic import DynamicAdapter
# Initialize with dynamic adapter
adapter = DynamicAdapter()
nlp = NLP2CMD(adapter=adapter)
# Transform query
result = nlp.transform("find all python files")
print(result.command) # find . -name "*.py"
from nlp2cmd.intelligent import IntelligentNLP2CMD
# Initialize with version-aware generation
nlp = IntelligentNLP2CMD(storage_dir="./schemas")
# Transform with version detection
ir = nlp.transform("list containers", detect_version=True)
print(f"Command: {ir.dsl}")
print(f"Version detected: {ir.metadata.get('detected_version')}")
registry = DynamicSchemaRegistry(use_per_command_storage=True)
nlp = IntelligentNLP2CMD()
result = nlp.transform(query, detect_version=True)
nlp.learn_from_feedback(query, generated, corrected)
registry.save_cache("schemas.json")
registry.load_cache("schemas.json")