@arizeai/phoenix-client
Version:
A client for the Phoenix API
38 lines • 1.34 kB
JavaScript
/**
* Build and validate annotation result fields
*/
function buildTraceAnnotationResult(annotation) {
const result = {};
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;
}
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 trace annotation");
}
return result;
}
/**
* Convert a TraceAnnotation to the API format
*/
export function toTraceAnnotationData(annotation) {
if (annotation.name.trim() === "note") {
throw new Error('The name "note" is reserved for trace and span notes. Use addTraceNote instead.');
}
const result = buildTraceAnnotationResult(annotation);
return {
trace_id: annotation.traceId.trim(),
name: annotation.name.trim(),
annotator_kind: annotation.annotatorKind ?? "HUMAN",
result,
metadata: annotation.metadata ?? null,
identifier: annotation.identifier?.trim() ?? "",
};
}
//# sourceMappingURL=types.js.map