@arizeai/phoenix-client
Version:
A client for the Phoenix API
37 lines • 1.31 kB
JavaScript
/**
* 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
*/
export function toSessionAnnotationData(annotation) {
const result = buildSessionAnnotationResult(annotation);
return {
session_id: annotation.sessionId.trim(),
name: annotation.name.trim(),
annotator_kind: annotation.annotatorKind ?? "HUMAN",
result,
metadata: annotation.metadata ?? null,
identifier: annotation.identifier?.trim() ?? "",
};
}
//# sourceMappingURL=types.js.map