> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Ragas

> 使用 Ragas 和 TokenLab 評估 LLM 應用程式

## 概覽

Ragas 可以透過將與 OpenAI 相容的 `AsyncOpenAI` 客戶端傳入 `llm_factory`，來評估由 TokenLab 支援的應用程式。

<Note>
  **類型**: 評估框架

  **主要路徑**: 與 OpenAI 相容的 Chat Completions

  **支援信心**: 支援與 OpenAI 相容的路徑
</Note>

## 環境設定

```bash theme={null}
export TOKENLAB_API_KEY="sk-your-tokenlab-key"
```

## 評估器範例

```python theme={null}
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}",
)
```

在 Ragas 指標 (metrics) 和測試集 (testsets) 中使用 `llm` 的方式，與使用 OpenAI SDK 支援的模型相同。

## 端點注意事項

Ragas 在此處使用 OpenAI SDK 客戶端路徑。若要使用原生 TokenLab Responses、Anthropic Messages 和 Gemini 路由，建議透過直接支援這些請求格式的評估執行器 (evaluation runners) 來進行。
