문자열 평가
이제 주제 전문가가 작성한 정답과 비교해 최종 출력을 제대로 평가해 볼 차례예요. 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을 활용한 RAG(검색 증강 생성)
연습 안내
- 제공된
eval_llm과prompt_template을 사용해 LangSmith QA 문자열 평가기를 생성하세요. query에 대한 전문가의 응답(ref_answer)과 비교하여 RAG 출력인predicted_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}")