Generate Code
Generates code using Google Vertex AI's code generation models.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
info
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Inputs
- Connection Id - The unique identifier of the connection to Vertex AI, typically obtained from the Connect node.
- Prompt - The prompt describing the code to be generated.
Options
- Temperature - Controls randomness in the response (optional).
- Max Output Tokens - Maximum number of tokens in the response. Default is 256. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words.
- Candidate Count - Number of response candidates to generate. Default is 1.
- Model - The code model to use. Options include:
- Custom Model
- Code Bison
- Default is Code Bison.
- Custom Model - Custom model name if "Custom Model" is selected.
- Locations - Google Cloud region for the service. Default is "us-central1".
- Publishers - Publisher of the model. Default is "google".
Output
- Response - The generated code from the Vertex AI model as an object.
How It Works
The Generate Code node sends a prompt to a Vertex AI code generation model and returns the model's code response. When executed, the node:
- Validates the connection ID and retrieves the authentication token
- Validates the required prompt input
- Collects all optional parameters and configurations
- Constructs a request with the prompt and parameters
- Sends the request to the Vertex AI code model endpoint
- Processes the response and returns it
Requirements
- A valid connection to Vertex AI established with the Connect node
- Valid Google Cloud credentials with appropriate permissions
- A properly configured Vertex AI code generation model
- A clear prompt describing the desired code
Error Handling
The node will return specific errors in the following cases:
- Empty or invalid Connection ID
- Empty prompt
- Invalid parameter values
- Missing required parameters
- Invalid model selection
- Network connectivity issues
- Vertex AI service errors
- Authentication failures
Usage Notes
- The Connection ID must be obtained from a successful Connect node execution
- The Prompt should clearly describe what code you want to generate
- Temperature controls creativity: lower values for more deterministic code, higher values for more creative solutions
- Max Output Tokens limits the length of generated code
- Multiple candidates can be generated by increasing Candidate Count
- The Code Bison model is optimized for code generation tasks
- The Locations parameter should match where your Vertex AI resources are deployed
- Generated code should be reviewed and tested before use in production environments