UNPKG

@arizeai/phoenix-client

Version:

A client for the Phoenix API

41 lines 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.toSessionAnnotationData = toSessionAnnotationData; /** * Build and validate annotation result fields */ function buildSessionAnnotationResult(annotation) { const result = {}; // Build result with trimming for string fields if (annotation.label !== undefined) { result.label = annotation.label.trim() || null; } if (annotation.score !== undefined) { result.score = annotation.score; } if (annotation.explanation !== undefined) { result.explanation = annotation.explanation.trim() || null; } // Validate that at least one result field is provided const hasValidResult = result.label || result.score !== undefined || result.explanation; if (!hasValidResult) { throw new Error(`At least one of label, score, or explanation must be provided for session annotation`); } return result; } /** * Convert a SessionAnnotation to the API format */ function toSessionAnnotationData(annotation) { var _a, _b, _c, _d; const result = buildSessionAnnotationResult(annotation); return { session_id: annotation.sessionId.trim(), name: annotation.name.trim(), annotator_kind: (_a = annotation.annotatorKind) !== null && _a !== void 0 ? _a : "HUMAN", result, metadata: (_b = annotation.metadata) !== null && _b !== void 0 ? _b : null, identifier: (_d = (_c = annotation.identifier) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : "", }; } //# sourceMappingURL=types.js.map