建立檢索提示模板
現在你的文件已經匯入向量資料庫並可供檢索,你需要設計一個對話提示模板,將取回的文件片段與使用者輸入的問題結合。
提示的一般結構已經提供;你的目標是把正確的輸入變數佔位符插入到 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([("____", ____)])