@arizeai/phoenix-client 1.0.2 → 1.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.
Files changed (84) hide show
  1. package/README.md +17 -5
  2. package/dist/esm/__generated__/api/v1.d.ts +1809 -295
  3. package/dist/esm/__generated__/api/v1.d.ts.map +1 -1
  4. package/dist/esm/experiments/runExperiment.d.ts +48 -13
  5. package/dist/esm/experiments/runExperiment.d.ts.map +1 -1
  6. package/dist/esm/experiments/runExperiment.js +139 -36
  7. package/dist/esm/experiments/runExperiment.js.map +1 -1
  8. package/dist/esm/schemas/llm/constants.d.ts +1 -1
  9. package/dist/esm/schemas/llm/converters.d.ts +4 -4
  10. package/dist/esm/schemas/llm/openai/converters.d.ts +1 -1
  11. package/dist/esm/schemas/llm/phoenixPrompt/converters.d.ts +8 -8
  12. package/dist/esm/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts +5 -5
  13. package/dist/esm/schemas/llm/phoenixPrompt/messageSchemas.d.ts +8 -8
  14. package/dist/esm/schemas/llm/schemas.d.ts +4 -4
  15. package/dist/esm/spans/addSpanAnnotation.d.ts +39 -0
  16. package/dist/esm/spans/addSpanAnnotation.d.ts.map +1 -0
  17. package/dist/esm/spans/addSpanAnnotation.js +44 -0
  18. package/dist/esm/spans/addSpanAnnotation.js.map +1 -0
  19. package/dist/esm/spans/index.d.ts +3 -0
  20. package/dist/esm/spans/index.d.ts.map +1 -0
  21. package/dist/esm/spans/index.js +3 -0
  22. package/dist/esm/spans/index.js.map +1 -0
  23. package/dist/esm/spans/logSpanAnnotations.d.ts +51 -0
  24. package/dist/esm/spans/logSpanAnnotations.d.ts.map +1 -0
  25. package/dist/esm/spans/logSpanAnnotations.js +53 -0
  26. package/dist/esm/spans/logSpanAnnotations.js.map +1 -0
  27. package/dist/esm/spans/types.d.ts +43 -0
  28. package/dist/esm/spans/types.d.ts.map +1 -0
  29. package/dist/esm/spans/types.js +18 -0
  30. package/dist/esm/spans/types.js.map +1 -0
  31. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  32. package/dist/esm/types/annotations.d.ts +2 -1
  33. package/dist/esm/types/annotations.d.ts.map +1 -1
  34. package/dist/esm/types/experiments.d.ts +1 -7
  35. package/dist/esm/types/experiments.d.ts.map +1 -1
  36. package/dist/esm/utils/formatPromptMessages.d.ts +3 -1
  37. package/dist/esm/utils/formatPromptMessages.d.ts.map +1 -1
  38. package/dist/esm/utils/getPromptBySelector.d.ts.map +1 -1
  39. package/dist/src/__generated__/api/v1.d.ts +1809 -295
  40. package/dist/src/__generated__/api/v1.d.ts.map +1 -1
  41. package/dist/src/experiments/runExperiment.d.ts +48 -13
  42. package/dist/src/experiments/runExperiment.d.ts.map +1 -1
  43. package/dist/src/experiments/runExperiment.js +138 -36
  44. package/dist/src/experiments/runExperiment.js.map +1 -1
  45. package/dist/src/schemas/llm/constants.d.ts +1 -1
  46. package/dist/src/schemas/llm/converters.d.ts +4 -4
  47. package/dist/src/schemas/llm/openai/converters.d.ts +1 -1
  48. package/dist/src/schemas/llm/phoenixPrompt/converters.d.ts +8 -8
  49. package/dist/src/schemas/llm/phoenixPrompt/messagePartSchemas.d.ts +5 -5
  50. package/dist/src/schemas/llm/phoenixPrompt/messageSchemas.d.ts +8 -8
  51. package/dist/src/schemas/llm/schemas.d.ts +4 -4
  52. package/dist/src/spans/addSpanAnnotation.d.ts +39 -0
  53. package/dist/src/spans/addSpanAnnotation.d.ts.map +1 -0
  54. package/dist/src/spans/addSpanAnnotation.js +59 -0
  55. package/dist/src/spans/addSpanAnnotation.js.map +1 -0
  56. package/dist/src/spans/index.d.ts +3 -0
  57. package/dist/src/spans/index.d.ts.map +1 -0
  58. package/dist/src/spans/index.js +19 -0
  59. package/dist/src/spans/index.js.map +1 -0
  60. package/dist/src/spans/logSpanAnnotations.d.ts +51 -0
  61. package/dist/src/spans/logSpanAnnotations.d.ts.map +1 -0
  62. package/dist/src/spans/logSpanAnnotations.js +68 -0
  63. package/dist/src/spans/logSpanAnnotations.js.map +1 -0
  64. package/dist/src/spans/types.d.ts +43 -0
  65. package/dist/src/spans/types.d.ts.map +1 -0
  66. package/dist/src/spans/types.js +22 -0
  67. package/dist/src/spans/types.js.map +1 -0
  68. package/dist/src/types/annotations.d.ts +2 -1
  69. package/dist/src/types/annotations.d.ts.map +1 -1
  70. package/dist/src/types/experiments.d.ts +1 -7
  71. package/dist/src/types/experiments.d.ts.map +1 -1
  72. package/dist/src/utils/formatPromptMessages.d.ts +3 -1
  73. package/dist/src/utils/formatPromptMessages.d.ts.map +1 -1
  74. package/dist/src/utils/getPromptBySelector.d.ts.map +1 -1
  75. package/dist/tsconfig.tsbuildinfo +1 -1
  76. package/package.json +8 -2
  77. package/src/__generated__/api/v1.ts +1809 -295
  78. package/src/experiments/runExperiment.ts +211 -74
  79. package/src/spans/addSpanAnnotation.ts +59 -0
  80. package/src/spans/index.ts +2 -0
  81. package/src/spans/logSpanAnnotations.ts +71 -0
  82. package/src/spans/types.ts +60 -0
  83. package/src/types/annotations.ts +4 -1
  84. package/src/types/experiments.ts +1 -7
@@ -0,0 +1,44 @@
1
+ import { createClient } from "../client.js";
2
+ import { toSpanAnnotationData } from "./types.js";
3
+ /**
4
+ * Add an annotation to a span.
5
+ *
6
+ * The annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, and metadata.
7
+ * If an identifier is provided and an annotation with that identifier already exists, it will be updated.
8
+ *
9
+ * @param params - The parameters to add a span annotation
10
+ * @returns The ID of the created or updated annotation
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const result = await addSpanAnnotation({
15
+ * spanAnnotation: {
16
+ * spanId: "123abc",
17
+ * name: "quality_score",
18
+ * label: "good",
19
+ * score: 0.95,
20
+ * annotatorKind: "LLM",
21
+ * identifier: "custom_id_123",
22
+ * metadata: {
23
+ * model: "gpt-4"
24
+ * }
25
+ * }
26
+ * });
27
+ * ```
28
+ */
29
+ export async function addSpanAnnotation({ client: _client, spanAnnotation, }) {
30
+ const client = _client ?? createClient();
31
+ const { data, error } = await client.POST("/v1/span_annotations", {
32
+ body: {
33
+ data: [toSpanAnnotationData(spanAnnotation)],
34
+ },
35
+ });
36
+ if (error) {
37
+ throw new Error(`Failed to add span annotation: ${error}`);
38
+ }
39
+ if (!data?.data?.[0]?.id) {
40
+ throw new Error("No annotation ID returned from server");
41
+ }
42
+ return data.data[0];
43
+ }
44
+ //# sourceMappingURL=addSpanAnnotation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addSpanAnnotation.js","sourceRoot":"","sources":["../../../src/spans/addSpanAnnotation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAkB,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAS/D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,EACtC,MAAM,EAAE,OAAO,EACf,cAAc,GACU;IACxB,MAAM,MAAM,GAAG,OAAO,IAAI,YAAY,EAAE,CAAC;IAEzC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE;QAChE,IAAI,EAAE;YACJ,IAAI,EAAE,CAAC,oBAAoB,CAAC,cAAc,CAAC,CAAC;SAC7C;KACF,CAAC,CAAC;IAEH,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,kCAAkC,KAAK,EAAE,CAAC,CAAC;IAC7D,CAAC;IAED,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACtB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./addSpanAnnotation.js";
2
+ export * from "./logSpanAnnotations.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/spans/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from "./addSpanAnnotation.js";
2
+ export * from "./logSpanAnnotations.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/spans/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { ClientFn } from "../types/core.js";
2
+ import { SpanAnnotation } from "./types.js";
3
+ /**
4
+ * Parameters to log multiple span annotations
5
+ */
6
+ interface LogSpanAnnotationsParams extends ClientFn {
7
+ /**
8
+ * The span annotations to log
9
+ */
10
+ spanAnnotations: SpanAnnotation[];
11
+ }
12
+ /**
13
+ * Log multiple span annotations in a single request.
14
+ *
15
+ * Each annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, and metadata.
16
+ * If an identifier is provided and an annotation with that identifier already exists, it will be updated.
17
+ *
18
+ * @param params - The parameters to log span annotations
19
+ * @returns The IDs of the created or updated annotations
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * const results = await logSpanAnnotations({
24
+ * spanAnnotations: [
25
+ * {
26
+ * spanId: "123abc",
27
+ * name: "quality_score",
28
+ * label: "good",
29
+ * score: 0.95,
30
+ * annotatorKind: "LLM",
31
+ * identifier: "custom_id_123",
32
+ * metadata: {
33
+ * model: "gpt-4"
34
+ * }
35
+ * },
36
+ * {
37
+ * spanId: "456def",
38
+ * name: "sentiment",
39
+ * label: "positive",
40
+ * score: 0.8,
41
+ * annotatorKind: "CODE"
42
+ * }
43
+ * ]
44
+ * });
45
+ * ```
46
+ */
47
+ export declare function logSpanAnnotations({ client: _client, spanAnnotations, }: LogSpanAnnotationsParams): Promise<{
48
+ id: string;
49
+ }[]>;
50
+ export {};
51
+ //# sourceMappingURL=logSpanAnnotations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logSpanAnnotations.d.ts","sourceRoot":"","sources":["../../../src/spans/logSpanAnnotations.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAwB,MAAM,SAAS,CAAC;AAE/D;;GAEG;AACH,UAAU,wBAAyB,SAAQ,QAAQ;IACjD;;OAEG;IACH,eAAe,EAAE,cAAc,EAAE,CAAC;CACnC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAsB,kBAAkB,CAAC,EACvC,MAAM,EAAE,OAAO,EACf,eAAe,GAChB,EAAE,wBAAwB,GAAG,OAAO,CAAC;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,CAAC,CAkBtD"}
@@ -0,0 +1,53 @@
1
+ import { createClient } from "../client.js";
2
+ import { toSpanAnnotationData } from "./types.js";
3
+ /**
4
+ * Log multiple span annotations in a single request.
5
+ *
6
+ * Each annotation can be of type "LLM", "CODE", or "HUMAN" and can include a label, score, and metadata.
7
+ * If an identifier is provided and an annotation with that identifier already exists, it will be updated.
8
+ *
9
+ * @param params - The parameters to log span annotations
10
+ * @returns The IDs of the created or updated annotations
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * const results = await logSpanAnnotations({
15
+ * spanAnnotations: [
16
+ * {
17
+ * spanId: "123abc",
18
+ * name: "quality_score",
19
+ * label: "good",
20
+ * score: 0.95,
21
+ * annotatorKind: "LLM",
22
+ * identifier: "custom_id_123",
23
+ * metadata: {
24
+ * model: "gpt-4"
25
+ * }
26
+ * },
27
+ * {
28
+ * spanId: "456def",
29
+ * name: "sentiment",
30
+ * label: "positive",
31
+ * score: 0.8,
32
+ * annotatorKind: "CODE"
33
+ * }
34
+ * ]
35
+ * });
36
+ * ```
37
+ */
38
+ export async function logSpanAnnotations({ client: _client, spanAnnotations, }) {
39
+ const client = _client ?? createClient();
40
+ const { data, error } = await client.POST("/v1/span_annotations", {
41
+ body: {
42
+ data: spanAnnotations.map(toSpanAnnotationData),
43
+ },
44
+ });
45
+ if (error) {
46
+ throw new Error(`Failed to log span annotations: ${error}`);
47
+ }
48
+ if (!data?.data?.length) {
49
+ throw new Error("No annotation IDs returned from server");
50
+ }
51
+ return data.data;
52
+ }
53
+ //# sourceMappingURL=logSpanAnnotations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logSpanAnnotations.js","sourceRoot":"","sources":["../../../src/spans/logSpanAnnotations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAkB,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAY/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,EACvC,MAAM,EAAE,OAAO,EACf,eAAe,GACU;IACzB,MAAM,MAAM,GAAG,OAAO,IAAI,YAAY,EAAE,CAAC;IAEzC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,sBAAsB,EAAE;QAChE,IAAI,EAAE;YACJ,IAAI,EAAE,eAAe,CAAC,GAAG,CAAC,oBAAoB,CAAC;SAChD;KACF,CAAC,CAAC;IAEH,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CAAC,mCAAmC,KAAK,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { paths } from "../__generated__/api/v1.js";
2
+ type SpanAnnotationData = paths["/v1/span_annotations"]["post"]["requestBody"]["content"]["application/json"]["data"][0];
3
+ /**
4
+ * Parameters for a single span annotation
5
+ */
6
+ export interface SpanAnnotation {
7
+ /**
8
+ * The OpenTelemetry Span ID (hex format without 0x prefix)
9
+ */
10
+ spanId: string;
11
+ /**
12
+ * The name of the annotation
13
+ */
14
+ name: string;
15
+ /**
16
+ * The label assigned by the annotation
17
+ */
18
+ label?: string;
19
+ /**
20
+ * The score assigned by the annotation
21
+ */
22
+ score?: number;
23
+ /**
24
+ * The identifier of the annotation. If provided, the annotation will be updated if it already exists.
25
+ */
26
+ identifier?: string;
27
+ /**
28
+ * Metadata for the annotation
29
+ */
30
+ metadata?: Record<string, unknown>;
31
+ /**
32
+ * The kind of annotator used for the annotation
33
+ * Can be "HUMAN", "LLM", or "CODE"
34
+ * @default "HUMAN"
35
+ */
36
+ annotatorKind?: SpanAnnotationData["annotator_kind"];
37
+ }
38
+ /**
39
+ * Convert a SpanAnnotation to the API format
40
+ */
41
+ export declare function toSpanAnnotationData(annotation: SpanAnnotation): SpanAnnotationData;
42
+ export {};
43
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/spans/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAEhD,KAAK,kBAAkB,GACrB,KAAK,CAAC,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjG;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC;;;;OAIG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;CACtD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,cAAc,GACzB,kBAAkB,CAapB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Convert a SpanAnnotation to the API format
3
+ */
4
+ export function toSpanAnnotationData(annotation) {
5
+ return {
6
+ span_id: annotation.spanId,
7
+ name: annotation.name,
8
+ annotator_kind: annotation.annotatorKind ?? "HUMAN",
9
+ result: {
10
+ label: annotation.label ?? null,
11
+ score: annotation.score ?? null,
12
+ explanation: null,
13
+ },
14
+ metadata: annotation.metadata ?? null,
15
+ identifier: annotation.identifier ?? "",
16
+ };
17
+ }
18
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/spans/types.ts"],"names":[],"mappings":"AAyCA;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAA0B;IAE1B,OAAO;QACL,OAAO,EAAE,UAAU,CAAC,MAAM;QAC1B,IAAI,EAAE,UAAU,CAAC,IAAI;QACrB,cAAc,EAAE,UAAU,CAAC,aAAa,IAAI,OAAO;QACnD,MAAM,EAAE;YACN,KAAK,EAAE,UAAU,CAAC,KAAK,IAAI,IAAI;YAC/B,KAAK,EAAE,UAAU,CAAC,KAAK,IAAI,IAAI;YAC/B,WAAW,EAAE,IAAI;SAClB;QACD,QAAQ,EAAE,UAAU,CAAC,QAAQ,IAAI,IAAI;QACrC,UAAU,EAAE,UAAU,CAAC,UAAU,IAAI,EAAE;KACxC,CAAC;AACJ,CAAC"}