建立 Cypher 的 few-shot 提示詞
最後一個用來提升 Cypher 產生可靠度的技巧是提供「few-shot 提示詞」。few-shot 提示詞能在不必用大量範例資料集微調模型的情況下,引導模型更接近你要的輸出。
這個情境已經準備好一組量身打造的範例,儲存在 examples。你可以在 shell 中印出來查看內容。你會用這些範例來為 Cypher 產生流程建立一個 few-shot 提示詞。你先前建立的圖仍可使用,變數為 graph。
本練習屬於課程
使用 LangChain 的 Retrieval Augmented Generation(RAG)
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create an example prompt template
example_prompt = ____(
"User input: {question}\nCypher query: {query}"
)
# Create the few-shot prompt template
cypher_prompt = ____(
examples=____,
example_prompt=____,
prefix="You are a Neo4j expert. Given an input question, create a syntactically correct Cypher query to run.\n\nHere is the schema information\n{schema}.\n\nBelow are a number of examples of questions and their corresponding Cypher queries.",
suffix="User input: {question}\nCypher query: ",
input_variables=["____"]
)