07. Custom LLM evaluation
Rate with custom Evaluator
You can configure custom LLM evaluators or Heuristic evaluators.
# installation
# !pip install -U langsmith langchain-teddynote# Configuration file for managing API KEY as environment variable
from dotenv import load_dotenv
# Load API KEY information
load_dotenv() True # LangSmith set up tracking. https://smith.langchain.com
# !pip install -qU langchain-teddynote
from langchain_teddynote import logging
# Enter a project name.
logging.langsmith("CH16-Evaluations") Start tracking LangSmith.
[Project name]
CH16-Evaluations Define functions for RAG performance testing
We will create a RAG system to use for testing.
ask_question Generate a function with the name Lee. Input inputs Ra receives a dickery, answer Ra returns the dictionary.
Custom Evaluator Configuration
You can keep the input parameters and return value format of the custom functions below.
Custom function
Input
RunandExampleTo receive and outputdictReturns.Return value
{"key": "score_name", "score": score}It is organized in format. Below we have defined a simple example function. Returns a random score between 1~10 regardless of the answer.

Custom LLM-as-Judge
This time, we will create an LLM Chain and use it as an evaluator.
first, context , answer , question Defines the function that returns.
Next, create a custom LLM evaluator.
At this time, the evaluation prompt is freely adjustable.
Previously created context_answer_rag_answer Answers generated using functions, context custom_llm_evaluator Enter in to proceed with the evaluation.
custom_evaluator Define functions.
run.outputs: Get the answer, context, question created by the RAG chain.example.outputs: Get the correct answer from the dataset.
Proceed with the evaluation.

Last updated