@dynatrace-oss/dt-eval-lib

中文文档
0.0.23-alpha发布于 2026/11/10Apache-2.0TypeScriptES Module零依赖构建来源已验证近 30 天下载 1.2万

Minimal TypeScript library for running LLM-as-a-judge evaluations

原始使用文档
文档目录12 节
  1. Install
  2. Build
  3. Test
  4. Quick Usage
  5. Available Metrics
  6. Providers
  7. Environment Variables
  8. Google Gemini Enterprise Platform (Vertex AI) Setup
  9. Azure OpenAI Setup
  10. Amazon Bedrock Setup
  11. Metric Identification
  12. Configuration

dt-eval-lib

npm version npm downloads Build License

Minimal TypeScript library for running LLM-as-a-judge evaluations.

Install

npm install @dynatrace-oss/dt-eval-lib

Then install the peer dependency for your provider:

ProviderPeer dependency
openai, azure-openainpm install openai
anthropicnpm install @anthropic-ai/sdk
vertex, gemininpm install @google/genai
bedrocknpm install @aws-sdk/client-bedrock-runtime

Build

npm run build

Test

npm test

Quick Usage

import { evaluate, BuiltInMetric } from "@dynatrace-oss/dt-eval-lib";

const result = await evaluate(
  BuiltInMetric.Toxicity,
  {
    input: "Tell me a joke",
    output: "Why did the chicken cross the road? To get to the other side!",
  },
  {
    provider: {
      provider: "openai",
      apiKey: "sk-...",
    },
  },
);

console.log(result.score);       // { value: 1, label: "pass" }
console.log(result.explanation); // { summary: "...", reasoning: "..." }

Available Metrics

All built-in metrics return a continuous score in [0.0, 1.0]. The score is labeled "pass" when value >= threshold and "fail" otherwise. Every built-in metric defaults to threshold: 0.5 — override it per-call via EvalConfig.scoring.thresholdOverride. Source of truth: src/prompts/catalog-data.ts.

MetricEnumScore rangeFields used from EvalInput
answer-completenessBuiltInMetric.AnswerCompleteness0.0 – 1.0input, output
biasBuiltInMetric.Bias0.0 – 1.0input, output
concisenessBuiltInMetric.Conciseness0.0 – 1.0input, output
context-relevanceBuiltInMetric.ContextRelevance0.0 – 1.0input
factual-accuracyBuiltInMetric.FactualAccuracy0.0 – 1.0input, output
faithfulnessBuiltInMetric.Faithfulness0.0 – 1.0input, output
fluencyBuiltInMetric.Fluency0.0 – 1.0input, output
hallucinationBuiltInMetric.Hallucination0.0 – 1.0input, output
output-prompt-injectionBuiltInMetric.OutputPromptInjection0.0 – 1.0output
pii-leakageBuiltInMetric.PiiLeakage0.0 – 1.0input, output
prompt-injectionBuiltInMetric.PromptInjection0.0 – 1.0input
relevanceBuiltInMetric.Relevance0.0 – 1.0input, output
summarization-qualityBuiltInMetric.SummarizationQuality0.0 – 1.0input, output
toxicityBuiltInMetric.Toxicity0.0 – 1.0output
user-frustrationBuiltInMetric.UserFrustration0.0 – 1.0input

Note: The "Fields used" column lists which fields the metric prompt actually reads. EvalInput.output is required at the TypeScript type level for all calls — pass output: "" for metrics that only use input.

Providers

Supports OpenAI, Anthropic, Azure OpenAI, Google Gemini Enterprise Platform (Vertex AI), and Amazon Bedrock. Configure via explicit options in code or environment variables.

Environment Variables

# OpenAI
OPENAI_API_KEY=sk-...
OPENAI_BASE_URL=https://your-proxy.example.com/v1  # optional

# Anthropic
ANTHROPIC_API_KEY=sk-ant-...
ANTHROPIC_BASE_URL=https://your-proxy.example.com  # optional

# Azure OpenAI (all three required)
AZURE_OPENAI_API_KEY=...
AZURE_OPENAI_ENDPOINT=https://<resource>.openai.azure.com
AZURE_OPENAI_API_VERSION=2024-02-01

# Google Gemini Enterprise Platform (Vertex AI) — ADC path (no API key needed)
GOOGLE_CLOUD_PROJECT=my-gcp-project
GOOGLE_CLOUD_LOCATION=us-central1  # optional, defaults to "global"

# Google Gemini Enterprise Platform (Vertex AI) — API key path
GOOGLE_API_KEY=AIza...

# Amazon Bedrock — static credentials (optional if using IAM roles / SSO)
AWS_ACCESS_KEY_ID=...
AWS_SECRET_ACCESS_KEY=...
AWS_DEFAULT_REGION=us-east-1  # optional, defaults to "us-east-1"

Config is resolved in this order for each option:

  1. Explicit value in provider options
  2. Environment variable

Google Gemini Enterprise Platform (Vertex AI) Setup

Use Application Default Credentials (ADC) with provider ID vertex when running on GKE or Cloud Run with Workload Identity, or pass apiKey with provider ID gemini for key-based auth.

Azure OpenAI Setup

All four fields are required — model is your Azure deployment name, which is user-defined and has no default.

await evaluate(BuiltInMetric.Toxicity, input, {
  provider: {
    provider: "azure-openai",
    apiKey: "...",                                    // or AZURE_OPENAI_API_KEY
    baseUrl: "https://<resource>.openai.azure.com",  // or AZURE_OPENAI_ENDPOINT
    apiVersion: "2024-02-01",                         // or AZURE_OPENAI_API_VERSION
    model: "my-gpt4-deployment",                      // your deployment name
  },
});

Amazon Bedrock Setup

Uses the AWS SDK credential chain — IAM roles, SSO, and AWS_PROFILE are all resolved automatically. Static credentials are only needed if you can't use role-based auth.

Note: Google provider IDs vertex and gemini both use the @google/genai SDK; azure-openai and openai both use the openai SDK.

Metric Identification

Metrics are identified by the BuiltInMetric enum. You can also pass a custom PromptDefinition object directly:

import { evaluate, BuiltInMetric } from "@dynatrace-oss/dt-eval-lib";

await evaluate(BuiltInMetric.Toxicity, input, config);   // built-in metric via enum
await evaluate(myCustomPrompt, input, config);             // custom PromptDefinition object

Use listPrompts() and getPrompt() to discover available metrics:

import { listPrompts, getPrompt, BuiltInMetric } from "@dynatrace-oss/dt-eval-lib";

const all = listPrompts();                        // all 15 built-in metrics
const tox = getPrompt(BuiltInMetric.Toxicity);    // single metric by ID

Configuration

import type { EvalConfig, EvalInput } from "@dynatrace-oss/dt-eval-lib";

// What you pass to evaluate()
const input: EvalInput = {
  input: "What is the capital of France?",    // required — the user query
  output: "The capital of France is Paris.",  // required — the LLM response to evaluate
  context: "...",                              // optional — retrieved documents (RAG)
  expectedOutput: "...",                       // optional — reference answer
};

// How to run the evaluation
const config: EvalConfig = {
  provider: {
    provider: "openai",  // "openai" | "anthropic" | "azure-openai" | "vertex" | "gemini" | "bedrock"
    apiKey: "sk-...",    // optional if env var is set
    baseUrl: "https://", // optional — openai and anthropic only
    model: "...",        // optional — see src/engine/providers/index.ts for per-provider defaults
    timeout: 30000,      // optional — request timeout in ms (default: 30000)
    maxRetries: 2,       // optional — retries on transient errors (default: 2)
  },
  scoring: {
    thresholdOverride: 0.8, // optional — override the metric's pass threshold (default: 0.5)
  },
};

版本与发布记录

@dynatrace-oss/dt-eval-lib 共发布 15 个版本,首次发布于 2026/04/16;过去 12 个月发布了 15 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.23-alphalatest2026/11/103 天前
0.0.22-alpha2026/11/0211 天前
0.0.21-alpha2026/10/2321 天前
0.0.20-alpha2026/10/121 个月前
0.0.19-alpha2026/09/012 个月前
0.0.18-alpha2026/09/012 个月前

其他发布通道:alpha1 → 0.0.1-alpha1,alpha → 0.0.13-alpha。

关于 @dynatrace-oss/dt-eval-lib 的常见问题

@dynatrace-oss/dt-eval-lib 是什么?

Minimal TypeScript library for running LLM-as-a-judge evaluations

如何安装 @dynatrace-oss/dt-eval-lib?

在项目目录运行 npm install @dynatrace-oss/dt-eval-lib,或使用 pnpm add / yarn add / bun add。

@dynatrace-oss/dt-eval-lib 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dynatrace-oss/dt-eval-lib 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dynatrace-oss/dt-eval-lib 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^22.23.4 || ^24.22.1 || >=26.12.1。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dynatrace-oss/dt-eval-lib 可以商用吗?

@dynatrace-oss/dt-eval-lib 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dynatrace-oss/dt-eval-lib 的下载量有多少?

根据 npm 官方下载统计,@dynatrace-oss/dt-eval-lib 在 2026/10/13 – 2026/11/11 这 30 天内被下载 12,102 次,日均约 403 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dynatrace-oss/dt-eval-lib 还在维护吗?

最新版本 0.0.23-alpha 发布于 2026/11/10(3 天前);至今共发布 15 个版本,其中过去 12 个月发布了 15 个;首次发布于 2026/04/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。