UNPKG

@arizeai/phoenix-client

Version:

A client for the Phoenix API

87 lines 2.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getSpanAnnotations = getSpanAnnotations; const client_1 = require("../client"); /** * Get span annotations for a list of span IDs. * * This method allows you to retrieve annotations for specific spans within a project. * You can filter annotations by name and support cursor-based pagination. * * @experimental this function is experimental and may change in the future * * @param params - The parameters to get span annotations * @returns A paginated response containing annotations and optional next cursor * * @example * ```ts * // Get annotations for specific spans * const result = await getSpanAnnotations({ * client, * project: { projectName: "my-project" }, * spanIds: ["span1", "span2", "span3"], * limit: 50 * }); * * // Get specific annotation types * const result = await getSpanAnnotations({ * client, * project: { projectName: "my-project" }, * spanIds: ["span1"], * includeAnnotationNames: ["quality_score", "sentiment"], * limit: 100 * }); * * // Paginate through results * let cursor: string | undefined; * do { * const result = await getSpanAnnotations({ * client, * project: { projectName: "my-project" }, * spanIds: ["span1"], * cursor, * limit: 100 * }); * * // Process annotations * result.annotations.forEach(annotation => { * console.log(`Annotation: ${annotation.name}, Label: ${annotation.result.label}`); * }); * * cursor = result.nextCursor || undefined; * } while (cursor); * ``` */ async function getSpanAnnotations({ client: _client, project, spanIds, includeAnnotationNames, excludeAnnotationNames, cursor, limit = 100, }) { var _a, _b; const client = _client !== null && _client !== void 0 ? _client : (0, client_1.createClient)(); const projectIdentifier = "projectId" in project ? project.projectId : project.projectName; const params = { span_ids: spanIds, limit, }; if (cursor) { params.cursor = cursor; } if (includeAnnotationNames !== undefined) { params.include_annotation_names = includeAnnotationNames; } if (excludeAnnotationNames !== undefined) { params.exclude_annotation_names = excludeAnnotationNames; } const { data, error } = await client.GET("/v1/projects/{project_identifier}/span_annotations", { params: { path: { project_identifier: projectIdentifier, }, query: params, }, }); if (error) throw error; return { annotations: (_a = data === null || data === void 0 ? void 0 : data.data) !== null && _a !== void 0 ? _a : [], nextCursor: (_b = data === null || data === void 0 ? void 0 : data.next_cursor) !== null && _b !== void 0 ? _b : null, }; } //# sourceMappingURL=getSpanAnnotations.js.map