> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # Confident AI Exporter [Confident AI](https://www.confident-ai.com/) 是一個 LLM Observability 與評估平台,協助團隊在開發與正式環境中建立可靠的 AI 應用程式。 `@mastra/deepeval` 套件會將 Mastra Trace 傳送至 Confident AI,你可以在該平台針對 Trace 執行指標,並持續追蹤品質。這套機制建構於平台背後的開放原始碼評估 SDK [DeepEval](https://www.confident-ai.com/docs) 之上。 ## 安裝 **npm**: ```bash npm install @mastra/deepeval@latest ``` **pnpm**: ```bash pnpm add @mastra/deepeval@latest ``` **Yarn**: ```bash yarn add @mastra/deepeval@latest ``` **Bun**: ```bash bun add @mastra/deepeval@latest ``` ## 設定 ### 必要條件 1. **Confident AI 帳號**:前往 [confident-ai.com](https://www.confident-ai.com/) 註冊 2. **API Key**:在 Confident AI 專案設定中產生 3. **環境變數**:設定你的憑證: ```bash CONFIDENT_API_KEY=confident_proj_xxxxxxxxxxxxx # Optional CONFIDENT_TRACE_ENVIRONMENT=production # Defaults to "development" ``` ### 零設定 設定環境變數後,即可使用不帶任何設定的 Exporter: ```typescript import { Mastra } from '@mastra/core' import { Observability } from '@mastra/observability' import { DeepEvalExporter } from '@mastra/deepeval' export const mastra = new Mastra({ observability: new Observability({ configs: { deepeval: { serviceName: 'my-service', exporters: [new DeepEvalExporter()], }, }, }), }) ``` ### 明確設定 你也可以直接傳入憑證(優先於環境變數): ```typescript import { Mastra } from '@mastra/core' import { Observability } from '@mastra/observability' import { DeepEvalExporter } from '@mastra/deepeval' export const mastra = new Mastra({ observability: new Observability({ configs: { deepeval: { serviceName: 'my-service', exporters: [ new DeepEvalExporter({ apiKey: process.env.CONFIDENT_API_KEY, environment: 'production', }), ], }, }, }), }) ``` ### 指標集合 Confident AI 會使用專案中定義的指標集合評估傳入的 Trace。你可以在 Trace 層級或依 span 類型附加指標集合。Trace 層級指標會針對整個 Trace 執行,而依類型設定的指標則會針對相符的 span 執行。 ```typescript new DeepEvalExporter({ metricCollection: 'trace-metrics', // trace-level llmMetricCollection: 'llm-metrics', // applied to LLM spans agentMetricCollection: 'agent-metrics', // applied to agent spans toolMetricCollectionMap: { search: 'search-tool-metrics', // applied to the "search" tool }, }) ``` ### 完整設定 ```typescript new DeepEvalExporter({ apiKey: process.env.CONFIDENT_API_KEY, environment: 'production', // Default: "development" name: 'my-trace', // Default: the Mastra serviceName tags: ['production'], metadata: { team: 'growth' }, }) ``` ## Span 類型對應 Mastra span 對應至 Confident AI 中顯示的下列 span 類型: | Mastra span 類型 | Confident AI span 類型 | | ---------------------------------------------------------------------- | -------------------- | | `AGENT_RUN`, `WORKFLOW_RUN` | `AGENT` | | `MODEL_GENERATION` | `LLM` | | `TOOL_CALL`, `MCP_TOOL_CALL`, `PROVIDER_TOOL_CALL`, `CLIENT_TOOL_CALL` | `TOOL` | | `RAG_EMBEDDING`, `RAG_VECTOR_OPERATION` | `RETRIEVER` | | 所有其他匯出的 span 類型 | `CUSTOM` | ## 相關內容 - [Tracing 總覽](https://mastra.zisheng.pro/zh-TW/docs/observability/tracing/overview) - [DeepEvalExporter 參考](https://mastra.zisheng.pro/zh-TW/reference/observability/tracing/exporters/confident-ai) - [Confident AI 文件](https://www.confident-ai.com/docs)