TokenLab

Frameworks & Platforms

Ragas

Evaluate LLM apps with Ragas and TokenLab

Overview

Ragas can evaluate TokenLab-backed applications by passing an OpenAI-compatible AsyncOpenAI client into llm_factory.

Installation

pip install "ragas==0.4.3" "langchain-community<0.4" openai

Environment

export TOKENLAB_API_KEY="sk-your-tokenlab-key"

Example Evaluator

import os

from openai import AsyncOpenAI
from ragas.llms import llm_factory
from ragas.metrics import DiscreteMetric

client = AsyncOpenAI(
    api_key=os.environ["TOKENLAB_API_KEY"],
    base_url="https://api.tokenlab.sh/v1",
)
llm = llm_factory("claude-sonnet-5", client=client)

metric = DiscreteMetric(
    name="summary_accuracy",
    allowed_values=["accurate", "inaccurate"],
    prompt="Evaluate whether the response is accurate. Answer only accurate or inaccurate.\n\nResponse: {response}",
)

Use llm in Ragas metrics and testsets the same way you would use an OpenAI SDK-backed model.

Endpoint Notes

This Ragas setup uses the OpenAI SDK. Responses, Anthropic Messages, and Gemini require an evaluation client that supports the corresponding format.

On this page