Building Chatbots involves writing a lot of code and for different application, we have to build different chatbots but a Large Language Model(LLM) help us build a custom chatbot using Prompt Engineering. ChatGPT is a generalized conversational interface where the model is being trained on huge data. But sometimes organizations need to build a specific conversational interface just for their application and here we use Prompt Engineering. We can build different types of chatbots like AI customer agents, AI order takers for restaurants, AI clinic assistants, AI lawyer assistants etc.
The components of OpenAIs ChatGPT consists of a series of messages as input and a model-generated output. A general workflow for any chatbot is :
System message -> Assistant message <=> User message
1) System message: For any chatbot, a system message is a message which defines the behavior and persona of the chatbot. It is high-level instruction for the conversation. It is defined once and the chatbot(assistant) has to obey the definition provided as a system message. For ChatGPT we cannot see a system message since it is already defined by the LLM. But for any custom chatbot, we will define a system message in which we tell the exact role of the chatbot.
2) User message: This is the message which user gives to an assistant i.e. the chatbot.
3) Assistant message: It is the response to the user's message. The assistant here is the actual chatbot or the chat model e.g. chatGPT user interface.
We use a different method known as 'get_completion_from_messages' where the 'message' parameter is a list of dictionaries defining role and content.
As we can see here that in the messages list, we have two dictionaries. The role of the system defines the chatbot. The user message provides the query.
Each conversation with a language model is a standalone interaction which means that we must provide all relevant messages for the model to draw from in the current conversation. If we want the model to draw from earlier parts of the conversation, we must provide the earlier exchanges in the input to the model. This is called the context.
As mentioned above, the first prompt defines the name, the second prompt asks for the name but the chatbot has no context so it doesn't know the name and the third prompt has the context so it successfully remembers the name.
Now we will build a custom chatbot named as FIRbot which registers the First Investigation Report of a victim.
The 'collect_messages' method creates a dictionary for a user, calls the 'get_completion_from_messages' method, creates a dictionary for an assistant and appends it in the panel.
Output
Thus we have built an AI chatbot that registers the first investigation report of the victim and it can be used at police stations.