@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
|
@@ -290,7 +290,10 @@ export interface paths {
|
|
|
290
290
|
path?: never;
|
|
291
291
|
cookie?: never;
|
|
292
292
|
};
|
|
293
|
-
/**
|
|
293
|
+
/**
|
|
294
|
+
* List runs for an experiment
|
|
295
|
+
* @description Retrieve a paginated list of runs for an experiment
|
|
296
|
+
*/
|
|
294
297
|
get: operations["listExperimentRuns"];
|
|
295
298
|
put?: never;
|
|
296
299
|
/** Create run for an experiment */
|
|
@@ -633,6 +636,23 @@ export interface paths {
|
|
|
633
636
|
patch?: never;
|
|
634
637
|
trace?: never;
|
|
635
638
|
};
|
|
639
|
+
"/v1/document_annotations": {
|
|
640
|
+
parameters: {
|
|
641
|
+
query?: never;
|
|
642
|
+
header?: never;
|
|
643
|
+
path?: never;
|
|
644
|
+
cookie?: never;
|
|
645
|
+
};
|
|
646
|
+
get?: never;
|
|
647
|
+
put?: never;
|
|
648
|
+
/** Annotate Span Documents */
|
|
649
|
+
post: operations["annotateSpanDocuments"];
|
|
650
|
+
delete?: never;
|
|
651
|
+
options?: never;
|
|
652
|
+
head?: never;
|
|
653
|
+
patch?: never;
|
|
654
|
+
trace?: never;
|
|
655
|
+
};
|
|
636
656
|
"/v1/users": {
|
|
637
657
|
parameters: {
|
|
638
658
|
query?: never;
|
|
@@ -681,6 +701,16 @@ export interface paths {
|
|
|
681
701
|
export type webhooks = Record<string, never>;
|
|
682
702
|
export interface components {
|
|
683
703
|
schemas: {
|
|
704
|
+
/** AnnotateSpanDocumentsRequestBody */
|
|
705
|
+
AnnotateSpanDocumentsRequestBody: {
|
|
706
|
+
/** Data */
|
|
707
|
+
data: components["schemas"]["SpanDocumentAnnotationData"][];
|
|
708
|
+
};
|
|
709
|
+
/** AnnotateSpanDocumentsResponseBody */
|
|
710
|
+
AnnotateSpanDocumentsResponseBody: {
|
|
711
|
+
/** Data */
|
|
712
|
+
data: components["schemas"]["InsertedSpanDocumentAnnotation"][];
|
|
713
|
+
};
|
|
684
714
|
/** AnnotateSpansRequestBody */
|
|
685
715
|
AnnotateSpansRequestBody: {
|
|
686
716
|
/** Data */
|
|
@@ -691,6 +721,24 @@ export interface components {
|
|
|
691
721
|
/** Data */
|
|
692
722
|
data: components["schemas"]["InsertedSpanAnnotation"][];
|
|
693
723
|
};
|
|
724
|
+
/** AnnotationResult */
|
|
725
|
+
AnnotationResult: {
|
|
726
|
+
/**
|
|
727
|
+
* Label
|
|
728
|
+
* @description The label assigned by the annotation
|
|
729
|
+
*/
|
|
730
|
+
label?: string | null;
|
|
731
|
+
/**
|
|
732
|
+
* Score
|
|
733
|
+
* @description The score assigned by the annotation
|
|
734
|
+
*/
|
|
735
|
+
score?: number | null;
|
|
736
|
+
/**
|
|
737
|
+
* Explanation
|
|
738
|
+
* @description Explanation of the annotation result
|
|
739
|
+
*/
|
|
740
|
+
explanation?: string | null;
|
|
741
|
+
};
|
|
694
742
|
/** CategoricalAnnotationConfig */
|
|
695
743
|
CategoricalAnnotationConfig: {
|
|
696
744
|
/** Name */
|
|
@@ -1228,6 +1276,14 @@ export interface components {
|
|
|
1228
1276
|
*/
|
|
1229
1277
|
id: string;
|
|
1230
1278
|
};
|
|
1279
|
+
/** InsertedSpanDocumentAnnotation */
|
|
1280
|
+
InsertedSpanDocumentAnnotation: {
|
|
1281
|
+
/**
|
|
1282
|
+
* Id
|
|
1283
|
+
* @description The ID of the inserted span document annotation
|
|
1284
|
+
*/
|
|
1285
|
+
id: string;
|
|
1286
|
+
};
|
|
1231
1287
|
/** ListDatasetExamplesData */
|
|
1232
1288
|
ListDatasetExamplesData: {
|
|
1233
1289
|
/** Dataset Id */
|
|
@@ -1259,6 +1315,8 @@ export interface components {
|
|
|
1259
1315
|
ListExperimentRunsResponseBody: {
|
|
1260
1316
|
/** Data */
|
|
1261
1317
|
data: components["schemas"]["ExperimentRunResponse"][];
|
|
1318
|
+
/** Next Cursor */
|
|
1319
|
+
next_cursor: string | null;
|
|
1262
1320
|
};
|
|
1263
1321
|
/** ListExperimentsResponseBody */
|
|
1264
1322
|
ListExperimentsResponseBody: {
|
|
@@ -2097,11 +2155,25 @@ export interface components {
|
|
|
2097
2155
|
};
|
|
2098
2156
|
/** SpanAnnotation */
|
|
2099
2157
|
SpanAnnotation: {
|
|
2158
|
+
/** Id */
|
|
2159
|
+
id: string;
|
|
2100
2160
|
/**
|
|
2101
|
-
*
|
|
2102
|
-
*
|
|
2161
|
+
* Created At
|
|
2162
|
+
* Format: date-time
|
|
2103
2163
|
*/
|
|
2104
|
-
|
|
2164
|
+
created_at: string;
|
|
2165
|
+
/**
|
|
2166
|
+
* Updated At
|
|
2167
|
+
* Format: date-time
|
|
2168
|
+
*/
|
|
2169
|
+
updated_at: string;
|
|
2170
|
+
/**
|
|
2171
|
+
* Source
|
|
2172
|
+
* @enum {string}
|
|
2173
|
+
*/
|
|
2174
|
+
source: "API" | "APP";
|
|
2175
|
+
/** User Id */
|
|
2176
|
+
user_id: string | null;
|
|
2105
2177
|
/**
|
|
2106
2178
|
* Name
|
|
2107
2179
|
* @description The name of the annotation
|
|
@@ -2114,7 +2186,7 @@ export interface components {
|
|
|
2114
2186
|
*/
|
|
2115
2187
|
annotator_kind: "LLM" | "CODE" | "HUMAN";
|
|
2116
2188
|
/** @description The result of the annotation */
|
|
2117
|
-
result?: components["schemas"]["
|
|
2189
|
+
result?: components["schemas"]["AnnotationResult"] | null;
|
|
2118
2190
|
/**
|
|
2119
2191
|
* Metadata
|
|
2120
2192
|
* @description Metadata for the annotation
|
|
@@ -2128,33 +2200,14 @@ export interface components {
|
|
|
2128
2200
|
* @default
|
|
2129
2201
|
*/
|
|
2130
2202
|
identifier?: string;
|
|
2131
|
-
/** Id */
|
|
2132
|
-
id: string;
|
|
2133
|
-
/**
|
|
2134
|
-
* Created At
|
|
2135
|
-
* Format: date-time
|
|
2136
|
-
*/
|
|
2137
|
-
created_at: string;
|
|
2138
|
-
/**
|
|
2139
|
-
* Updated At
|
|
2140
|
-
* Format: date-time
|
|
2141
|
-
*/
|
|
2142
|
-
updated_at: string;
|
|
2143
|
-
/**
|
|
2144
|
-
* Source
|
|
2145
|
-
* @enum {string}
|
|
2146
|
-
*/
|
|
2147
|
-
source: "API" | "APP";
|
|
2148
|
-
/** User Id */
|
|
2149
|
-
user_id: string | null;
|
|
2150
|
-
};
|
|
2151
|
-
/** SpanAnnotationData */
|
|
2152
|
-
SpanAnnotationData: {
|
|
2153
2203
|
/**
|
|
2154
2204
|
* Span Id
|
|
2155
2205
|
* @description OpenTelemetry Span ID (hex format w/o 0x prefix)
|
|
2156
2206
|
*/
|
|
2157
2207
|
span_id: string;
|
|
2208
|
+
};
|
|
2209
|
+
/** SpanAnnotationData */
|
|
2210
|
+
SpanAnnotationData: {
|
|
2158
2211
|
/**
|
|
2159
2212
|
* Name
|
|
2160
2213
|
* @description The name of the annotation
|
|
@@ -2167,7 +2220,7 @@ export interface components {
|
|
|
2167
2220
|
*/
|
|
2168
2221
|
annotator_kind: "LLM" | "CODE" | "HUMAN";
|
|
2169
2222
|
/** @description The result of the annotation */
|
|
2170
|
-
result?: components["schemas"]["
|
|
2223
|
+
result?: components["schemas"]["AnnotationResult"] | null;
|
|
2171
2224
|
/**
|
|
2172
2225
|
* Metadata
|
|
2173
2226
|
* @description Metadata for the annotation
|
|
@@ -2181,24 +2234,11 @@ export interface components {
|
|
|
2181
2234
|
* @default
|
|
2182
2235
|
*/
|
|
2183
2236
|
identifier?: string;
|
|
2184
|
-
};
|
|
2185
|
-
/** SpanAnnotationResult */
|
|
2186
|
-
SpanAnnotationResult: {
|
|
2187
|
-
/**
|
|
2188
|
-
* Label
|
|
2189
|
-
* @description The label assigned by the annotation
|
|
2190
|
-
*/
|
|
2191
|
-
label?: string | null;
|
|
2192
2237
|
/**
|
|
2193
|
-
*
|
|
2194
|
-
* @description
|
|
2195
|
-
*/
|
|
2196
|
-
score?: number | null;
|
|
2197
|
-
/**
|
|
2198
|
-
* Explanation
|
|
2199
|
-
* @description Explanation of the annotation result
|
|
2238
|
+
* Span Id
|
|
2239
|
+
* @description OpenTelemetry Span ID (hex format w/o 0x prefix)
|
|
2200
2240
|
*/
|
|
2201
|
-
|
|
2241
|
+
span_id: string;
|
|
2202
2242
|
};
|
|
2203
2243
|
/** SpanAnnotationsResponseBody */
|
|
2204
2244
|
SpanAnnotationsResponseBody: {
|
|
@@ -2220,6 +2260,45 @@ export interface components {
|
|
|
2220
2260
|
*/
|
|
2221
2261
|
span_id: string;
|
|
2222
2262
|
};
|
|
2263
|
+
/** SpanDocumentAnnotationData */
|
|
2264
|
+
SpanDocumentAnnotationData: {
|
|
2265
|
+
/**
|
|
2266
|
+
* Name
|
|
2267
|
+
* @description The name of the annotation
|
|
2268
|
+
*/
|
|
2269
|
+
name: string;
|
|
2270
|
+
/**
|
|
2271
|
+
* Annotator Kind
|
|
2272
|
+
* @description The kind of annotator used for the annotation
|
|
2273
|
+
* @enum {string}
|
|
2274
|
+
*/
|
|
2275
|
+
annotator_kind: "LLM" | "CODE" | "HUMAN";
|
|
2276
|
+
/** @description The result of the annotation */
|
|
2277
|
+
result?: components["schemas"]["AnnotationResult"] | null;
|
|
2278
|
+
/**
|
|
2279
|
+
* Metadata
|
|
2280
|
+
* @description Metadata for the annotation
|
|
2281
|
+
*/
|
|
2282
|
+
metadata?: {
|
|
2283
|
+
[key: string]: unknown;
|
|
2284
|
+
} | null;
|
|
2285
|
+
/**
|
|
2286
|
+
* Identifier
|
|
2287
|
+
* @description The identifier of the annotation. If provided, the annotation will be updated if it already exists.
|
|
2288
|
+
* @default
|
|
2289
|
+
*/
|
|
2290
|
+
identifier?: string;
|
|
2291
|
+
/**
|
|
2292
|
+
* Span Id
|
|
2293
|
+
* @description OpenTelemetry Span ID (hex format w/o 0x prefix)
|
|
2294
|
+
*/
|
|
2295
|
+
span_id: string;
|
|
2296
|
+
/**
|
|
2297
|
+
* Document Position
|
|
2298
|
+
* @description A 0 based index of the document. E.x. the first document during retrieval is 0
|
|
2299
|
+
*/
|
|
2300
|
+
document_position: number;
|
|
2301
|
+
};
|
|
2223
2302
|
/** SpanEvent */
|
|
2224
2303
|
SpanEvent: {
|
|
2225
2304
|
/**
|
|
@@ -3355,7 +3434,12 @@ export interface operations {
|
|
|
3355
3434
|
};
|
|
3356
3435
|
listExperimentRuns: {
|
|
3357
3436
|
parameters: {
|
|
3358
|
-
query?:
|
|
3437
|
+
query?: {
|
|
3438
|
+
/** @description Cursor for pagination (base64-encoded experiment run ID) */
|
|
3439
|
+
cursor?: string | null;
|
|
3440
|
+
/** @description The max number of experiment runs to return at a time. If not specified, returns all results. */
|
|
3441
|
+
limit?: number | null;
|
|
3442
|
+
};
|
|
3359
3443
|
header?: never;
|
|
3360
3444
|
path: {
|
|
3361
3445
|
experiment_id: string;
|
|
@@ -3391,13 +3475,13 @@ export interface operations {
|
|
|
3391
3475
|
"text/plain": string;
|
|
3392
3476
|
};
|
|
3393
3477
|
};
|
|
3394
|
-
/** @description
|
|
3478
|
+
/** @description Invalid cursor format */
|
|
3395
3479
|
422: {
|
|
3396
3480
|
headers: {
|
|
3397
3481
|
[name: string]: unknown;
|
|
3398
3482
|
};
|
|
3399
3483
|
content: {
|
|
3400
|
-
"
|
|
3484
|
+
"text/plain": string;
|
|
3401
3485
|
};
|
|
3402
3486
|
};
|
|
3403
3487
|
};
|
|
@@ -4587,6 +4671,60 @@ export interface operations {
|
|
|
4587
4671
|
};
|
|
4588
4672
|
};
|
|
4589
4673
|
};
|
|
4674
|
+
annotateSpanDocuments: {
|
|
4675
|
+
parameters: {
|
|
4676
|
+
query?: {
|
|
4677
|
+
/** @description If set to true, the annotations are inserted synchronously. */
|
|
4678
|
+
sync?: boolean;
|
|
4679
|
+
};
|
|
4680
|
+
header?: never;
|
|
4681
|
+
path?: never;
|
|
4682
|
+
cookie?: never;
|
|
4683
|
+
};
|
|
4684
|
+
requestBody: {
|
|
4685
|
+
content: {
|
|
4686
|
+
"application/json": components["schemas"]["AnnotateSpanDocumentsRequestBody"];
|
|
4687
|
+
};
|
|
4688
|
+
};
|
|
4689
|
+
responses: {
|
|
4690
|
+
/** @description Span document annotation inserted successfully */
|
|
4691
|
+
200: {
|
|
4692
|
+
headers: {
|
|
4693
|
+
[name: string]: unknown;
|
|
4694
|
+
};
|
|
4695
|
+
content: {
|
|
4696
|
+
"application/json": components["schemas"]["AnnotateSpanDocumentsResponseBody"];
|
|
4697
|
+
};
|
|
4698
|
+
};
|
|
4699
|
+
/** @description Forbidden */
|
|
4700
|
+
403: {
|
|
4701
|
+
headers: {
|
|
4702
|
+
[name: string]: unknown;
|
|
4703
|
+
};
|
|
4704
|
+
content: {
|
|
4705
|
+
"text/plain": string;
|
|
4706
|
+
};
|
|
4707
|
+
};
|
|
4708
|
+
/** @description Span not found */
|
|
4709
|
+
404: {
|
|
4710
|
+
headers: {
|
|
4711
|
+
[name: string]: unknown;
|
|
4712
|
+
};
|
|
4713
|
+
content: {
|
|
4714
|
+
"text/plain": string;
|
|
4715
|
+
};
|
|
4716
|
+
};
|
|
4717
|
+
/** @description Invalid request - non-empty identifier not supported */
|
|
4718
|
+
422: {
|
|
4719
|
+
headers: {
|
|
4720
|
+
[name: string]: unknown;
|
|
4721
|
+
};
|
|
4722
|
+
content: {
|
|
4723
|
+
"text/plain": string;
|
|
4724
|
+
};
|
|
4725
|
+
};
|
|
4726
|
+
};
|
|
4727
|
+
};
|
|
4590
4728
|
getUsers: {
|
|
4591
4729
|
parameters: {
|
|
4592
4730
|
query?: {
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createClient } from "../client";
|
|
2
|
+
import { ClientFn } from "../types/core";
|
|
3
|
+
import { DocumentAnnotation, toDocumentAnnotationData } from "./types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parameters to add a document annotation
|
|
7
|
+
*/
|
|
8
|
+
export interface AddDocumentAnnotationParams extends ClientFn {
|
|
9
|
+
documentAnnotation: DocumentAnnotation;
|
|
10
|
+
/**
|
|
11
|
+
* If true, the request will be fulfilled synchronously and return the annotation ID.
|
|
12
|
+
* If false, the request will be processed asynchronously and return null.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
sync?: boolean;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Add an annotation to a document within a span.
|
|
20
|
+
*
|
|
21
|
+
* The annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, explanation, and metadata.
|
|
22
|
+
* At least one of label, score, or explanation must be provided.
|
|
23
|
+
*
|
|
24
|
+
* @param params - The parameters to add a document annotation
|
|
25
|
+
* @returns The ID of the created annotation
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```ts
|
|
29
|
+
* const result = await addDocumentAnnotation({
|
|
30
|
+
* documentAnnotation: {
|
|
31
|
+
* spanId: "123abc",
|
|
32
|
+
* documentPosition: 0,
|
|
33
|
+
* name: "relevance_score",
|
|
34
|
+
* label: "relevant",
|
|
35
|
+
* score: 0.95,
|
|
36
|
+
* annotatorKind: "LLM",
|
|
37
|
+
* explanation: "Document is highly relevant to the query",
|
|
38
|
+
* metadata: {
|
|
39
|
+
* model: "gpt-4"
|
|
40
|
+
* }
|
|
41
|
+
* }
|
|
42
|
+
* });
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export async function addDocumentAnnotation({
|
|
46
|
+
client: _client,
|
|
47
|
+
documentAnnotation,
|
|
48
|
+
sync = false,
|
|
49
|
+
}: AddDocumentAnnotationParams): Promise<{ id: string } | null> {
|
|
50
|
+
const client = _client ?? createClient();
|
|
51
|
+
|
|
52
|
+
const { data, error } = await client.POST("/v1/document_annotations", {
|
|
53
|
+
params: {
|
|
54
|
+
query: { sync },
|
|
55
|
+
},
|
|
56
|
+
body: {
|
|
57
|
+
data: [toDocumentAnnotationData(documentAnnotation)],
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (error) {
|
|
62
|
+
throw new Error(`Failed to add document annotation: ${error}`);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return data?.data?.[0] || null;
|
|
66
|
+
}
|
|
@@ -7,6 +7,12 @@ import { SpanAnnotation, toSpanAnnotationData } from "./types";
|
|
|
7
7
|
*/
|
|
8
8
|
export interface AddSpanAnnotationParams extends ClientFn {
|
|
9
9
|
spanAnnotation: SpanAnnotation;
|
|
10
|
+
/**
|
|
11
|
+
* If true, the request will be fulfilled synchronously and return the annotation ID.
|
|
12
|
+
* If false, the request will be processed asynchronously and return null.
|
|
13
|
+
* @default false
|
|
14
|
+
*/
|
|
15
|
+
sync?: boolean;
|
|
10
16
|
}
|
|
11
17
|
|
|
12
18
|
/**
|
|
@@ -38,10 +44,14 @@ export interface AddSpanAnnotationParams extends ClientFn {
|
|
|
38
44
|
export async function addSpanAnnotation({
|
|
39
45
|
client: _client,
|
|
40
46
|
spanAnnotation,
|
|
41
|
-
|
|
47
|
+
sync = false,
|
|
48
|
+
}: AddSpanAnnotationParams): Promise<{ id: string } | null> {
|
|
42
49
|
const client = _client ?? createClient();
|
|
43
50
|
|
|
44
51
|
const { data, error } = await client.POST("/v1/span_annotations", {
|
|
52
|
+
params: {
|
|
53
|
+
query: { sync },
|
|
54
|
+
},
|
|
45
55
|
body: {
|
|
46
56
|
data: [toSpanAnnotationData(spanAnnotation)],
|
|
47
57
|
},
|
|
@@ -51,9 +61,5 @@ export async function addSpanAnnotation({
|
|
|
51
61
|
throw new Error(`Failed to add span annotation: ${error}`);
|
|
52
62
|
}
|
|
53
63
|
|
|
54
|
-
|
|
55
|
-
throw new Error("No annotation ID returned from server");
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return data.data[0];
|
|
64
|
+
return data?.data?.[0] || null;
|
|
59
65
|
}
|
package/src/spans/index.ts
CHANGED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { createClient } from "../client";
|
|
2
|
+
import { ClientFn } from "../types/core";
|
|
3
|
+
import { DocumentAnnotation, toDocumentAnnotationData } from "./types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Parameters to log multiple document annotations
|
|
7
|
+
*/
|
|
8
|
+
export interface LogDocumentAnnotationsParams extends ClientFn {
|
|
9
|
+
/**
|
|
10
|
+
* The document annotations to log
|
|
11
|
+
*/
|
|
12
|
+
documentAnnotations: DocumentAnnotation[];
|
|
13
|
+
/**
|
|
14
|
+
* If true, the request will be fulfilled synchronously and return the annotation IDs.
|
|
15
|
+
* If false, the request will be processed asynchronously and return null.
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
sync?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Log multiple document annotations in a single request.
|
|
23
|
+
*
|
|
24
|
+
* Each annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, explanation, and metadata.
|
|
25
|
+
* At least one of label, score, or explanation must be provided for each annotation.
|
|
26
|
+
*
|
|
27
|
+
* @param params - The parameters to log document annotations
|
|
28
|
+
* @returns The IDs of the created annotations
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* const results = await logDocumentAnnotations({
|
|
33
|
+
* documentAnnotations: [
|
|
34
|
+
* {
|
|
35
|
+
* spanId: "123abc",
|
|
36
|
+
* documentPosition: 0,
|
|
37
|
+
* name: "relevance_score",
|
|
38
|
+
* label: "relevant",
|
|
39
|
+
* score: 0.95,
|
|
40
|
+
* annotatorKind: "LLM",
|
|
41
|
+
* explanation: "Document is highly relevant to the query",
|
|
42
|
+
* metadata: {
|
|
43
|
+
* model: "gpt-4"
|
|
44
|
+
* }
|
|
45
|
+
* },
|
|
46
|
+
* {
|
|
47
|
+
* spanId: "123abc",
|
|
48
|
+
* documentPosition: 1,
|
|
49
|
+
* name: "relevance_score",
|
|
50
|
+
* label: "somewhat_relevant",
|
|
51
|
+
* score: 0.6,
|
|
52
|
+
* annotatorKind: "LLM"
|
|
53
|
+
* }
|
|
54
|
+
* ]
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export async function logDocumentAnnotations({
|
|
59
|
+
client: _client,
|
|
60
|
+
documentAnnotations,
|
|
61
|
+
sync = false,
|
|
62
|
+
}: LogDocumentAnnotationsParams): Promise<{ id: string }[]> {
|
|
63
|
+
const client = _client ?? createClient();
|
|
64
|
+
|
|
65
|
+
const { data, error } = await client.POST("/v1/document_annotations", {
|
|
66
|
+
params: {
|
|
67
|
+
query: { sync },
|
|
68
|
+
},
|
|
69
|
+
body: {
|
|
70
|
+
data: documentAnnotations.map(toDocumentAnnotationData),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
if (error) {
|
|
75
|
+
throw new Error(`Failed to log document annotations: ${error}`);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return data?.data || [];
|
|
79
|
+
}
|
|
@@ -10,6 +10,12 @@ export interface LogSpanAnnotationsParams extends ClientFn {
|
|
|
10
10
|
* The span annotations to log
|
|
11
11
|
*/
|
|
12
12
|
spanAnnotations: SpanAnnotation[];
|
|
13
|
+
/**
|
|
14
|
+
* If true, the request will be fulfilled synchronously and return the annotation IDs.
|
|
15
|
+
* If false, the request will be processed asynchronously and return null.
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
sync?: boolean;
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
/**
|
|
@@ -50,10 +56,14 @@ export interface LogSpanAnnotationsParams extends ClientFn {
|
|
|
50
56
|
export async function logSpanAnnotations({
|
|
51
57
|
client: _client,
|
|
52
58
|
spanAnnotations,
|
|
59
|
+
sync = false,
|
|
53
60
|
}: LogSpanAnnotationsParams): Promise<{ id: string }[]> {
|
|
54
61
|
const client = _client ?? createClient();
|
|
55
62
|
|
|
56
63
|
const { data, error } = await client.POST("/v1/span_annotations", {
|
|
64
|
+
params: {
|
|
65
|
+
query: { sync },
|
|
66
|
+
},
|
|
57
67
|
body: {
|
|
58
68
|
data: spanAnnotations.map(toSpanAnnotationData),
|
|
59
69
|
},
|
|
@@ -63,9 +73,5 @@ export async function logSpanAnnotations({
|
|
|
63
73
|
throw new Error(`Failed to log span annotations: ${error}`);
|
|
64
74
|
}
|
|
65
75
|
|
|
66
|
-
|
|
67
|
-
throw new Error("No annotation IDs returned from server");
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return data.data;
|
|
76
|
+
return data?.data || [];
|
|
71
77
|
}
|