Step-by-Step Guides

Building chatbots with System Message

Building chatbots
with System
Message

Building chatbots with System Message

Overview

In this guide, we will modify the "Basic Chat with Prompt and History" example, integrating the ChatPromptTemplate with the SystemMessagePromptTemplate and HumanMessagePromptTemplate components. By following these steps, you'll be able to build a personalized chatbot that can interpret and respond based on user-defined System messages.

Interactive Guide

Step-by-Step Instructions

  1. Navigate to the "Community Examples" section.

  2. Locate the "Basic Chat with Prompt and History" example, and click on "Fork Example".

  3. Once in the editor, find the "PromptTemplate" component and remove it.

  4. Now, add these three components: ChatPromptTemplate, SystemMessagePromptTemplate, and HumanMessagePromptTemplate.

Note

Remember to set the model to gpt-3.5-turbo-0613 or the most up-to-date version. The latest models have improved capabilities to comprehend System messages.

  1. Open the "Prompt" field on the SystemMessagePromptTemplate component.

  2. Enter the text: You are a {role} that {behavior}.

  3. Save your changes by clicking on "Check & Save".

  4. Define the 'role' variable by typing "obedient assistant".

  5. Next, navigate to the HumanMessagePromptTemplate and open the "Prompt" field.

  6. Here, simply enter {input}.

  7. Save these changes by clicking on "Check & Save".

  8. Now, you should see your flow populated with the variables you defined.

  9. In the Memory component, set the 'Input Key' to "input".

  1. Open the "Prompt" field on the SystemMessagePromptTemplate component.

  2. Enter the text: You are a {role} that {behavior}.

  3. Save your changes by clicking on "Check & Save".

  4. Define the 'role' variable by typing "obedient assistant".

  5. Next, navigate to the HumanMessagePromptTemplate and open the "Prompt" field.

  6. Here, simply enter {input}.

  7. Save these changes by clicking on "Check & Save".

  8. Now, you should see your flow populated with the variables you defined.

  9. In the Memory component, set the 'Input Key' to "input".

Tip

When using a Memory component with multiple variables, it's crucial to specify which variable should be used to generate the conversation history.

  1. Click on the "Build" button to implement your changes.

  2. Open the chat interface to test your modifications.

  3. You should now be able to see and use the defined variables in the chat interface.

  4. Click on 'role' to examine the variable you established in the canvas.

  5. Now, let's define the 'behavior' variable.

  6. Enter the text: "writes the word 'Langflow' at the end of every sentence."

  7. Test your chatbot by typing "How can you help me?"

  8. If everything was set up correctly, your chatbot should respond appropriately, following the defined behavior.

  9. Congratulations! You have successfully customized and built your chatbot.

By following these instructions, you have created a dynamic chatbot capable of understanding and responding based on custom system messages, enhancing the user experience and interaction. Enjoy your personalized assistant!

Getting Started

👋 Welcome to Langflow
📦 How to install?
🤗 HuggingFace Spaces
🎨 Creating Flows

Guidelines

Sign up and Sign in
API Keys
Assynchronous Processing
Component
Features
Collection
Prompt Customization
Chat Interface
Chat Widget
Custom Components

Step-by-Step Guides

Async API
Integrating documents with prompt variables
Building chatbots with System Message
Integrating Langfuse with Langflow

Examples

FlowRunner Component
Conversation Chain
Buffer Memory
MidJourney Prompt Chain
CSV Loader
Serp API Tool
Multiple Vector Stores
Python Function
📚 How to Upload Examples?

Deployment

Deploy on Google Cloud Platform

Contributing

How to contribute?
GitHub Issues
Community

Search Docs…

Search Docs…