开始使用免费开始使用

字符串评估

现在是时候通过与领域专家撰写的答案对比,认真评估最终输出了。您将使用 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 链的输出已存为 predicted_answer,专家的参考答案已存为 ref_answer

所有必要的类均已为您导入。

本练习是课程的一部分

使用 LangChain 的 Retrieval Augmented Generation (RAG)

查看课程

练习说明

  • 使用提供的 eval_llmprompt_template 创建 LangSmith 的 QA 字符串评估器。
  • 评估 RAG 输出 predicted_answer,方法是将其与针对 query 的专家回答进行比较,专家回答已存为 ref_answer

交互式实操练习

通过完成这段示例代码来试试这个练习。

# 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}")
编辑并运行代码