UNPKG

@arizeai/phoenix-client

Version:

A client for the Phoenix API

53 lines 1.55 kB
import { createClient } from "../client.js"; import { toSpanAnnotationData } from "./types.js"; /** * Log multiple span annotations in a single request. * * Each annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, and metadata. * If an identifier is provided and an annotation with that identifier already exists, it will be updated. * * @param params - The parameters to log span annotations * @returns The IDs of the created or updated annotations * * @example * ```ts * const results = await logSpanAnnotations({ * spanAnnotations: [ * { * spanId: "123abc", * name: "quality_score", * label: "good", * score: 0.95, * annotatorKind: "LLM", * identifier: "custom_id_123", * metadata: { * model: "gpt-4" * } * }, * { * spanId: "456def", * name: "sentiment", * label: "positive", * score: 0.8, * annotatorKind: "CODE" * } * ] * }); * ``` */ export async function logSpanAnnotations({ client: _client, spanAnnotations, sync = false, }) { const client = _client ?? createClient(); const { data, error } = await client.POST("/v1/span_annotations", { params: { query: { sync }, }, body: { data: spanAnnotations.map(toSpanAnnotationData), }, }); if (error) { throw new Error(`Failed to log span annotations: ${error}`); } return data?.data || []; } //# sourceMappingURL=logSpanAnnotations.js.map