> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # Confident AI exporter [Confident AI](https://www.confident-ai.com/) 是一個 LLM 可觀測性及評估平台,協助團隊在開發及生產環境中建立可靠的 AI 應用程式。 `@mastra/deepeval` 依賴套件會將你的 Mastra Trace 傳送至 Confident AI,讓你可以對其執行指標評估,並持續追蹤品質。它建基於平台背後的開源評估 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 金鑰**:在你的 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` | ## 相關內容 - [Trace 概覽](https://mastra.zisheng.pro/zh-HK/docs/observability/tracing/overview) - [DeepEvalExporter 參考資料](https://mastra.zisheng.pro/zh-HK/reference/observability/tracing/exporters/confident-ai) - [Confident AI 文件](https://www.confident-ai.com/docs)