Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left
Apply NowLogin using Social Account
     Continue with GoogleLogin using your credentials
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.
Importing Libraries:
from langchain.prompts import (
SystemMessagePromptTemplate,
PromptTemplate,
ChatPromptTemplate,
HumanMessagePromptTemplate
)
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
Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
No hints are availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here
Loading comments...