@arizeai/phoenix-client 3.2.0 → 4.0.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 (55) hide show
  1. package/dist/esm/prompts/sdks/toAI.d.ts +13 -3
  2. package/dist/esm/prompts/sdks/toAI.d.ts.map +1 -1
  3. package/dist/esm/prompts/sdks/toAI.js +23 -15
  4. package/dist/esm/prompts/sdks/toAI.js.map +1 -1
  5. package/dist/esm/prompts/sdks/toSDK.d.ts +1 -1
  6. package/dist/esm/schemas/llm/constants.d.ts +30 -12
  7. package/dist/esm/schemas/llm/constants.d.ts.map +1 -1
  8. package/dist/esm/schemas/llm/converters.d.ts +120 -48
  9. package/dist/esm/schemas/llm/converters.d.ts.map +1 -1
  10. package/dist/esm/schemas/llm/openai/converters.d.ts +6 -3
  11. package/dist/esm/schemas/llm/openai/converters.d.ts.map +1 -1
  12. package/dist/esm/schemas/llm/openai/converters.js +7 -4
  13. package/dist/esm/schemas/llm/openai/converters.js.map +1 -1
  14. package/dist/esm/schemas/llm/schemas.d.ts +37 -16
  15. package/dist/esm/schemas/llm/schemas.d.ts.map +1 -1
  16. package/dist/esm/schemas/llm/vercel/messagePartSchemas.d.ts +42 -12
  17. package/dist/esm/schemas/llm/vercel/messagePartSchemas.d.ts.map +1 -1
  18. package/dist/esm/schemas/llm/vercel/messagePartSchemas.js +5 -2
  19. package/dist/esm/schemas/llm/vercel/messagePartSchemas.js.map +1 -1
  20. package/dist/esm/schemas/llm/vercel/messageSchemas.d.ts +31 -10
  21. package/dist/esm/schemas/llm/vercel/messageSchemas.d.ts.map +1 -1
  22. package/dist/esm/schemas/llm/vercel/toolSchemas.d.ts +3 -3
  23. package/dist/esm/schemas/llm/vercel/toolSchemas.js +1 -1
  24. package/dist/esm/schemas/llm/vercel/toolSchemas.js.map +1 -1
  25. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  26. package/dist/src/prompts/sdks/toAI.d.ts +13 -3
  27. package/dist/src/prompts/sdks/toAI.d.ts.map +1 -1
  28. package/dist/src/prompts/sdks/toAI.js +24 -16
  29. package/dist/src/prompts/sdks/toAI.js.map +1 -1
  30. package/dist/src/prompts/sdks/toSDK.d.ts +1 -1
  31. package/dist/src/schemas/llm/constants.d.ts +30 -12
  32. package/dist/src/schemas/llm/constants.d.ts.map +1 -1
  33. package/dist/src/schemas/llm/converters.d.ts +120 -48
  34. package/dist/src/schemas/llm/converters.d.ts.map +1 -1
  35. package/dist/src/schemas/llm/openai/converters.d.ts +6 -3
  36. package/dist/src/schemas/llm/openai/converters.d.ts.map +1 -1
  37. package/dist/src/schemas/llm/openai/converters.js +7 -4
  38. package/dist/src/schemas/llm/openai/converters.js.map +1 -1
  39. package/dist/src/schemas/llm/schemas.d.ts +37 -16
  40. package/dist/src/schemas/llm/schemas.d.ts.map +1 -1
  41. package/dist/src/schemas/llm/vercel/messagePartSchemas.d.ts +42 -12
  42. package/dist/src/schemas/llm/vercel/messagePartSchemas.d.ts.map +1 -1
  43. package/dist/src/schemas/llm/vercel/messagePartSchemas.js +5 -2
  44. package/dist/src/schemas/llm/vercel/messagePartSchemas.js.map +1 -1
  45. package/dist/src/schemas/llm/vercel/messageSchemas.d.ts +31 -10
  46. package/dist/src/schemas/llm/vercel/messageSchemas.d.ts.map +1 -1
  47. package/dist/src/schemas/llm/vercel/toolSchemas.d.ts +3 -3
  48. package/dist/src/schemas/llm/vercel/toolSchemas.js +1 -1
  49. package/dist/src/schemas/llm/vercel/toolSchemas.js.map +1 -1
  50. package/dist/tsconfig.tsbuildinfo +1 -1
  51. package/package.json +4 -4
  52. package/src/prompts/sdks/toAI.ts +42 -32
  53. package/src/schemas/llm/openai/converters.ts +7 -4
  54. package/src/schemas/llm/vercel/messagePartSchemas.ts +5 -2
  55. package/src/schemas/llm/vercel/toolSchemas.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arizeai/phoenix-client",
3
- "version": "3.2.0",
3
+ "version": "4.0.0",
4
4
  "description": "A client for the Phoenix API",
5
5
  "main": "dist/src/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -53,11 +53,11 @@
53
53
  "author": "oss@arize.com",
54
54
  "license": "ELv2",
55
55
  "devDependencies": {
56
- "@ai-sdk/openai": "^1.1.15",
56
+ "@ai-sdk/openai": "^2.0.27",
57
57
  "@anthropic-ai/sdk": "^0.35.0",
58
58
  "@types/async": "^3.2.24",
59
59
  "@types/node": "^20.17.22",
60
- "ai": "^4.1.24",
60
+ "ai": "^5.0.38",
61
61
  "openai": "^4.77.0",
62
62
  "openapi-typescript": "^7.6.1",
63
63
  "tsx": "^4.19.3",
@@ -84,7 +84,7 @@
84
84
  },
85
85
  "optionalDependencies": {
86
86
  "@anthropic-ai/sdk": "^0.35.0",
87
- "ai": "^4.1.47",
87
+ "ai": "^5.0.38",
88
88
  "openai": "^5.12.1"
89
89
  },
90
90
  "scripts": {
@@ -2,22 +2,23 @@ import invariant from "tiny-invariant";
2
2
  import {
3
3
  safelyConvertMessageToProvider,
4
4
  safelyConvertToolChoiceToProvider,
5
- safelyConvertToolDefinitionToProvider,
6
5
  } from "../../schemas/llm/converters";
7
6
  import { formatPromptMessages } from "../../utils/formatPromptMessages";
8
7
  import { Variables, toSDKParamsBase } from "./types";
9
- import {
10
- type streamText,
11
- type generateText,
12
- type ToolSet,
13
- type Tool,
14
- } from "ai";
8
+ import { type ToolSet, type ModelMessage, type ToolChoice } from "ai";
15
9
  import { VercelAIToolChoice } from "../../schemas/llm/vercel/toolChoiceSchemas";
16
10
 
17
- export type PartialStreamTextParams = Omit<
18
- Parameters<typeof streamText>[0] | Parameters<typeof generateText>[0],
19
- "model"
20
- >;
11
+ export type PartialAIParams = {
12
+ messages: ModelMessage[];
13
+ /**
14
+ The tools that the model can call. The model needs to support calling tools.
15
+ */
16
+ tools?: ToolSet;
17
+ /**
18
+ The tool choice strategy. Default: 'auto'.
19
+ */
20
+ toolChoice?: ToolChoice<ToolSet>;
21
+ };
21
22
 
22
23
  export type ToAIParams<V extends Variables> = toSDKParamsBase<V>;
23
24
 
@@ -30,16 +31,16 @@ export type ToAIParams<V extends Variables> = toSDKParamsBase<V>;
30
31
  export const toAI = <V extends Variables>({
31
32
  prompt,
32
33
  variables,
33
- }: ToAIParams<V>): PartialStreamTextParams | null => {
34
+ }: ToAIParams<V>): PartialAIParams | null => {
34
35
  // eslint-disable-next-line no-console
35
36
  console.warn(
36
37
  "Prompt invocation parameters not currently supported in AI SDK, falling back to default invocation parameters"
37
38
  );
38
39
  try {
39
40
  // parts of the prompt that can be directly converted to OpenAI params
40
- const baseCompletionParams = {
41
+ const baseCompletionParams: Partial<PartialAIParams> = {
41
42
  // Invocation parameters are validated on the phoenix-side
42
- } satisfies Partial<PartialStreamTextParams>;
43
+ };
43
44
 
44
45
  if (!("messages" in prompt.template)) {
45
46
  return null;
@@ -55,7 +56,7 @@ export const toAI = <V extends Variables>({
55
56
  );
56
57
  }
57
58
 
58
- const messages = formattedMessages.map((message) => {
59
+ const messages: ModelMessage[] = formattedMessages.map((message) => {
59
60
  const vercelAIMessage = safelyConvertMessageToProvider({
60
61
  message,
61
62
  targetProvider: "VERCEL_AI",
@@ -65,21 +66,30 @@ export const toAI = <V extends Variables>({
65
66
  });
66
67
 
67
68
  // convert tools to Vercel AI tool set, which is a map of tool name to tool
68
- let tools: ToolSet | undefined = prompt.tools?.tools.reduce((acc, tool) => {
69
- if (!tool.function.parameters) {
70
- return acc;
71
- }
72
- const vercelAIToolDefinition = safelyConvertToolDefinitionToProvider({
73
- toolDefinition: tool,
74
- targetProvider: "VERCEL_AI",
75
- });
76
- invariant(vercelAIToolDefinition, "Tool definition is not valid");
77
- acc[tool.function.name] = vercelAIToolDefinition satisfies Tool;
78
- return acc;
79
- }, {} as ToolSet);
80
- const hasTools = Object.keys(tools ?? {}).length > 0;
81
- tools = hasTools ? tools : undefined;
82
-
69
+ // TODO: Vercel AI SDK 5 has complex tool schema
70
+ // let tools: ToolSet | undefined = prompt.tools?.tools.reduce((acc, tool) => {
71
+ // if (!tool.function.parameters) {
72
+ // return acc;
73
+ // }
74
+ // const vercelAIToolDefinition = safelyConvertToolDefinitionToProvider({
75
+ // toolDefinition: tool,
76
+ // targetProvider: "VERCEL_AI",
77
+ // });
78
+ // invariant(vercelAIToolDefinition, "Tool definition is not valid");
79
+ // // TODO: get the symbol working here for validators
80
+ // acc[tool.function.name] = vercelAIToolDefinition as unknown as Tool;
81
+ // return acc;
82
+ // }, {} as ToolSet);
83
+ // const hasTools = Object.keys(tools ?? {}).length > 0;
84
+ // tools = hasTools ? tools : undefined;
85
+ const hasTools = false;
86
+ const tools = undefined;
87
+ if (prompt.tools?.tools && prompt.tools?.tools.length) {
88
+ // eslint-disable-next-line no-console
89
+ console.warn(
90
+ "Prompt tools not currently supported in the AI SDK, falling back to no tools"
91
+ );
92
+ }
83
93
  let toolChoice: VercelAIToolChoice | undefined =
84
94
  safelyConvertToolChoiceToProvider({
85
95
  toolChoice: prompt.tools?.tool_choice,
@@ -88,12 +98,12 @@ export const toAI = <V extends Variables>({
88
98
  toolChoice = hasTools ? toolChoice : undefined;
89
99
 
90
100
  // combine base and computed params
91
- const completionParams = {
101
+ const completionParams: PartialAIParams = {
92
102
  ...baseCompletionParams,
93
103
  messages,
94
104
  tools,
95
105
  toolChoice,
96
- } satisfies Partial<PartialStreamTextParams>;
106
+ };
97
107
 
98
108
  return completionParams;
99
109
  } catch (error) {
@@ -272,7 +272,7 @@ export const openAIMessageToVercelAI = openAIMessageSchema.transform(
272
272
  type: "tool-call",
273
273
  toolCallId: tc.id,
274
274
  toolName: tc.function.name,
275
- args: tc.function.arguments,
275
+ input: tc.function.arguments,
276
276
  });
277
277
  });
278
278
  }
@@ -289,7 +289,7 @@ export const openAIMessageToVercelAI = openAIMessageSchema.transform(
289
289
  type: "tool-result",
290
290
  toolCallId: openai.tool_call_id,
291
291
  toolName: "", // We don't have this??
292
- result: openai.content,
292
+ output: { type: "text", value: openai.content },
293
293
  });
294
294
  } else {
295
295
  openai.content.forEach((part) => {
@@ -298,7 +298,10 @@ export const openAIMessageToVercelAI = openAIMessageSchema.transform(
298
298
  type: "tool-result",
299
299
  toolCallId: openai.tool_call_id,
300
300
  toolName: "", // We don't have this??
301
- result: part.text,
301
+ output: {
302
+ type: "text",
303
+ value: part.text,
304
+ },
302
305
  });
303
306
  return;
304
307
  }
@@ -391,7 +394,7 @@ export const openAIToolDefinitionToVercelAI =
391
394
  (openai): VercelAIToolDefinition => ({
392
395
  type: "function",
393
396
  description: openai.function.description,
394
- parameters: {
397
+ inputSchema: {
395
398
  _type: undefined,
396
399
  jsonSchema: openai.function.parameters,
397
400
  validate: undefined,
@@ -26,7 +26,7 @@ export const vercelAIChatPartToolCallSchema = z.object({
26
26
  type: z.literal("tool-call"),
27
27
  toolCallId: z.string(),
28
28
  toolName: z.string(),
29
- args: jsonLiteralSchema, // json serializable parameters
29
+ input: jsonLiteralSchema, // json serializable parameters
30
30
  });
31
31
 
32
32
  export type VercelAIChatPartToolCall = z.infer<
@@ -37,7 +37,10 @@ export const vercelAIChatPartToolResultSchema = z.object({
37
37
  type: z.literal("tool-result"),
38
38
  toolCallId: z.string(),
39
39
  toolName: z.string(),
40
- result: jsonLiteralSchema, // json serializable result
40
+ output: z.object({
41
+ type: z.literal("text"), // TODO: extend to support other output types
42
+ value: z.string(),
43
+ }),
41
44
  });
42
45
 
43
46
  export type VercelAIChatPartToolResult = z.infer<
@@ -9,7 +9,7 @@ import { z } from "zod";
9
9
  export const vercelAIToolDefinitionSchema = z.object({
10
10
  type: z.literal("function"),
11
11
  description: z.string().optional(),
12
- parameters: z.object({
12
+ inputSchema: z.object({
13
13
  _type: z.unknown().optional().default(undefined),
14
14
  validate: z.unknown().optional().default(undefined),
15
15
  jsonSchema: z.record(z.string(), z.unknown()).optional(),