Skip to main content
Morph makes it easy to create AI applications that use LLM to generate code and perform execution results. In this tutorial, you will create an application that automatically generates Python code in response to user input and displays the results of the visualisation in real-time.

Prerequisites

Please install pageckages in advance by the following command.
Obtain the OpenAI API key in advance from the OpenAI dashboard and save it in an .env file.
.env

Output

chat_sidebyside

Tutorial

By specifying layout="side-by-side" in the <LLM /> component, you can generate code based on user input and display the results in real-time. Furthermore, the code generation and execution are handled within a Python function using the text_to_plotly function, which covers everything from visualization to executing the code.
The text_to_plotly function takes a user prompt and a DataFrame as arguments to generate and execute code that performs data analysis using Plotly, according to the user’s request. Additionally, the side-by-side layout of the <LLM /> component allows the HTML passed as the second argument to the create_chunk function to be displayed next to the chat UI, enabling real-time display.