@arizeai/phoenix-client 5.6.0 → 5.7.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.
Files changed (43) hide show
  1. package/dist/esm/__generated__/api/v1.d.ts +5 -1
  2. package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
  3. package/dist/esm/datasets/appendDatasetExamples.d.ts +29 -1
  4. package/dist/esm/datasets/appendDatasetExamples.d.ts.map +1 -1
  5. package/dist/esm/datasets/appendDatasetExamples.js +34 -1
  6. package/dist/esm/datasets/appendDatasetExamples.js.map +1 -1
  7. package/dist/esm/datasets/createDataset.d.ts +36 -1
  8. package/dist/esm/datasets/createDataset.d.ts.map +1 -1
  9. package/dist/esm/datasets/createDataset.js +41 -1
  10. package/dist/esm/datasets/createDataset.js.map +1 -1
  11. package/dist/esm/experiments/runExperiment.d.ts.map +1 -1
  12. package/dist/esm/experiments/runExperiment.js +2 -3
  13. package/dist/esm/experiments/runExperiment.js.map +1 -1
  14. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  15. package/dist/esm/types/datasets.d.ts +6 -0
  16. package/dist/esm/types/datasets.d.ts.map +1 -1
  17. package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
  18. package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
  19. package/dist/src/__generated__/api/v1.d.ts +5 -1
  20. package/dist/src/__generated__/api/v1.d.ts.map +1 -1
  21. package/dist/src/datasets/appendDatasetExamples.d.ts +29 -1
  22. package/dist/src/datasets/appendDatasetExamples.d.ts.map +1 -1
  23. package/dist/src/datasets/appendDatasetExamples.js +35 -7
  24. package/dist/src/datasets/appendDatasetExamples.js.map +1 -1
  25. package/dist/src/datasets/createDataset.d.ts +36 -1
  26. package/dist/src/datasets/createDataset.d.ts.map +1 -1
  27. package/dist/src/datasets/createDataset.js +43 -8
  28. package/dist/src/datasets/createDataset.js.map +1 -1
  29. package/dist/src/experiments/runExperiment.d.ts.map +1 -1
  30. package/dist/src/experiments/runExperiment.js +2 -3
  31. package/dist/src/experiments/runExperiment.js.map +1 -1
  32. package/dist/src/types/datasets.d.ts +6 -0
  33. package/dist/src/types/datasets.d.ts.map +1 -1
  34. package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
  35. package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/package.json +2 -2
  38. package/src/__generated__/api/v1.ts +5 -1
  39. package/src/datasets/appendDatasetExamples.ts +37 -1
  40. package/src/datasets/createDataset.ts +44 -1
  41. package/src/experiments/runExperiment.ts +2 -3
  42. package/src/types/datasets.ts +6 -0
  43. package/src/__generated__/api/v1.d.ts +0 -1255
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arizeai/phoenix-client",
3
- "version": "5.6.0",
3
+ "version": "5.7.0",
4
4
  "description": "A client for the Phoenix API",
5
5
  "main": "dist/src/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -75,7 +75,7 @@
75
75
  "tsx": "^4.19.3",
76
76
  "typescript": "^5.8.2",
77
77
  "vitest": "^4.0.10",
78
- "@arizeai/phoenix-evals": "0.6.5"
78
+ "@arizeai/phoenix-evals": "0.7.0"
79
79
  },
80
80
  "dependencies": {
81
81
  "@arizeai/openinference-semantic-conventions": "^1.1.0",
@@ -172,7 +172,7 @@ export interface paths {
172
172
  };
173
173
  get?: never;
174
174
  put?: never;
175
- /** Upload dataset from JSON, CSV, or PyArrow */
175
+ /** Upload dataset from JSON, JSONL, CSV, or PyArrow */
176
176
  post: operations["uploadDataset"];
177
177
  delete?: never;
178
178
  options?: never;
@@ -3616,6 +3616,8 @@ export interface operations {
3616
3616
  metadata?: Record<string, unknown>[];
3617
3617
  /** @description Split per example: string, string array, or null */
3618
3618
  splits?: (string | string[] | null)[];
3619
+ /** @description Span IDs to link examples back to spans */
3620
+ span_ids?: (string | null)[];
3619
3621
  };
3620
3622
  "multipart/form-data": {
3621
3623
  /** @enum {string} */
@@ -3627,6 +3629,8 @@ export interface operations {
3627
3629
  "metadata_keys[]"?: string[];
3628
3630
  /** @description Column names for auto-assigning examples to splits */
3629
3631
  "split_keys[]"?: string[];
3632
+ /** @description Column name for span IDs to link examples back to spans */
3633
+ span_id_key?: string;
3630
3634
  /** Format: binary */
3631
3635
  file: string;
3632
3636
  };
@@ -24,8 +24,36 @@ export type AppendDatasetExamplesResponse = {
24
24
  };
25
25
 
26
26
  /**
27
- * Append examples to an existing dataset
27
+ * Append examples to an existing dataset.
28
+ *
28
29
  * @experimental this interface may change in the future
30
+ *
31
+ * @param params - The parameters for appending examples
32
+ * @param params.client - Optional Phoenix client instance
33
+ * @param params.dataset - The dataset to append examples to (by ID or name)
34
+ * @param params.examples - The examples to append. Each example can include:
35
+ * - `input`: Required input data for the example
36
+ * - `output`: Optional expected output data
37
+ * - `metadata`: Optional metadata for the example
38
+ * - `splits`: Optional split assignment (string, array of strings, or null)
39
+ * - `spanId`: Optional OpenTelemetry span ID to link the example back to its source span
40
+ *
41
+ * @returns A promise that resolves to the dataset ID
42
+ *
43
+ * @example
44
+ * ```ts
45
+ * // Append examples with span links to an existing dataset
46
+ * const { datasetId } = await appendDatasetExamples({
47
+ * dataset: { datasetName: "qa-dataset" },
48
+ * examples: [
49
+ * {
50
+ * input: { question: "What is deep learning?" },
51
+ * output: { answer: "Deep learning is..." },
52
+ * spanId: "span123abc" // Links to the source span
53
+ * }
54
+ * ]
55
+ * });
56
+ * ```
29
57
  */
30
58
  export async function appendDatasetExamples({
31
59
  client: _client,
@@ -39,6 +67,13 @@ export async function appendDatasetExamples({
39
67
  const splits = examples.map((example) =>
40
68
  example.splits !== undefined ? example.splits : null
41
69
  );
70
+
71
+ // Extract span IDs from examples, preserving null/undefined as null
72
+ const spanIds = examples.map((example) => example?.spanId ?? null);
73
+
74
+ // Only include span_ids in the request if at least one example has a span ID
75
+ const hasSpanIds = spanIds.some((id) => id !== null);
76
+
42
77
  let datasetName: string;
43
78
  if ("datasetName" in dataset) {
44
79
  datasetName = dataset.datasetName;
@@ -62,6 +97,7 @@ export async function appendDatasetExamples({
62
97
  outputs,
63
98
  metadata,
64
99
  splits,
100
+ ...(hasSpanIds ? { span_ids: spanIds } : {}),
65
101
  },
66
102
  });
67
103
  invariant(appendResponse.data?.data, "Failed to append dataset examples");
@@ -24,8 +24,43 @@ export type CreateDatasetResponse = {
24
24
  };
25
25
 
26
26
  /**
27
- * Create a new dataset
27
+ * Create a new dataset with examples.
28
+ *
28
29
  * @experimental this interface may change in the future
30
+ *
31
+ * @param params - The parameters for creating the dataset
32
+ * @param params.client - Optional Phoenix client instance
33
+ * @param params.name - The name of the dataset
34
+ * @param params.description - The description of the dataset
35
+ * @param params.examples - The examples to create in the dataset. Each example can include:
36
+ * - `input`: Required input data for the example
37
+ * - `output`: Optional expected output data
38
+ * - `metadata`: Optional metadata for the example
39
+ * - `splits`: Optional split assignment (string, array of strings, or null)
40
+ * - `spanId`: Optional OpenTelemetry span ID to link the example back to its source span
41
+ *
42
+ * @returns A promise that resolves to the created dataset ID
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * // Create a dataset with span links
47
+ * const { datasetId } = await createDataset({
48
+ * name: "qa-dataset",
49
+ * description: "Q&A examples from traces",
50
+ * examples: [
51
+ * {
52
+ * input: { question: "What is AI?" },
53
+ * output: { answer: "Artificial Intelligence is..." },
54
+ * spanId: "abc123def456" // Links to the source span
55
+ * },
56
+ * {
57
+ * input: { question: "Explain ML" },
58
+ * output: { answer: "Machine Learning is..." },
59
+ * spanId: "789ghi012jkl"
60
+ * }
61
+ * ]
62
+ * });
63
+ * ```
29
64
  */
30
65
  export async function createDataset({
31
66
  client: _client,
@@ -40,6 +75,13 @@ export async function createDataset({
40
75
  const splits = examples.map((example) =>
41
76
  example?.splits !== undefined ? example.splits : null
42
77
  );
78
+
79
+ // Extract span IDs from examples, preserving null/undefined as null
80
+ const spanIds = examples.map((example) => example?.spanId ?? null);
81
+
82
+ // Only include span_ids in the request if at least one example has a span ID
83
+ const hasSpanIds = spanIds.some((id) => id !== null);
84
+
43
85
  const createDatasetResponse = await client.POST("/v1/datasets/upload", {
44
86
  params: {
45
87
  query: {
@@ -55,6 +97,7 @@ export async function createDataset({
55
97
  outputs,
56
98
  metadata,
57
99
  splits,
100
+ ...(hasSpanIds ? { span_ids: spanIds } : {}),
58
101
  },
59
102
  });
60
103
  invariant(createDatasetResponse.data?.data, "Failed to create dataset");
@@ -48,7 +48,6 @@ import {
48
48
  import { getExperimentInfo } from "./getExperimentInfo";
49
49
  import { getExperimentEvaluators } from "./helpers";
50
50
 
51
- import assert from "assert";
52
51
  import { queue } from "async";
53
52
  import invariant from "tiny-invariant";
54
53
 
@@ -181,7 +180,7 @@ export async function runExperiment({
181
180
  diagLogLevel,
182
181
  }: RunExperimentParams): Promise<RanExperiment> {
183
182
  // Validation
184
- assert(
183
+ invariant(
185
184
  isValidRepetitionParam(repetitions),
186
185
  "repetitions must be an integer greater than 0"
187
186
  );
@@ -416,7 +415,7 @@ function runTaskWithExamples({
416
415
  repetitions?: number;
417
416
  }): Promise<void> {
418
417
  // Validate the input
419
- assert(
418
+ invariant(
420
419
  isValidRepetitionParam(repetitions),
421
420
  "repetitions must be an integer greater than 0"
422
421
  );
@@ -52,6 +52,12 @@ export interface Example {
52
52
  * - null for no split assignment
53
53
  */
54
54
  splits?: string | string[] | null;
55
+ /**
56
+ * OpenTelemetry span ID to link this example back to its source span.
57
+ * When provided, the dataset example will be associated with the span
58
+ * in the Phoenix UI, enabling traceability from datasets back to traces.
59
+ */
60
+ spanId?: string | null;
55
61
  }
56
62
 
57
63
  /**