@arizeai/phoenix-client 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -1
- package/dist/esm/__generated__/api/v1.d.ts +185 -47
- package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
- package/dist/esm/spans/addDocumentAnnotation.d.ts +45 -0
- package/dist/esm/spans/addDocumentAnnotation.d.ts.map +1 -0
- package/dist/esm/spans/addDocumentAnnotation.js +45 -0
- package/dist/esm/spans/addDocumentAnnotation.js.map +1 -0
- package/dist/esm/spans/addSpanAnnotation.d.ts +8 -2
- package/dist/esm/spans/addSpanAnnotation.d.ts.map +1 -1
- package/dist/esm/spans/addSpanAnnotation.js +5 -5
- package/dist/esm/spans/addSpanAnnotation.js.map +1 -1
- package/dist/esm/spans/index.d.ts +2 -0
- package/dist/esm/spans/index.d.ts.map +1 -1
- package/dist/esm/spans/index.js +2 -0
- package/dist/esm/spans/index.js.map +1 -1
- package/dist/esm/spans/logDocumentAnnotations.d.ts +58 -0
- package/dist/esm/spans/logDocumentAnnotations.d.ts.map +1 -0
- package/dist/esm/spans/logDocumentAnnotations.js +55 -0
- package/dist/esm/spans/logDocumentAnnotations.js.map +1 -0
- package/dist/esm/spans/logSpanAnnotations.d.ts +7 -1
- package/dist/esm/spans/logSpanAnnotations.d.ts.map +1 -1
- package/dist/esm/spans/logSpanAnnotations.js +5 -5
- package/dist/esm/spans/logSpanAnnotations.js.map +1 -1
- package/dist/esm/spans/types.d.ts +48 -0
- package/dist/esm/spans/types.d.ts.map +1 -1
- package/dist/esm/spans/types.js +41 -8
- package/dist/esm/spans/types.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
- package/dist/src/__generated__/api/v1.d.ts +185 -47
- package/dist/src/__generated__/api/v1.d.ts.map +1 -1
- package/dist/src/spans/addDocumentAnnotation.d.ts +45 -0
- package/dist/src/spans/addDocumentAnnotation.d.ts.map +1 -0
- package/dist/src/spans/addDocumentAnnotation.js +49 -0
- package/dist/src/spans/addDocumentAnnotation.js.map +1 -0
- package/dist/src/spans/addSpanAnnotation.d.ts +8 -2
- package/dist/src/spans/addSpanAnnotation.d.ts.map +1 -1
- package/dist/src/spans/addSpanAnnotation.js +6 -6
- package/dist/src/spans/addSpanAnnotation.js.map +1 -1
- package/dist/src/spans/index.d.ts +2 -0
- package/dist/src/spans/index.d.ts.map +1 -1
- package/dist/src/spans/index.js +2 -0
- package/dist/src/spans/index.js.map +1 -1
- package/dist/src/spans/logDocumentAnnotations.d.ts +58 -0
- package/dist/src/spans/logDocumentAnnotations.d.ts.map +1 -0
- package/dist/src/spans/logDocumentAnnotations.js +58 -0
- package/dist/src/spans/logDocumentAnnotations.js.map +1 -0
- package/dist/src/spans/logSpanAnnotations.d.ts +7 -1
- package/dist/src/spans/logSpanAnnotations.d.ts.map +1 -1
- package/dist/src/spans/logSpanAnnotations.js +5 -6
- package/dist/src/spans/logSpanAnnotations.js.map +1 -1
- package/dist/src/spans/types.d.ts +48 -0
- package/dist/src/spans/types.d.ts.map +1 -1
- package/dist/src/spans/types.js +45 -10
- package/dist/src/spans/types.js.map +1 -1
- package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
- package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/__generated__/api/v1.d.ts +1240 -1238
- package/src/__generated__/api/v1.ts +185 -47
- package/src/spans/addDocumentAnnotation.ts +66 -0
- package/src/spans/addSpanAnnotation.ts +12 -6
- package/src/spans/index.ts +2 -0
- package/src/spans/logDocumentAnnotations.ts +79 -0
- package/src/spans/logSpanAnnotations.ts +11 -5
- package/src/spans/types.ts +112 -8
package/src/spans/types.ts
CHANGED
|
@@ -3,6 +3,9 @@ import { paths } from "../__generated__/api/v1";
|
|
|
3
3
|
type SpanAnnotationData =
|
|
4
4
|
paths["/v1/span_annotations"]["post"]["requestBody"]["content"]["application/json"]["data"][0];
|
|
5
5
|
|
|
6
|
+
type SpanDocumentAnnotationData =
|
|
7
|
+
paths["/v1/document_annotations"]["post"]["requestBody"]["content"]["application/json"]["data"][0];
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
* Parameters for a single span annotation
|
|
8
11
|
*/
|
|
@@ -23,6 +26,10 @@ export interface SpanAnnotation {
|
|
|
23
26
|
* The score assigned by the annotation
|
|
24
27
|
*/
|
|
25
28
|
score?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Explanation of the annotation result
|
|
31
|
+
*/
|
|
32
|
+
explanation?: string;
|
|
26
33
|
/**
|
|
27
34
|
* The identifier of the annotation. If provided, the annotation will be updated if it already exists.
|
|
28
35
|
*/
|
|
@@ -39,22 +46,119 @@ export interface SpanAnnotation {
|
|
|
39
46
|
annotatorKind?: SpanAnnotationData["annotator_kind"];
|
|
40
47
|
}
|
|
41
48
|
|
|
49
|
+
/**
|
|
50
|
+
* Parameters for a single document annotation
|
|
51
|
+
*/
|
|
52
|
+
export interface DocumentAnnotation {
|
|
53
|
+
/**
|
|
54
|
+
* The OpenTelemetry Span ID (hex format without 0x prefix)
|
|
55
|
+
*/
|
|
56
|
+
spanId: string;
|
|
57
|
+
/**
|
|
58
|
+
* The 0-based index of the document within the span
|
|
59
|
+
*/
|
|
60
|
+
documentPosition: number;
|
|
61
|
+
/**
|
|
62
|
+
* The name of the annotation
|
|
63
|
+
*/
|
|
64
|
+
name: string;
|
|
65
|
+
/**
|
|
66
|
+
* The label assigned by the annotation
|
|
67
|
+
*/
|
|
68
|
+
label?: string;
|
|
69
|
+
/**
|
|
70
|
+
* The score assigned by the annotation
|
|
71
|
+
*/
|
|
72
|
+
score?: number;
|
|
73
|
+
/**
|
|
74
|
+
* Explanation of the annotation result
|
|
75
|
+
*/
|
|
76
|
+
explanation?: string;
|
|
77
|
+
/**
|
|
78
|
+
* Metadata for the annotation
|
|
79
|
+
*/
|
|
80
|
+
metadata?: Record<string, unknown>;
|
|
81
|
+
/**
|
|
82
|
+
* The kind of annotator used for the annotation
|
|
83
|
+
* Can be "HUMAN", "LLM", or "CODE"
|
|
84
|
+
* @default "HUMAN"
|
|
85
|
+
*/
|
|
86
|
+
annotatorKind?: SpanDocumentAnnotationData["annotator_kind"];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
type AnnotationResult = {
|
|
90
|
+
label?: string | null;
|
|
91
|
+
score?: number | null;
|
|
92
|
+
explanation?: string | null;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Build and validate annotation result fields
|
|
97
|
+
*/
|
|
98
|
+
function buildAnnotationResult(
|
|
99
|
+
annotation: Pick<
|
|
100
|
+
SpanAnnotation | DocumentAnnotation,
|
|
101
|
+
"label" | "score" | "explanation"
|
|
102
|
+
>,
|
|
103
|
+
annotationType: "span" | "document"
|
|
104
|
+
): AnnotationResult {
|
|
105
|
+
const result: AnnotationResult = {};
|
|
106
|
+
|
|
107
|
+
// Build result with trimming for string fields
|
|
108
|
+
if (annotation.label !== undefined) {
|
|
109
|
+
result.label = annotation.label.trim() || null;
|
|
110
|
+
}
|
|
111
|
+
if (annotation.score !== undefined) {
|
|
112
|
+
result.score = annotation.score;
|
|
113
|
+
}
|
|
114
|
+
if (annotation.explanation !== undefined) {
|
|
115
|
+
result.explanation = annotation.explanation.trim() || null;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Validate that at least one result field is provided
|
|
119
|
+
const hasValidResult =
|
|
120
|
+
result.label || result.score !== undefined || result.explanation;
|
|
121
|
+
if (!hasValidResult) {
|
|
122
|
+
throw new Error(
|
|
123
|
+
`At least one of label, score, or explanation must be provided for ${annotationType} annotation`
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return result;
|
|
128
|
+
}
|
|
129
|
+
|
|
42
130
|
/**
|
|
43
131
|
* Convert a SpanAnnotation to the API format
|
|
44
132
|
*/
|
|
45
133
|
export function toSpanAnnotationData(
|
|
46
134
|
annotation: SpanAnnotation
|
|
47
135
|
): SpanAnnotationData {
|
|
136
|
+
const result = buildAnnotationResult(annotation, "span");
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
span_id: annotation.spanId.trim(),
|
|
140
|
+
name: annotation.name.trim(),
|
|
141
|
+
annotator_kind: annotation.annotatorKind ?? "HUMAN",
|
|
142
|
+
result,
|
|
143
|
+
metadata: annotation.metadata ?? null,
|
|
144
|
+
identifier: annotation.identifier?.trim() ?? "",
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Convert a DocumentAnnotation to the API format
|
|
150
|
+
*/
|
|
151
|
+
export function toDocumentAnnotationData(
|
|
152
|
+
annotation: DocumentAnnotation
|
|
153
|
+
): SpanDocumentAnnotationData {
|
|
154
|
+
const result = buildAnnotationResult(annotation, "document");
|
|
155
|
+
|
|
48
156
|
return {
|
|
49
|
-
span_id: annotation.spanId,
|
|
50
|
-
|
|
157
|
+
span_id: annotation.spanId.trim(),
|
|
158
|
+
document_position: annotation.documentPosition,
|
|
159
|
+
name: annotation.name.trim(),
|
|
51
160
|
annotator_kind: annotation.annotatorKind ?? "HUMAN",
|
|
52
|
-
result
|
|
53
|
-
label: annotation.label ?? null,
|
|
54
|
-
score: annotation.score ?? null,
|
|
55
|
-
explanation: null,
|
|
56
|
-
},
|
|
161
|
+
result,
|
|
57
162
|
metadata: annotation.metadata ?? null,
|
|
58
|
-
identifier: annotation.identifier ?? "",
|
|
59
163
|
};
|
|
60
164
|
}
|