Code Recipe
Last updated
Last updated
Use this procedure to use a Code Recipe on the canvas.
Click the plus icon on the canvas and select Code Recipe from the list. This opens the Code tab.
The default code displayed in the interface will also load in Jupyter Notebook when you click the Edit in Notebook button.
Write the Python code to create a dataset or recipe that you want to add to the canvas in the Code tab. Alternatively, click Edit in Notebook to modify the code using the Jupyter Notebook editor. After making changes in the notebook, click Save Back to Recipe to save your updates seamlessly.
You can save your code at key points throughout the development of a recipe, ensuring progress is preserved and changes are tracked effectively. To learn more, see Managing Checkpoints.
Note:
You can add datasets, artifacts, and models available on the canvas as inputs to the code recipe using the plus icon in the Inputs section on the left.
You can view all nodes on the canvas by expanding the Canvas nodes section. Click on individual nodes to inspect them and use the copy option to replicate node names for use in code.
In the following example, you can see the code to fetch a dataset by making an API call:
Click Conditions to add conditions within the recipe, where each condition is defined using a Key, an Operator, and a Value. The Key is predefined in the Project Settings, while you can specify the Value of your choice. The code executes only when the defined condition is met.
Click Save Code to save the code. This enables the Test option. Use this option to test if the code is working as expected. You can use the Stop button to halt the recipe execution at any point during its test run.
Once the test is successful, the output will be displayed on another tab.
Info: You can also view logs while testing the recipe by clicking Log for Test. This provides access to detailed records and allows you to either download the logs as a text file or open them in a new browser tab for a more detailed view.
Ctrl+T (or Cmd+T on Mac) → Test a recipe
Ctrl+R (or Cmd+R on Mac) → Run a recipe
Ctrl+S (or Cmd+S on Mac) → Save code changes
Click Run to execute the code and create a dataset. If needed, you can stop the recipe at any time by clicking the Stop button.
After running the code successfully, the generated dataset gets added to the canvas.
Checkpoints allow you to save your code at key stages, preserving progress and offering flexibility during development. You can tweak your code, create new checkpoint versions, and switch between them effortlessly. Once you're satisfied with a version, save it to the Current tab and run the recipe.
This feature is exclusively available in the Code Recipe under the Code tab. You can create up to five checkpoints and seamlessly navigate between them as needed.
Open the Code Recipe:
Click the plus icon on the canvas and select API Connector from the list. This opens the Code tab.
Write and Save Code:
Write your code in the Code tab and click Save Code CheckPoint to save it as a checkpoint. Once saved, the checkpoint is displayed as a new tab.
To delete a checkpoint, use the Delete Checkpoint option available on the checkpoint tab.
Run Checkpoint Code:
To execute the code saved in a checkpoint, first click Save Code to Current on the respective checkpoint tab.
Open the API Connector:
Click the plus icon on the canvas and select Code Recipe from the list. This opens the Code tab.
Switch Checkpoints:
On the Current tab, click the Save Code CheckPoint drop-down to view all created checkpoints. Select the checkpoint you want to switch to.
To edit a checkpoint, use the Edit option corresponding to it in the drop-down menu.
To delete a checkpoint, use the Delete option next to it in the drop-down menu.
Note:
A maximum of five checkpoints can be created at any given time.
Switching between checkpoints allows you to experiment with different versions of your code without losing progress.
Finalized code must always be saved to the Current tab to run the recipe successfully.
The Code Assist feature in the Code Recipe allows users to interact with an AI-powered assistant to generate and understand code without leaving the platform.
Users can:
Provide a code snippet to receive an explanation.
Enter a prompt to generate new code.
This eliminates the need to switch to external tools like AskAI chat, as users can now use the Ask Code Assistant directly within the platform.
Users can choose from different AI models to generate responses:
GPT-4o
GPT-4 Turbo
GPT-3.5 Mini
Users can switch between these models based on their requirements.
The generated code must be manually copied and pasted into the Code Recipe.
Users can clear conversation history to start fresh. The history clears automatically when the session expires.
Click the plus icon on the canvas and select Code Recipe from the list. This opens the Code tab.
Click Code Assist to open the Code Assist side sheet.
Copy the code snippet from the Current tab and use Ctrl+I (Windows) or Cmd+I (Mac) to paste it into the prompt window.
Enter your query to either:
Get an explanation of the code snippet.
Provide a prompt to generate a new code snippet.
Note: You can switch between GPT-4o, GPT-4 Turbo, or GPT-3.5 Turbo for optimal responses.
Click Generate to obtain the AI-generated response.
Manually copy the generated code and paste it into the Current tab at the appropriate place.
Click Save Code to apply the changes.
Click Clear History to restart the conversation.
Click Close to exit the side sheet.
You can define custom Python libraries within a Code Recipe using the Requirements option. This ensures conflict-free execution by isolating dependencies for each recipe.
Click the plus icon on the canvas and select Code Recipe from the list.
Click Requirements to open the Requirements window.
Enter the required Python libraries.
Click Save.
Note: These libraries take precedence over the environment-level libraries during execution.