字串評估
現在要實際評估最終輸出,並與領域專家的標準答案比較。你將使用 LangSmith 的 LangChainStringEvaluator 類別來執行這個字串比對評估。
一個用於字串評估的 prompt_template 已經為你寫好如下:
You are an expert professor specialized in grading students' answers to questions.
You are grading the following question:{query}
Here is the real answer:{answer}
You are grading the following predicted answer:{result}
Respond with CORRECT or INCORRECT:
Grade:
RAG chain 的輸出已儲存在 predicted_answer,而專家的回應則儲存在 ref_answer。
所需的所有類別都已為你匯入。
本練習屬於課程
使用 LangChain 的 Retrieval Augmented Generation(RAG)
練習說明
- 使用提供的
eval_llm與prompt_template建立 LangSmith 的 QA 字串評估器。 - 評估 RAG 的輸出
predicted_answer,並與儲存在ref_answer、針對該query的專家回應進行比較。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create the QA string evaluator
qa_evaluator = ____(
"____",
config={
"llm": ____,
"prompt": ____
}
)
query = "How does RAG improve question answering with LLMs?"
# Evaluate the RAG output by evaluating strings
score = qa_evaluator.evaluator.____(
prediction=____,
reference=____,
input=____
)
print(f"Score: {score}")