Valutazione di stringhe
È il momento di valutare davvero l'output finale confrontandolo con una risposta scritta da un esperto della materia. Userai la classe LangChainStringEvaluator di LangSmith per eseguire questa valutazione tramite confronto tra stringhe.
Un prompt_template per la valutazione delle stringhe è già stato preparato per te come:
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:
L'output della RAG chain è salvato come predicted_answer e la risposta dell'esperto è salvata come ref_answer.
Tutte le classi necessarie sono già state importate per te.
Questo esercizio fa parte del corso
Retrieval Augmented Generation (RAG) con LangChain
Istruzioni dell'esercizio
- Crea il valutatore di stringhe QA di LangSmith usando
eval_llme ilprompt_templateforniti. - Valuta l'output della RAG,
predicted_answer, confrontandolo con la risposta dell'esperto allaquery, che è salvata comeref_answer.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# 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}")