Project - Building a RAG Chatbot from Your Website Data using OpenAI and Langchain

19 / 26

Step 5: Defining LLM Prompt - Constructing Prompt Template

Now, as we have defined our system message, let's utilize the Langchain's Prompt Templates. Prompt templates in Langchain allow you to define a general prompt structure with placeholders for specific information. These placeholders are then filled in at runtime with the relevant values for your use case.

INSTRUCTIONS
  1. Importing Libraries:

    from langchain.prompts import (
        SystemMessagePromptTemplate,
        PromptTemplate,
        ChatPromptTemplate,
        HumanMessagePromptTemplate
      )
    
  2. Define a function get_prompt that creates a Langchain Prompt Template:

--

def get_prompt():
    prompt = ChatPromptTemplate(
        input_variables=['context', 'question', 'chat_history', 'organization_name', 'organization_info', 'contact_info'],
        messages=[
            SystemMessagePromptTemplate(
                prompt=PromptTemplate(
                    input_variables=['context', 'chat_history', 'organization_name', 'organization_info', 'contact_info'],
                    template=system_prompt, template_format='f-string',
                    validate_template=True
                ), additional_kwargs={}
            ),
            HumanMessagePromptTemplate(
                prompt=PromptTemplate(
                    input_variables=['question'],
                    template='{question}\nHelpful Answer:', template_format='f-string',
                    validate_template=True
                ), additional_kwargs={}
            )
        ]
    )
    return prompt
See Answer

No hints are availble for this assesment


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...