@arizeai/phoenix-client
Version:
A client for the Phoenix API
49 lines • 1.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.addDocumentAnnotation = addDocumentAnnotation;
const client_1 = require("../client");
const types_1 = require("./types");
/**
* Add an annotation to a document within a span.
*
* The annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, explanation, and metadata.
* At least one of label, score, or explanation must be provided.
*
* @param params - The parameters to add a document annotation
* @returns The ID of the created annotation
*
* @example
* ```ts
* const result = await addDocumentAnnotation({
* documentAnnotation: {
* spanId: "123abc",
* documentPosition: 0,
* name: "relevance_score",
* label: "relevant",
* score: 0.95,
* annotatorKind: "LLM",
* explanation: "Document is highly relevant to the query",
* metadata: {
* model: "gpt-4"
* }
* }
* });
* ```
*/
async function addDocumentAnnotation({ client: _client, documentAnnotation, sync = false, }) {
var _a;
const client = _client !== null && _client !== void 0 ? _client : (0, client_1.createClient)();
const { data, error } = await client.POST("/v1/document_annotations", {
params: {
query: { sync },
},
body: {
data: [(0, types_1.toDocumentAnnotationData)(documentAnnotation)],
},
});
if (error) {
throw new Error(`Failed to add document annotation: ${error}`);
}
return ((_a = data === null || data === void 0 ? void 0 : data.data) === null || _a === void 0 ? void 0 : _a[0]) || null;
}
//# sourceMappingURL=addDocumentAnnotation.js.map