Create a chat app
Morph makes it easy to create chat apps that utilise the LLM API and share them with your team.
In this tutorial, you will create a chat app using Morph’s LLM components and OpenAI’s API.
Prerequisites
Obtain the OpenAI API key in advance from the OpenAI dashboard and save it in an .env
file.
If you are using a cloud environment, set this as an environment variable in the “Data” tab.
Output
Tutorial
Create a chat app using the <LLM />
component and the LLM API.
Implement the chat app logic in the Python function and use the create_chunk
function to stream the chat logs, allowing the <LLM />
component to automatically display the streaming results.
Implement the logic to answer user questions using the OpenAI SDK.
The function specified in the postData
attribute of the <LLM />
component takes prompt
and thread_id
as arguments.
- prompt: The prompt entered by the user
- thread_id: The ID of the chat thread. A new ID is issued when a new thread is opened.