@arizeai/phoenix-client 3.0.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 +188 -50
- package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
- package/dist/esm/experiments/instrumention.d.ts +6 -1
- package/dist/esm/experiments/instrumention.d.ts.map +1 -1
- package/dist/esm/experiments/instrumention.js +15 -15
- package/dist/esm/experiments/instrumention.js.map +1 -1
- package/dist/esm/experiments/runExperiment.d.ts +12 -2
- package/dist/esm/experiments/runExperiment.d.ts.map +1 -1
- package/dist/esm/experiments/runExperiment.js +5 -2
- package/dist/esm/experiments/runExperiment.js.map +1 -1
- package/dist/esm/schemas/llm/converters.js +4 -4
- package/dist/esm/schemas/llm/converters.js.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 +188 -50
- package/dist/src/__generated__/api/v1.d.ts.map +1 -1
- package/dist/src/experiments/instrumention.d.ts +6 -1
- package/dist/src/experiments/instrumention.d.ts.map +1 -1
- package/dist/src/experiments/instrumention.js +13 -13
- package/dist/src/experiments/instrumention.js.map +1 -1
- package/dist/src/experiments/runExperiment.d.ts +12 -2
- package/dist/src/experiments/runExperiment.d.ts.map +1 -1
- package/dist/src/experiments/runExperiment.js +5 -2
- package/dist/src/experiments/runExperiment.js.map +1 -1
- package/dist/src/schemas/llm/converters.js +4 -4
- package/dist/src/schemas/llm/converters.js.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 +188 -50
- package/src/experiments/instrumention.ts +27 -14
- package/src/experiments/runExperiment.ts +15 -0
- package/src/schemas/llm/converters.ts +4 -4
- 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
|
/**
|
|
@@ -2351,11 +2430,11 @@ export interface components {
|
|
|
2351
2430
|
* @description The end time of the evaluation in ISO format
|
|
2352
2431
|
*/
|
|
2353
2432
|
end_time: string;
|
|
2354
|
-
/** @description The result of the evaluation */
|
|
2355
|
-
result
|
|
2433
|
+
/** @description The result of the evaluation. Either result or error must be provided. */
|
|
2434
|
+
result?: components["schemas"]["ExperimentEvaluationResult"] | null;
|
|
2356
2435
|
/**
|
|
2357
2436
|
* Error
|
|
2358
|
-
* @description
|
|
2437
|
+
* @description Error message if the evaluation encountered an error. Either result or error must be provided.
|
|
2359
2438
|
*/
|
|
2360
2439
|
error?: string | null;
|
|
2361
2440
|
/**
|
|
@@ -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?: {
|
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import { diag, DiagConsoleLogger, DiagLogLevel } from "@opentelemetry/api";
|
|
2
2
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";
|
|
3
3
|
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
NodeTracerProvider,
|
|
6
|
+
SpanProcessor,
|
|
7
|
+
} from "@opentelemetry/sdk-trace-node";
|
|
5
8
|
import { SEMRESATTRS_PROJECT_NAME } from "@arizeai/openinference-semantic-conventions";
|
|
6
9
|
import { HeadersOptions } from "openapi-fetch";
|
|
7
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
OpenInferenceBatchSpanProcessor,
|
|
12
|
+
OpenInferenceSimpleSpanProcessor,
|
|
13
|
+
} from "@arizeai/openinference-vercel";
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
16
|
* Creates a provider that exports traces to Phoenix.
|
|
@@ -13,9 +19,15 @@ export function createProvider({
|
|
|
13
19
|
projectName,
|
|
14
20
|
baseUrl,
|
|
15
21
|
headers,
|
|
22
|
+
useBatchSpanProcessor = true,
|
|
16
23
|
}: {
|
|
17
24
|
projectName: string;
|
|
18
25
|
headers: HeadersOptions;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to use batching for the span processor.
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
useBatchSpanProcessor: boolean;
|
|
19
31
|
/**
|
|
20
32
|
* The base URL of the Phoenix. Doesn't include the /v1/traces path.
|
|
21
33
|
*/
|
|
@@ -23,22 +35,23 @@ export function createProvider({
|
|
|
23
35
|
}) {
|
|
24
36
|
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ERROR);
|
|
25
37
|
|
|
38
|
+
const exporter = new OTLPTraceExporter({
|
|
39
|
+
url: `${baseUrl}/v1/traces`,
|
|
40
|
+
headers: Array.isArray(headers) ? Object.fromEntries(headers) : headers,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
let spanProcessor: SpanProcessor;
|
|
44
|
+
if (useBatchSpanProcessor) {
|
|
45
|
+
spanProcessor = new OpenInferenceBatchSpanProcessor({ exporter });
|
|
46
|
+
} else {
|
|
47
|
+
spanProcessor = new OpenInferenceSimpleSpanProcessor({ exporter });
|
|
48
|
+
}
|
|
49
|
+
|
|
26
50
|
const provider = new NodeTracerProvider({
|
|
27
51
|
resource: resourceFromAttributes({
|
|
28
52
|
[SEMRESATTRS_PROJECT_NAME]: projectName,
|
|
29
53
|
}),
|
|
30
|
-
spanProcessors: [
|
|
31
|
-
// We opt to use the OpenInferenceSimpleSpanProcessor instead of the SimpleSpanProcessor
|
|
32
|
-
// Since so many AI applications use the AI SDK
|
|
33
|
-
new OpenInferenceSimpleSpanProcessor({
|
|
34
|
-
exporter: new OTLPTraceExporter({
|
|
35
|
-
url: `${baseUrl}/v1/traces`,
|
|
36
|
-
headers: Array.isArray(headers)
|
|
37
|
-
? Object.fromEntries(headers)
|
|
38
|
-
: headers,
|
|
39
|
-
}),
|
|
40
|
-
}),
|
|
41
|
-
],
|
|
54
|
+
spanProcessors: [spanProcessor],
|
|
42
55
|
});
|
|
43
56
|
|
|
44
57
|
return provider;
|
|
@@ -94,6 +94,11 @@ export type RunExperimentParams = ClientFn & {
|
|
|
94
94
|
* @default true
|
|
95
95
|
*/
|
|
96
96
|
setGlobalTracerProvider?: boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Whether to use batching for the span processor.
|
|
99
|
+
* @default true
|
|
100
|
+
*/
|
|
101
|
+
useBatchSpanProcessor?: boolean;
|
|
97
102
|
};
|
|
98
103
|
|
|
99
104
|
/**
|
|
@@ -141,6 +146,7 @@ export async function runExperiment({
|
|
|
141
146
|
concurrency = 5,
|
|
142
147
|
dryRun = false,
|
|
143
148
|
setGlobalTracerProvider = true,
|
|
149
|
+
useBatchSpanProcessor = true,
|
|
144
150
|
}: RunExperimentParams): Promise<RanExperiment> {
|
|
145
151
|
let provider: NodeTracerProvider | undefined;
|
|
146
152
|
const isDryRun = typeof dryRun === "number" || dryRun === true;
|
|
@@ -201,6 +207,7 @@ export async function runExperiment({
|
|
|
201
207
|
projectName,
|
|
202
208
|
baseUrl,
|
|
203
209
|
headers: client.config.headers ?? {},
|
|
210
|
+
useBatchSpanProcessor,
|
|
204
211
|
});
|
|
205
212
|
// Register the provider
|
|
206
213
|
if (setGlobalTracerProvider) {
|
|
@@ -276,6 +283,7 @@ export async function runExperiment({
|
|
|
276
283
|
concurrency,
|
|
277
284
|
dryRun,
|
|
278
285
|
setGlobalTracerProvider,
|
|
286
|
+
useBatchSpanProcessor,
|
|
279
287
|
});
|
|
280
288
|
ranExperiment.evaluationRuns = evaluationRuns;
|
|
281
289
|
|
|
@@ -421,6 +429,7 @@ export async function evaluateExperiment({
|
|
|
421
429
|
concurrency = 5,
|
|
422
430
|
dryRun = false,
|
|
423
431
|
setGlobalTracerProvider = true,
|
|
432
|
+
useBatchSpanProcessor = true,
|
|
424
433
|
}: {
|
|
425
434
|
/**
|
|
426
435
|
* The experiment to evaluate
|
|
@@ -445,6 +454,11 @@ export async function evaluateExperiment({
|
|
|
445
454
|
* @default true
|
|
446
455
|
*/
|
|
447
456
|
setGlobalTracerProvider?: boolean;
|
|
457
|
+
/**
|
|
458
|
+
* Whether to use batching for the span processor.
|
|
459
|
+
* @default true
|
|
460
|
+
*/
|
|
461
|
+
useBatchSpanProcessor?: boolean;
|
|
448
462
|
}): Promise<RanExperiment> {
|
|
449
463
|
const isDryRun = typeof dryRun === "number" || dryRun === true;
|
|
450
464
|
const client = _client ?? createClient();
|
|
@@ -459,6 +473,7 @@ export async function evaluateExperiment({
|
|
|
459
473
|
projectName: "evaluators",
|
|
460
474
|
baseUrl,
|
|
461
475
|
headers: client.config.headers ?? {},
|
|
476
|
+
useBatchSpanProcessor,
|
|
462
477
|
});
|
|
463
478
|
if (setGlobalTracerProvider) {
|
|
464
479
|
provider.register();
|
|
@@ -38,7 +38,7 @@ export const safelyConvertMessageToProvider = <
|
|
|
38
38
|
);
|
|
39
39
|
// convert the OpenAI format to the target provider format
|
|
40
40
|
return fromOpenAIMessage({ message: openAIMessage, targetProvider });
|
|
41
|
-
} catch
|
|
41
|
+
} catch {
|
|
42
42
|
return null;
|
|
43
43
|
}
|
|
44
44
|
};
|
|
@@ -64,7 +64,7 @@ export const safelyConvertToolCallToProvider = <
|
|
|
64
64
|
toolCall: openAIToolCall,
|
|
65
65
|
targetProvider,
|
|
66
66
|
});
|
|
67
|
-
} catch
|
|
67
|
+
} catch {
|
|
68
68
|
return null;
|
|
69
69
|
}
|
|
70
70
|
};
|
|
@@ -90,7 +90,7 @@ export const safelyConvertToolDefinitionToProvider = <
|
|
|
90
90
|
toolDefinition: openAIToolDefinition,
|
|
91
91
|
targetProvider,
|
|
92
92
|
});
|
|
93
|
-
} catch
|
|
93
|
+
} catch {
|
|
94
94
|
return null;
|
|
95
95
|
}
|
|
96
96
|
};
|
|
@@ -116,7 +116,7 @@ export const safelyConvertToolChoiceToProvider = <
|
|
|
116
116
|
toolChoice: openAIToolChoice,
|
|
117
117
|
targetProvider,
|
|
118
118
|
});
|
|
119
|
-
} catch
|
|
119
|
+
} catch {
|
|
120
120
|
return null;
|
|
121
121
|
}
|
|
122
122
|
};
|
|
@@ -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