07. Custom LLM evaluation

Rate with custom Evaluator

You can configure custom LLM evaluators or Heuristic evaluators.

Copy

# installation
# !pip install -U langsmith langchain-teddynote

Copy

# Configuration file for managing API KEY as environment variable
from dotenv import load_dotenv

# Load API KEY information
load_dotenv()

Copy

 True 

Copy

# 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")

Copy

Define functions for RAG performance testing

We will create a RAG system to use for testing.

Copy

Copy

ask_question Generate a function with the name Lee. Input inputs Ra receives a dickery, answer Ra returns the dictionary.

Copy

Custom Evaluator Configuration

You can keep the input parameters and return value format of the custom functions below.

Custom function

  • Input Run and Example To receive and output dict Returns.

  • 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.

Copy

Copy

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.

Copy

Next, create a custom LLM evaluator.

At this time, the evaluation prompt is freely adjustable.

Copy

Copy

Copy

Previously created context_answer_rag_answer Answers generated using functions, context custom_llm_evaluator Enter in to proceed with the evaluation.

Copy

Copy

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.

Copy

Proceed with the evaluation.

Copy

Last updated