构建检索提示模板
现在您的文档已被写入向量数据库并可供检索,您需要设计一个聊天提示模板,将检索到的文档片段与用户输入的问题结合起来。
提示的一般结构已提供;您的目标是将正确的输入变量占位符插入 message 字符串中,并将该字符串转换为聊天提示模板。
本练习是课程的一部分
使用 LangChain 开发 LLM 应用
练习说明
- 补全 message 字符串,添加用于动态插入检索文档的
context和用户输入问题question的占位符。 - 使用带有 "human" 角色的
.from_messages()方法,从message创建一个聊天提示模板。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Add placeholders to the message string
message = """
Answer the following question using the context provided:
Context:
____
Question:
____
Answer:
"""
# Create a chat prompt template from the message string
prompt_template = ChatPromptTemplate.from_messages([("____", ____)])