Generate AI Node
The nanoctl generate ai-node
command leverages OpenAI to automatically generate Blok Nodes based on natural language prompts. This powerful tool helps developers quickly scaffold production-ready bloks that follow the framework’s structural conventions.
By combining AI code generation with automatic registration in your project, this command significantly accelerates the Node development process while ensuring adherence to Blok standards.
Generate AI Node
Syntax
Creates a new Node using OpenAI’s API based on a natural language prompt.
Options
Option | Type | Description | Default |
---|---|---|---|
--name | string | Name for the new Node (required) | None |
--prompt | string | Description of the Node’s functionality (required) | None |
--api-key | string | OpenAI API key (falls back to env variable) | OPENAI_API_KEY |
--type | string | Type of template: class or module | class |
--help | boolean | Show help | false |
Examples
Generate a Basic Node
Generate a Node with Specific API Key
Generate a Node with Custom Type
What Happens When You Run This Command
When you execute the generate ai-node
command:
- The CLI sends your prompt to OpenAI to generate a complete Node implementation.
- The generated code is cleaned up and formatted properly.
- A new directory is created under
./nodes/
with your specified name. - The Node is automatically registered in your project’s
Nodes.ts
registry file. - The newly created Node and updated registry files are opened in VS Code.
Requirements
- Valid OpenAI API key (provided via
--api-key
flag orOPENAI_API_KEY
environment variable) - Existing Blok project structure
- Internet connection to access OpenAI API
Best Practices
-
Provide Clear, Specific Prompts: Craft prompts that are focused and descriptive. The more context you give, the better the AI can generate relevant and functional code. Avoid vague instructions and instead describe what the node should do, what inputs it expects, and any key logic it should contain.
-
Review and Test Generated Nodes Thoroughly: AI-generated code is meant to serve as a starting point, not a finished product. Always inspect and test the output carefully before using it in production environments. Validate logic, handle edge cases, and ensure it aligns with your system’s standards and expectations.
-
Use Descriptive, Purpose-Driven Names: Name your nodes clearly and consistently to reflect their function. This improves readability, maintainability, and collaboration—especially when multiple nodes are used in workflows or shared across teams.
-
Avoid Hardcoding Secrets: To keep your setup secure and flexible, add your
OPENAI_API_KEY
to your environment variables rather than passing it directly in the command line. This prevents accidental exposure and makes it easier to manage configurations across environments. -
Understand the Role of
generate ai-node
: Thegenerate ai-node
command is a convenience tool—not a compiler or validator. It helps bootstrap a new node using AI assistance, but the resulting code is a code snippet, not a production-ready solution. Treat it as a draft you will refine, test, and adapt as needed.