ai 3.3.8 → 3.3.9

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai",
3
- "version": "3.3.8",
3
+ "version": "3.3.9",
4
4
  "description": "Vercel AI SDK - The AI Toolkit for TypeScript and JavaScript",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -58,13 +58,13 @@
58
58
  }
59
59
  },
60
60
  "dependencies": {
61
- "@ai-sdk/provider": "0.0.19",
62
- "@ai-sdk/provider-utils": "1.0.12",
63
- "@ai-sdk/react": "0.0.44",
64
- "@ai-sdk/solid": "0.0.35",
65
- "@ai-sdk/svelte": "0.0.37",
66
- "@ai-sdk/ui-utils": "0.0.32",
67
- "@ai-sdk/vue": "0.0.36",
61
+ "@ai-sdk/provider": "0.0.20",
62
+ "@ai-sdk/provider-utils": "1.0.13",
63
+ "@ai-sdk/react": "0.0.45",
64
+ "@ai-sdk/solid": "0.0.36",
65
+ "@ai-sdk/svelte": "0.0.38",
66
+ "@ai-sdk/ui-utils": "0.0.33",
67
+ "@ai-sdk/vue": "0.0.37",
68
68
  "@opentelemetry/api": "1.9.0",
69
69
  "eventsource-parser": "1.1.2",
70
70
  "jsondiffpatch": "0.6.0",
@@ -4,12 +4,16 @@ import { Message } from '@ai-sdk/ui-utils';
4
4
  * A prompt constructor for Anthropic models.
5
5
  * Does not support `function` messages.
6
6
  * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api
7
+ *
8
+ * @deprecated Will be removed. Use the new provider architecture instead.
7
9
  */
8
10
  declare function experimental_buildAnthropicPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
9
11
  /**
10
12
  * A prompt constructor for Anthropic V3 models which require Messages API.
11
13
  * Does not support message with image content
12
14
  * @see https://docs.anthropic.com/claude/reference/messages_post
15
+ *
16
+ * @deprecated Will be removed. Use the new provider architecture instead.
13
17
  */
14
18
  declare function experimental_buildAnthropicMessages(messages: Pick<Message, 'content' | 'role'>[]): {
15
19
  role: "function" | "data" | "system" | "user" | "assistant" | "tool";
@@ -22,22 +26,29 @@ declare function experimental_buildAnthropicMessages(messages: Pick<Message, 'co
22
26
  /**
23
27
  * A prompt constructor for the HuggingFace StarChat Beta model.
24
28
  * Does not support `function` messages.
25
- * @see https://huggingface.co/HuggingFaceH4/starchat-beta
29
+ * @see https://huggingface.co/HuggingFaceH4/starchat-beta *
30
+ * @deprecated Will be removed. Use the new provider architecture instead.
26
31
  */
27
32
  declare function experimental_buildStarChatBetaPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
28
33
  /**
29
34
  * A prompt constructor for HuggingFace OpenAssistant models.
30
35
  * Does not support `function` or `system` messages.
31
- * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5
36
+ * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5 *
37
+ * @deprecated Will be removed. Use the new provider architecture instead.
32
38
  */
33
39
  declare function experimental_buildOpenAssistantPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
34
40
  /**
35
41
  * A prompt constructor for HuggingFace LLama 2 chat models.
36
42
  * Does not support `function` messages.
37
43
  * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2
44
+ *
45
+ * @deprecated Will be removed. Use the new provider architecture instead.
38
46
  */
39
47
  declare function experimental_buildLlama2Prompt(messages: Pick<Message, 'content' | 'role'>[]): string;
40
48
 
49
+ /**
50
+ * @deprecated Will be removed. Use the new provider architecture instead.
51
+ */
41
52
  declare function experimental_buildOpenAIMessages(messages: Message[]): ChatCompletionMessageParam[];
42
53
  type ChatCompletionMessageParam = ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam;
43
54
  interface ChatCompletionSystemMessageParam {
@@ -4,12 +4,16 @@ import { Message } from '@ai-sdk/ui-utils';
4
4
  * A prompt constructor for Anthropic models.
5
5
  * Does not support `function` messages.
6
6
  * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api
7
+ *
8
+ * @deprecated Will be removed. Use the new provider architecture instead.
7
9
  */
8
10
  declare function experimental_buildAnthropicPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
9
11
  /**
10
12
  * A prompt constructor for Anthropic V3 models which require Messages API.
11
13
  * Does not support message with image content
12
14
  * @see https://docs.anthropic.com/claude/reference/messages_post
15
+ *
16
+ * @deprecated Will be removed. Use the new provider architecture instead.
13
17
  */
14
18
  declare function experimental_buildAnthropicMessages(messages: Pick<Message, 'content' | 'role'>[]): {
15
19
  role: "function" | "data" | "system" | "user" | "assistant" | "tool";
@@ -22,22 +26,29 @@ declare function experimental_buildAnthropicMessages(messages: Pick<Message, 'co
22
26
  /**
23
27
  * A prompt constructor for the HuggingFace StarChat Beta model.
24
28
  * Does not support `function` messages.
25
- * @see https://huggingface.co/HuggingFaceH4/starchat-beta
29
+ * @see https://huggingface.co/HuggingFaceH4/starchat-beta *
30
+ * @deprecated Will be removed. Use the new provider architecture instead.
26
31
  */
27
32
  declare function experimental_buildStarChatBetaPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
28
33
  /**
29
34
  * A prompt constructor for HuggingFace OpenAssistant models.
30
35
  * Does not support `function` or `system` messages.
31
- * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5
36
+ * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5 *
37
+ * @deprecated Will be removed. Use the new provider architecture instead.
32
38
  */
33
39
  declare function experimental_buildOpenAssistantPrompt(messages: Pick<Message, 'content' | 'role'>[]): string;
34
40
  /**
35
41
  * A prompt constructor for HuggingFace LLama 2 chat models.
36
42
  * Does not support `function` messages.
37
43
  * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2
44
+ *
45
+ * @deprecated Will be removed. Use the new provider architecture instead.
38
46
  */
39
47
  declare function experimental_buildLlama2Prompt(messages: Pick<Message, 'content' | 'role'>[]): string;
40
48
 
49
+ /**
50
+ * @deprecated Will be removed. Use the new provider architecture instead.
51
+ */
41
52
  declare function experimental_buildOpenAIMessages(messages: Message[]): ChatCompletionMessageParam[];
42
53
  type ChatCompletionMessageParam = ChatCompletionSystemMessageParam | ChatCompletionUserMessageParam | ChatCompletionAssistantMessageParam | ChatCompletionToolMessageParam | ChatCompletionFunctionMessageParam;
43
54
  interface ChatCompletionSystemMessageParam {
@@ -1 +1 @@
1
- {"version":3,"sources":["../index.ts","../anthropic.ts","../huggingface.ts","../openai.tsx"],"sourcesContent":["export * from './anthropic';\nexport * from './huggingface';\nexport * from './openai';\n","import { Message } from '@ai-sdk/ui-utils';\n\n/**\n * A prompt constructor for Anthropic models.\n * Does not support `function` messages.\n * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api\n */\nexport function experimental_buildAnthropicPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages.map(({ content, role }) => {\n if (role === 'user') {\n return `\\n\\nHuman: ${content}`;\n } else {\n return `\\n\\nAssistant: ${content}`;\n }\n }) + '\\n\\nAssistant:'\n );\n}\n\n/**\n * A prompt constructor for Anthropic V3 models which require Messages API.\n * Does not support message with image content\n * @see https://docs.anthropic.com/claude/reference/messages_post\n */\nexport function experimental_buildAnthropicMessages(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return messages.map(({ content, role }) => {\n if (!['assistant', 'user'].includes(role)) {\n throw new Error(`Cannot use ${role} on Anthropic V3 Messages API`);\n }\n return {\n role,\n content: [{ type: 'text', text: content }],\n };\n });\n}\n","import { Message } from '@ai-sdk/ui-utils';\n\n/**\n * A prompt constructor for the HuggingFace StarChat Beta model.\n * Does not support `function` messages.\n * @see https://huggingface.co/HuggingFaceH4/starchat-beta\n */\nexport function experimental_buildStarChatBetaPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|user|>\\n${content}<|end|>\\n`;\n } else if (role === 'assistant') {\n return `<|assistant|>\\n${content}<|end|>\\n`;\n } else if (role === 'system') {\n return `<|system|>\\n${content}<|end|>\\n`;\n } else if (role === 'function') {\n throw new Error('StarChat Beta does not support function calls.');\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace OpenAssistant models.\n * Does not support `function` or `system` messages.\n * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5\n */\nexport function experimental_buildOpenAssistantPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|prompter|>${content}<|endoftext|>`;\n } else if (role === 'function') {\n throw new Error('OpenAssistant does not support function calls.');\n } else if (role === 'system') {\n throw new Error('OpenAssistant does not support system messages.');\n } else {\n return `<|assistant|>${content}<|endoftext|>`;\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace LLama 2 chat models.\n * Does not support `function` messages.\n * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2\n */\nexport function experimental_buildLlama2Prompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n const startPrompt = `<s>[INST] `;\n const endPrompt = ` [/INST]`;\n const conversation = messages.map(({ content, role }, index) => {\n if (role === 'user') {\n return content.trim();\n } else if (role === 'assistant') {\n return ` [/INST] ${content}</s><s>[INST] `;\n } else if (role === 'function') {\n throw new Error('Llama 2 does not support function calls.');\n } else if (role === 'system' && index === 0) {\n return `<<SYS>>\\n${content}\\n<</SYS>>\\n\\n`;\n } else {\n throw new Error(`Invalid message role: ${role}`);\n }\n });\n\n return startPrompt + conversation.join('') + endPrompt;\n}\n","import { Message } from '@ai-sdk/ui-utils';\n\nexport function experimental_buildOpenAIMessages(\n messages: Message[],\n): ChatCompletionMessageParam[] {\n return messages.map(message => {\n switch (message.role) {\n case 'system':\n case 'user':\n return {\n role: message.role,\n content: message.content,\n } satisfies ChatCompletionMessageParam;\n\n case 'assistant': {\n const function_call = message.function_call;\n\n if (\n function_call !== undefined &&\n (typeof function_call === 'string' ||\n function_call.arguments === undefined ||\n function_call.name === undefined)\n ) {\n throw new Error(\n 'Invalid function call in message. Expected a function call object',\n );\n }\n\n return {\n role: message.role,\n content: message.content,\n function_call:\n function_call === undefined\n ? undefined\n : {\n name: function_call.name!,\n arguments: function_call.arguments!,\n },\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'function': {\n if (message.name === undefined) {\n throw new Error('Invalid function call in message. Expected a name');\n }\n\n return {\n role: message.role,\n content: message.content,\n name: message.name,\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'data': {\n throw \"unsupported message role 'data'\";\n }\n\n case 'tool': {\n if (message.name === undefined) {\n throw new Error('Invalid tool message. Expected a name');\n }\n\n if (message.tool_call_id === undefined) {\n throw new Error('Invalid tool message. Expected a tool_call_id');\n }\n\n return {\n role: message.role,\n content: message.content,\n tool_call_id: message.tool_call_id,\n } satisfies ChatCompletionMessageParam;\n }\n }\n });\n}\n\n// copy of open ai messages (so we don't have a dependency on the openai package)\nexport type ChatCompletionMessageParam =\n | ChatCompletionSystemMessageParam\n | ChatCompletionUserMessageParam\n | ChatCompletionAssistantMessageParam\n | ChatCompletionToolMessageParam\n | ChatCompletionFunctionMessageParam;\n\nexport interface ChatCompletionSystemMessageParam {\n /**\n * The contents of the system message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `system`.\n */\n role: 'system';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport interface ChatCompletionUserMessageParam {\n /**\n * The contents of the user message.\n */\n content: string | Array<ChatCompletionContentPart>;\n\n /**\n * The role of the messages author, in this case `user`.\n */\n role: 'user';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport type ChatCompletionContentPart =\n | ChatCompletionContentPartText\n | ChatCompletionContentPartImage;\n\nexport interface ChatCompletionContentPartText {\n /**\n * The text content.\n */\n text: string;\n\n /**\n * The type of the content part.\n */\n type: 'text';\n}\n\nexport interface ChatCompletionContentPartImage {\n image_url: ChatCompletionContentPartImage.ImageURL;\n\n /**\n * The type of the content part.\n */\n type: 'image_url';\n}\n\nexport namespace ChatCompletionContentPartImage {\n export interface ImageURL {\n /**\n * Either a URL of the image or the base64 encoded image data.\n */\n url: string;\n\n /**\n * Specifies the detail level of the image. Learn more in the\n * [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).\n */\n detail?: 'auto' | 'low' | 'high';\n }\n}\n\nexport interface ChatCompletionAssistantMessageParam {\n /**\n * The role of the messages author, in this case `assistant`.\n */\n role: 'assistant';\n\n /**\n * The contents of the assistant message. Required unless `tool_calls` or\n * `function_call` is specified.\n */\n content?: string | null;\n\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n function_call?: ChatCompletionAssistantMessageParam.FunctionCall;\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n\n /**\n * The tool calls generated by the model, such as function calls.\n */\n tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionAssistantMessageParam {\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionMessageToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The function that the model called.\n */\n function: ChatCompletionMessageToolCall.Function;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: 'function';\n}\n\nexport namespace ChatCompletionMessageToolCall {\n /**\n * The function that the model called.\n */\n export interface Function {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionToolMessageParam {\n /**\n * The contents of the tool message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `tool`.\n */\n role: 'tool';\n\n /**\n * Tool call that this message is responding to.\n */\n tool_call_id: string;\n}\n\nexport interface ChatCompletionFunctionMessageParam {\n /**\n * The return value from the function call, to return to the model.\n */\n content: string | null;\n\n /**\n * The name of the function to call.\n */\n name: string;\n\n /**\n * The role of the messages author, in this case `function`.\n */\n role: 'function';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,SAAS,kCACd,UACA;AACA,SACE,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAClC,QAAI,SAAS,QAAQ;AACnB,aAAO;AAAA;AAAA,SAAc,OAAO;AAAA,IAC9B,OAAO;AACL,aAAO;AAAA;AAAA,aAAkB,OAAO;AAAA,IAClC;AAAA,EACF,CAAC,IAAI;AAET;AAOO,SAAS,oCACd,UACA;AACA,SAAO,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AACzC,QAAI,CAAC,CAAC,aAAa,MAAM,EAAE,SAAS,IAAI,GAAG;AACzC,YAAM,IAAI,MAAM,cAAc,IAAI,+BAA+B;AAAA,IACnE;AACA,WAAO;AAAA,MACL;AAAA,MACA,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,IAC3C;AAAA,EACF,CAAC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ts","../huggingface.ts","../openai.tsx"],"sourcesContent":["export * from './anthropic';\nexport * from './huggingface';\nexport * from './openai';\n","import { Message } from '@ai-sdk/ui-utils';\n\n/**\n * A prompt constructor for Anthropic models.\n * Does not support `function` messages.\n * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api\n *\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildAnthropicPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages.map(({ content, role }) => {\n if (role === 'user') {\n return `\\n\\nHuman: ${content}`;\n } else {\n return `\\n\\nAssistant: ${content}`;\n }\n }) + '\\n\\nAssistant:'\n );\n}\n\n/**\n * A prompt constructor for Anthropic V3 models which require Messages API.\n * Does not support message with image content\n * @see https://docs.anthropic.com/claude/reference/messages_post\n *\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildAnthropicMessages(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return messages.map(({ content, role }) => {\n if (!['assistant', 'user'].includes(role)) {\n throw new Error(`Cannot use ${role} on Anthropic V3 Messages API`);\n }\n return {\n role,\n content: [{ type: 'text', text: content }],\n };\n });\n}\n","import { Message } from '@ai-sdk/ui-utils';\n\n/**\n * A prompt constructor for the HuggingFace StarChat Beta model.\n * Does not support `function` messages.\n * @see https://huggingface.co/HuggingFaceH4/starchat-beta *\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildStarChatBetaPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|user|>\\n${content}<|end|>\\n`;\n } else if (role === 'assistant') {\n return `<|assistant|>\\n${content}<|end|>\\n`;\n } else if (role === 'system') {\n return `<|system|>\\n${content}<|end|>\\n`;\n } else if (role === 'function') {\n throw new Error('StarChat Beta does not support function calls.');\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace OpenAssistant models.\n * Does not support `function` or `system` messages.\n * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5 *\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildOpenAssistantPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|prompter|>${content}<|endoftext|>`;\n } else if (role === 'function') {\n throw new Error('OpenAssistant does not support function calls.');\n } else if (role === 'system') {\n throw new Error('OpenAssistant does not support system messages.');\n } else {\n return `<|assistant|>${content}<|endoftext|>`;\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace LLama 2 chat models.\n * Does not support `function` messages.\n * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2\n *\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildLlama2Prompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n const startPrompt = `<s>[INST] `;\n const endPrompt = ` [/INST]`;\n const conversation = messages.map(({ content, role }, index) => {\n if (role === 'user') {\n return content.trim();\n } else if (role === 'assistant') {\n return ` [/INST] ${content}</s><s>[INST] `;\n } else if (role === 'function') {\n throw new Error('Llama 2 does not support function calls.');\n } else if (role === 'system' && index === 0) {\n return `<<SYS>>\\n${content}\\n<</SYS>>\\n\\n`;\n } else {\n throw new Error(`Invalid message role: ${role}`);\n }\n });\n\n return startPrompt + conversation.join('') + endPrompt;\n}\n","import { Message } from '@ai-sdk/ui-utils';\n\n/**\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildOpenAIMessages(\n messages: Message[],\n): ChatCompletionMessageParam[] {\n return messages.map(message => {\n switch (message.role) {\n case 'system':\n case 'user':\n return {\n role: message.role,\n content: message.content,\n } satisfies ChatCompletionMessageParam;\n\n case 'assistant': {\n const function_call = message.function_call;\n\n if (\n function_call !== undefined &&\n (typeof function_call === 'string' ||\n function_call.arguments === undefined ||\n function_call.name === undefined)\n ) {\n throw new Error(\n 'Invalid function call in message. Expected a function call object',\n );\n }\n\n return {\n role: message.role,\n content: message.content,\n function_call:\n function_call === undefined\n ? undefined\n : {\n name: function_call.name!,\n arguments: function_call.arguments!,\n },\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'function': {\n if (message.name === undefined) {\n throw new Error('Invalid function call in message. Expected a name');\n }\n\n return {\n role: message.role,\n content: message.content,\n name: message.name,\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'data': {\n throw \"unsupported message role 'data'\";\n }\n\n case 'tool': {\n if (message.name === undefined) {\n throw new Error('Invalid tool message. Expected a name');\n }\n\n if (message.tool_call_id === undefined) {\n throw new Error('Invalid tool message. Expected a tool_call_id');\n }\n\n return {\n role: message.role,\n content: message.content,\n tool_call_id: message.tool_call_id,\n } satisfies ChatCompletionMessageParam;\n }\n }\n });\n}\n\n// copy of open ai messages (so we don't have a dependency on the openai package)\nexport type ChatCompletionMessageParam =\n | ChatCompletionSystemMessageParam\n | ChatCompletionUserMessageParam\n | ChatCompletionAssistantMessageParam\n | ChatCompletionToolMessageParam\n | ChatCompletionFunctionMessageParam;\n\nexport interface ChatCompletionSystemMessageParam {\n /**\n * The contents of the system message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `system`.\n */\n role: 'system';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport interface ChatCompletionUserMessageParam {\n /**\n * The contents of the user message.\n */\n content: string | Array<ChatCompletionContentPart>;\n\n /**\n * The role of the messages author, in this case `user`.\n */\n role: 'user';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport type ChatCompletionContentPart =\n | ChatCompletionContentPartText\n | ChatCompletionContentPartImage;\n\nexport interface ChatCompletionContentPartText {\n /**\n * The text content.\n */\n text: string;\n\n /**\n * The type of the content part.\n */\n type: 'text';\n}\n\nexport interface ChatCompletionContentPartImage {\n image_url: ChatCompletionContentPartImage.ImageURL;\n\n /**\n * The type of the content part.\n */\n type: 'image_url';\n}\n\nexport namespace ChatCompletionContentPartImage {\n export interface ImageURL {\n /**\n * Either a URL of the image or the base64 encoded image data.\n */\n url: string;\n\n /**\n * Specifies the detail level of the image. Learn more in the\n * [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).\n */\n detail?: 'auto' | 'low' | 'high';\n }\n}\n\nexport interface ChatCompletionAssistantMessageParam {\n /**\n * The role of the messages author, in this case `assistant`.\n */\n role: 'assistant';\n\n /**\n * The contents of the assistant message. Required unless `tool_calls` or\n * `function_call` is specified.\n */\n content?: string | null;\n\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n function_call?: ChatCompletionAssistantMessageParam.FunctionCall;\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n\n /**\n * The tool calls generated by the model, such as function calls.\n */\n tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionAssistantMessageParam {\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionMessageToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The function that the model called.\n */\n function: ChatCompletionMessageToolCall.Function;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: 'function';\n}\n\nexport namespace ChatCompletionMessageToolCall {\n /**\n * The function that the model called.\n */\n export interface Function {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionToolMessageParam {\n /**\n * The contents of the tool message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `tool`.\n */\n role: 'tool';\n\n /**\n * Tool call that this message is responding to.\n */\n tool_call_id: string;\n}\n\nexport interface ChatCompletionFunctionMessageParam {\n /**\n * The return value from the function call, to return to the model.\n */\n content: string | null;\n\n /**\n * The name of the function to call.\n */\n name: string;\n\n /**\n * The role of the messages author, in this case `function`.\n */\n role: 'function';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACSO,SAAS,kCACd,UACA;AACA,SACE,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAClC,QAAI,SAAS,QAAQ;AACnB,aAAO;AAAA;AAAA,SAAc,OAAO;AAAA,IAC9B,OAAO;AACL,aAAO;AAAA;AAAA,aAAkB,OAAO;AAAA,IAClC;AAAA,EACF,CAAC,IAAI;AAET;AASO,SAAS,oCACd,UACA;AACA,SAAO,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AACzC,QAAI,CAAC,CAAC,aAAa,MAAM,EAAE,SAAS,IAAI,GAAG;AACzC,YAAM,IAAI,MAAM,cAAc,IAAI,+BAA+B;AAAA,IACnE;AACA,WAAO;AAAA,MACL;AAAA,MACA,SAAS,CAAC,EAAE,MAAM,QAAQ,MAAM,QAAQ,CAAC;AAAA,IAC3C;AAAA,EACF,CAAC;AACH;;;AClCO,SAAS,qCACd,UACA;AACA,SACE,SACG,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAC1B,QAAI,SAAS,QAAQ;AACnB,aAAO;AAAA,EAAa,OAAO;AAAA;AAAA,IAC7B,WAAW,SAAS,aAAa;AAC/B,aAAO;AAAA,EAAkB,OAAO;AAAA;A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,UACd,SAAS,QAAQ;AAAA,QACnB;AAAA,MAEF,KAAK,aAAa;AAChB,cAAM,gBAAgB,QAAQ;AAE9B,YACE,kBAAkB,WACjB,OAAO,kBAAkB,YACxB,cAAc,cAAc,UAC5B,cAAc,SAAS,SACzB;AACA,gBAAM,IAAI;AAAA,YACR;AAAA,UACF;AAAA,QACF;AAEA,eAAO;AAAA,UACL,MAAM,QAAQ;AAAA,UACd,SAAS,QAAQ;AAAA,UACjB,eACE,kBAAkB,SACd,SACA;AAAA,YACE,MAAM,cAAc;AAAA,YACpB,WAAW,cAAc;AAAA,UAC3B;AAAA,QACR;AAAA,MACF;AAAA,MAEA,KAAK,YAAY;AACf,YAAI,QAAQ,SAAS,QAAW;AAC9B,gBAAM,IAAI,MAAM,mDAAmD;AAAA,QACrE;AAEA,eAAO;AAAA,UACL,MAAM,QAAQ;AAAA,UACd,SAAS,QAAQ;AAAA,UACjB,MAAM,QAAQ;AAAA,QAChB;AAAA,MACF;AAAA,MAEA,KAAK,QAAQ;AACX,cAAM;AAAA,MACR;AAAA,MAEA,KAAK,QAAQ;AACX,YAAI,QAAQ,SAAS,QAAW;AAC9B,gBAAM,IAAI,MAAM,uCAAuC;AAAA,QACzD;AAEA,YAAI,QAAQ,iBAAiB,QAAW;AACtC,gBAAM,IAAI,MAAM,+CAA+C;AAAA,QACjE;AAEA,eAAO;AAAA,UACL,MAAM,QAAQ;AAAA,UACd,SAAS,QAAQ;AAAA,UACjB,cAAc,QAAQ;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../anthropic.ts","../huggingface.ts","../openai.tsx"],"sourcesContent":["import { Message } from '@ai-sdk/ui-utils';\n\n/**\n * A prompt constructor for Anthropic models.\n * Does not support `function` messages.\n * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api\n */\nexport function experimental_buildAnthropicPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages.map(({ content, role }) => {\n if (role === 'user') {\n return `\\n\\nHuman: ${content}`;\n } else {\n return `\\n\\nAssistant: ${content}`;\n }\n }) + '\\n\\nAssistant:'\n );\n}\n\n/**\n * A prompt constructor for Anthropic V3 models which require Messages API.\n * Does not support message with image content\n * @see https://docs.anthropic.com/claude/reference/messages_post\n */\nexport function experimental_buildAnthropicMessages(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return messages.map(({ content, role }) => {\n if (!['assistant', 'user'].includes(role)) {\n throw new Error(`Cannot use ${role} on Anthropic V3 Messages API`);\n }\n return {\n role,\n content: [{ type: 'text', text: content }],\n };\n });\n}\n","import { Message } from '@ai-sdk/ui-utils';\n\n/**\n * A prompt constructor for the HuggingFace StarChat Beta model.\n * Does not support `function` messages.\n * @see https://huggingface.co/HuggingFaceH4/starchat-beta\n */\nexport function experimental_buildStarChatBetaPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|user|>\\n${content}<|end|>\\n`;\n } else if (role === 'assistant') {\n return `<|assistant|>\\n${content}<|end|>\\n`;\n } else if (role === 'system') {\n return `<|system|>\\n${content}<|end|>\\n`;\n } else if (role === 'function') {\n throw new Error('StarChat Beta does not support function calls.');\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace OpenAssistant models.\n * Does not support `function` or `system` messages.\n * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5\n */\nexport function experimental_buildOpenAssistantPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|prompter|>${content}<|endoftext|>`;\n } else if (role === 'function') {\n throw new Error('OpenAssistant does not support function calls.');\n } else if (role === 'system') {\n throw new Error('OpenAssistant does not support system messages.');\n } else {\n return `<|assistant|>${content}<|endoftext|>`;\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace LLama 2 chat models.\n * Does not support `function` messages.\n * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2\n */\nexport function experimental_buildLlama2Prompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n const startPrompt = `<s>[INST] `;\n const endPrompt = ` [/INST]`;\n const conversation = messages.map(({ content, role }, index) => {\n if (role === 'user') {\n return content.trim();\n } else if (role === 'assistant') {\n return ` [/INST] ${content}</s><s>[INST] `;\n } else if (role === 'function') {\n throw new Error('Llama 2 does not support function calls.');\n } else if (role === 'system' && index === 0) {\n return `<<SYS>>\\n${content}\\n<</SYS>>\\n\\n`;\n } else {\n throw new Error(`Invalid message role: ${role}`);\n }\n });\n\n return startPrompt + conversation.join('') + endPrompt;\n}\n","import { Message } from '@ai-sdk/ui-utils';\n\nexport function experimental_buildOpenAIMessages(\n messages: Message[],\n): ChatCompletionMessageParam[] {\n return messages.map(message => {\n switch (message.role) {\n case 'system':\n case 'user':\n return {\n role: message.role,\n content: message.content,\n } satisfies ChatCompletionMessageParam;\n\n case 'assistant': {\n const function_call = message.function_call;\n\n if (\n function_call !== undefined &&\n (typeof function_call === 'string' ||\n function_call.arguments === undefined ||\n function_call.name === undefined)\n ) {\n throw new Error(\n 'Invalid function call in message. Expected a function call object',\n );\n }\n\n return {\n role: message.role,\n content: message.content,\n function_call:\n function_call === undefined\n ? undefined\n : {\n name: function_call.name!,\n arguments: function_call.arguments!,\n },\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'function': {\n if (message.name === undefined) {\n throw new Error('Invalid function call in message. Expected a name');\n }\n\n return {\n role: message.role,\n content: message.content,\n name: message.name,\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'data': {\n throw \"unsupported message role 'data'\";\n }\n\n case 'tool': {\n if (message.name === undefined) {\n throw new Error('Invalid tool message. Expected a name');\n }\n\n if (message.tool_call_id === undefined) {\n throw new Error('Invalid tool message. Expected a tool_call_id');\n }\n\n return {\n role: message.role,\n content: message.content,\n tool_call_id: message.tool_call_id,\n } satisfies ChatCompletionMessageParam;\n }\n }\n });\n}\n\n// copy of open ai messages (so we don't have a dependency on the openai package)\nexport type ChatCompletionMessageParam =\n | ChatCompletionSystemMessageParam\n | ChatCompletionUserMessageParam\n | ChatCompletionAssistantMessageParam\n | ChatCompletionToolMessageParam\n | ChatCompletionFunctionMessageParam;\n\nexport interface ChatCompletionSystemMessageParam {\n /**\n * The contents of the system message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `system`.\n */\n role: 'system';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport interface ChatCompletionUserMessageParam {\n /**\n * The contents of the user message.\n */\n content: string | Array<ChatCompletionContentPart>;\n\n /**\n * The role of the messages author, in this case `user`.\n */\n role: 'user';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport type ChatCompletionContentPart =\n | ChatCompletionContentPartText\n | ChatCompletionContentPartImage;\n\nexport interface ChatCompletionContentPartText {\n /**\n * The text content.\n */\n text: string;\n\n /**\n * The type of the content part.\n */\n type: 'text';\n}\n\nexport interface ChatCompletionContentPartImage {\n image_url: ChatCompletionContentPartImage.ImageURL;\n\n /**\n * The type of the content part.\n */\n type: 'image_url';\n}\n\nexport namespace ChatCompletionContentPartImage {\n export interface ImageURL {\n /**\n * Either a URL of the image or the base64 encoded image data.\n */\n url: string;\n\n /**\n * Specifies the detail level of the image. Learn more in the\n * [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).\n */\n detail?: 'auto' | 'low' | 'high';\n }\n}\n\nexport interface ChatCompletionAssistantMessageParam {\n /**\n * The role of the messages author, in this case `assistant`.\n */\n role: 'assistant';\n\n /**\n * The contents of the assistant message. Required unless `tool_calls` or\n * `function_call` is specified.\n */\n content?: string | null;\n\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n function_call?: ChatCompletionAssistantMessageParam.FunctionCall;\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n\n /**\n * The tool calls generated by the model, such as function calls.\n */\n tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionAssistantMessageParam {\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionMessageToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The function that the model called.\n */\n function: ChatCompletionMessageToolCall.Function;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: 'function';\n}\n\nexport namespace ChatCompletionMessageToolCall {\n /**\n * The function that the model called.\n */\n export interface Function {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionToolMessageParam {\n /**\n * The contents of the tool message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `tool`.\n */\n role: 'tool';\n\n /**\n * Tool call that this message is responding to.\n */\n tool_call_id: string;\n}\n\nexport interface ChatCompletionFunctionMessageParam {\n /**\n * The return value from the function call, to return to the model.\n */\n content: string | null;\n\n /**\n * The name of the function to call.\n */\n name: string;\n\n /**\n * The role of the messages author, in this case `function`.\n */\n role: 'function';\n}\n"],"mappings":";AAOO,SAAS,kCACd,UACA;AACA,SACE,SAAS,IAAI,CAAC,EAAE,SAAS,KAA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AS,QAAQ;AAAA,UACjB,MAAM,QAAQ;AAAA,QAChB;AAAA,MACF;AAAA,MAEA,KAAK,QAAQ;AACX,cAAM;AAAA,MACR;AAAA,MAEA,KAAK,QAAQ;AACX,YAAI,QAAQ,SAAS,QAAW;AAC9B,gBAAM,IAAI,MAAM,uCAAuC;AAAA,QACzD;AAEA,YAAI,QAAQ,iBAAiB,QAAW;AACtC,gBAAM,IAAI,MAAM,+CAA+C;AAAA,QACjE;AAEA,eAAO;AAAA,UACL,MAAM,QAAQ;AAAA,UACd,SAAS,QAAQ;AAAA,UACjB,cAAc,QAAQ;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
1
+ {"version":3,"sources":["../anthropic.ts","../huggingface.ts","../openai.tsx"],"sourcesContent":["import { Message } from '@ai-sdk/ui-utils';\n\n/**\n * A prompt constructor for Anthropic models.\n * Does not support `function` messages.\n * @see https://docs.anthropic.com/claude/reference/getting-started-with-the-api\n *\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildAnthropicPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages.map(({ content, role }) => {\n if (role === 'user') {\n return `\\n\\nHuman: ${content}`;\n } else {\n return `\\n\\nAssistant: ${content}`;\n }\n }) + '\\n\\nAssistant:'\n );\n}\n\n/**\n * A prompt constructor for Anthropic V3 models which require Messages API.\n * Does not support message with image content\n * @see https://docs.anthropic.com/claude/reference/messages_post\n *\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildAnthropicMessages(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return messages.map(({ content, role }) => {\n if (!['assistant', 'user'].includes(role)) {\n throw new Error(`Cannot use ${role} on Anthropic V3 Messages API`);\n }\n return {\n role,\n content: [{ type: 'text', text: content }],\n };\n });\n}\n","import { Message } from '@ai-sdk/ui-utils';\n\n/**\n * A prompt constructor for the HuggingFace StarChat Beta model.\n * Does not support `function` messages.\n * @see https://huggingface.co/HuggingFaceH4/starchat-beta *\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildStarChatBetaPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|user|>\\n${content}<|end|>\\n`;\n } else if (role === 'assistant') {\n return `<|assistant|>\\n${content}<|end|>\\n`;\n } else if (role === 'system') {\n return `<|system|>\\n${content}<|end|>\\n`;\n } else if (role === 'function') {\n throw new Error('StarChat Beta does not support function calls.');\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace OpenAssistant models.\n * Does not support `function` or `system` messages.\n * @see https://huggingface.co/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5 *\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildOpenAssistantPrompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n return (\n messages\n .map(({ content, role }) => {\n if (role === 'user') {\n return `<|prompter|>${content}<|endoftext|>`;\n } else if (role === 'function') {\n throw new Error('OpenAssistant does not support function calls.');\n } else if (role === 'system') {\n throw new Error('OpenAssistant does not support system messages.');\n } else {\n return `<|assistant|>${content}<|endoftext|>`;\n }\n })\n .join('') + '<|assistant|>'\n );\n}\n\n/**\n * A prompt constructor for HuggingFace LLama 2 chat models.\n * Does not support `function` messages.\n * @see https://huggingface.co/meta-llama/Llama-2-70b-chat-hf and https://huggingface.co/blog/llama2#how-to-prompt-llama-2\n *\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildLlama2Prompt(\n messages: Pick<Message, 'content' | 'role'>[],\n) {\n const startPrompt = `<s>[INST] `;\n const endPrompt = ` [/INST]`;\n const conversation = messages.map(({ content, role }, index) => {\n if (role === 'user') {\n return content.trim();\n } else if (role === 'assistant') {\n return ` [/INST] ${content}</s><s>[INST] `;\n } else if (role === 'function') {\n throw new Error('Llama 2 does not support function calls.');\n } else if (role === 'system' && index === 0) {\n return `<<SYS>>\\n${content}\\n<</SYS>>\\n\\n`;\n } else {\n throw new Error(`Invalid message role: ${role}`);\n }\n });\n\n return startPrompt + conversation.join('') + endPrompt;\n}\n","import { Message } from '@ai-sdk/ui-utils';\n\n/**\n * @deprecated Will be removed. Use the new provider architecture instead.\n */\nexport function experimental_buildOpenAIMessages(\n messages: Message[],\n): ChatCompletionMessageParam[] {\n return messages.map(message => {\n switch (message.role) {\n case 'system':\n case 'user':\n return {\n role: message.role,\n content: message.content,\n } satisfies ChatCompletionMessageParam;\n\n case 'assistant': {\n const function_call = message.function_call;\n\n if (\n function_call !== undefined &&\n (typeof function_call === 'string' ||\n function_call.arguments === undefined ||\n function_call.name === undefined)\n ) {\n throw new Error(\n 'Invalid function call in message. Expected a function call object',\n );\n }\n\n return {\n role: message.role,\n content: message.content,\n function_call:\n function_call === undefined\n ? undefined\n : {\n name: function_call.name!,\n arguments: function_call.arguments!,\n },\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'function': {\n if (message.name === undefined) {\n throw new Error('Invalid function call in message. Expected a name');\n }\n\n return {\n role: message.role,\n content: message.content,\n name: message.name,\n } satisfies ChatCompletionMessageParam;\n }\n\n case 'data': {\n throw \"unsupported message role 'data'\";\n }\n\n case 'tool': {\n if (message.name === undefined) {\n throw new Error('Invalid tool message. Expected a name');\n }\n\n if (message.tool_call_id === undefined) {\n throw new Error('Invalid tool message. Expected a tool_call_id');\n }\n\n return {\n role: message.role,\n content: message.content,\n tool_call_id: message.tool_call_id,\n } satisfies ChatCompletionMessageParam;\n }\n }\n });\n}\n\n// copy of open ai messages (so we don't have a dependency on the openai package)\nexport type ChatCompletionMessageParam =\n | ChatCompletionSystemMessageParam\n | ChatCompletionUserMessageParam\n | ChatCompletionAssistantMessageParam\n | ChatCompletionToolMessageParam\n | ChatCompletionFunctionMessageParam;\n\nexport interface ChatCompletionSystemMessageParam {\n /**\n * The contents of the system message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `system`.\n */\n role: 'system';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport interface ChatCompletionUserMessageParam {\n /**\n * The contents of the user message.\n */\n content: string | Array<ChatCompletionContentPart>;\n\n /**\n * The role of the messages author, in this case `user`.\n */\n role: 'user';\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n}\n\nexport type ChatCompletionContentPart =\n | ChatCompletionContentPartText\n | ChatCompletionContentPartImage;\n\nexport interface ChatCompletionContentPartText {\n /**\n * The text content.\n */\n text: string;\n\n /**\n * The type of the content part.\n */\n type: 'text';\n}\n\nexport interface ChatCompletionContentPartImage {\n image_url: ChatCompletionContentPartImage.ImageURL;\n\n /**\n * The type of the content part.\n */\n type: 'image_url';\n}\n\nexport namespace ChatCompletionContentPartImage {\n export interface ImageURL {\n /**\n * Either a URL of the image or the base64 encoded image data.\n */\n url: string;\n\n /**\n * Specifies the detail level of the image. Learn more in the\n * [Vision guide](https://platform.openai.com/docs/guides/vision/low-or-high-fidelity-image-understanding).\n */\n detail?: 'auto' | 'low' | 'high';\n }\n}\n\nexport interface ChatCompletionAssistantMessageParam {\n /**\n * The role of the messages author, in this case `assistant`.\n */\n role: 'assistant';\n\n /**\n * The contents of the assistant message. Required unless `tool_calls` or\n * `function_call` is specified.\n */\n content?: string | null;\n\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n function_call?: ChatCompletionAssistantMessageParam.FunctionCall;\n\n /**\n * An optional name for the participant. Provides the model information to\n * differentiate between participants of the same role.\n */\n name?: string;\n\n /**\n * The tool calls generated by the model, such as function calls.\n */\n tool_calls?: Array<ChatCompletionMessageToolCall>;\n}\n\nexport namespace ChatCompletionAssistantMessageParam {\n /**\n * @deprecated: Deprecated and replaced by `tool_calls`. The name and arguments of\n * a function that should be called, as generated by the model.\n */\n export interface FunctionCall {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionMessageToolCall {\n /**\n * The ID of the tool call.\n */\n id: string;\n\n /**\n * The function that the model called.\n */\n function: ChatCompletionMessageToolCall.Function;\n\n /**\n * The type of the tool. Currently, only `function` is supported.\n */\n type: 'function';\n}\n\nexport namespace ChatCompletionMessageToolCall {\n /**\n * The function that the model called.\n */\n export interface Function {\n /**\n * The arguments to call the function with, as generated by the model in JSON\n * format. Note that the model does not always generate valid JSON, and may\n * hallucinate parameters not defined by your function schema. Validate the\n * arguments in your code before calling your function.\n */\n arguments: string;\n\n /**\n * The name of the function to call.\n */\n name: string;\n }\n}\n\nexport interface ChatCompletionToolMessageParam {\n /**\n * The contents of the tool message.\n */\n content: string;\n\n /**\n * The role of the messages author, in this case `tool`.\n */\n role: 'tool';\n\n /**\n * Tool call that this message is responding to.\n */\n tool_call_id: string;\n}\n\nexport interface ChatCompletionFunctionMessageParam {\n /**\n * The return value from the function call, to return to the model.\n */\n content: string | null;\n\n /**\n * The name of the function to call.\n */\n name: string;\n\n /**\n * The role of the messages author, in this case `function`.\n */\n role: 'function';\n}\n"],"mappings":";AASO,SAAS,kCACd,UACA;AACA,SACE,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AAClC,QAAI,SAAS,QAAQ;AACnB,aAAO;AAAA;AAAA,SAAc,OAAO;AAAA,IAC9B,OAAO;AACL,aAAO;AAAA;AAAA,aAAkB,OAAO;AAAA,IAClC;AAAA,EACF,CAAC,IAAI;AAET;AASO,SAAS,oCACd,UACA;AACA,SAAO,SAAS,IAAI,CAAC,EAAE,SAAS,KAAK,MAAM;AACzC,QAAI,CAAC,CAAC,aAAa,MAAM,EAAE,SAAS,IAAI,GAAG;AACzC,YAAM,IAAI,MAAM,cAAc,IAAI,+BAA+B;AAAA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,UACjB,cAAc,QAAQ;AAAA,QACxB;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,4 +1,4 @@
1
- import { LanguageModelV1FinishReason, LanguageModelV1CallWarning, LanguageModelV1 } from '@ai-sdk/provider';
1
+ import { LanguageModelV1FinishReason, LanguageModelV1CallWarning, LanguageModelV1ProviderMetadata, LanguageModelV1 } from '@ai-sdk/provider';
2
2
  import { ReactNode } from 'react';
3
3
  import { z } from 'zod';
4
4
  import OpenAI from 'openai';
@@ -178,6 +178,60 @@ type CallSettings = {
178
178
  headers?: Record<string, string | undefined>;
179
179
  };
180
180
 
181
+ /**
182
+ Represents the number of tokens used in a prompt and completion.
183
+ */
184
+ type CompletionTokenUsage = {
185
+ /**
186
+ The number of tokens used in the prompt.
187
+ */
188
+ promptTokens: number;
189
+ /**
190
+ The number of tokens used in the completion.
191
+ */
192
+ completionTokens: number;
193
+ /**
194
+ The total number of tokens used (promptTokens + completionTokens).
195
+ */
196
+ totalTokens: number;
197
+ };
198
+
199
+ /**
200
+ Reason why a language model finished generating a response.
201
+
202
+ Can be one of the following:
203
+ - `stop`: model generated stop sequence
204
+ - `length`: model generated maximum number of tokens
205
+ - `content-filter`: content filter violation stopped the model
206
+ - `tool-calls`: model triggered tool calls
207
+ - `error`: model stopped because of an error
208
+ - `other`: model stopped for other reasons
209
+ */
210
+ type FinishReason = LanguageModelV1FinishReason;
211
+ /**
212
+ Warning from the model provider for this call. The call will proceed, but e.g.
213
+ some settings might not be supported, which can lead to suboptimal results.
214
+ */
215
+ type CallWarning = LanguageModelV1CallWarning;
216
+ /**
217
+ Additional provider-specific metadata. They are passed through
218
+ to the provider from the AI SDK and enable provider-specific
219
+ functionality that can be fully encapsulated in the provider.
220
+ */
221
+ type ProviderMetadata = LanguageModelV1ProviderMetadata;
222
+ /**
223
+ Tool choice for the generation. It supports the following settings:
224
+
225
+ - `auto` (default): the model can choose whether and which tools to call.
226
+ - `required`: the model must call a tool. It can choose which tool to call.
227
+ - `none`: the model must not call tools
228
+ - `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
229
+ */
230
+ type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
231
+ type: 'tool';
232
+ toolName: keyof TOOLS;
233
+ };
234
+
181
235
  /**
182
236
  Data content. Can either be a base64-encoded string, a Uint8Array, an ArrayBuffer, or a Buffer.
183
237
  */
@@ -192,6 +246,12 @@ interface TextPart {
192
246
  The text content.
193
247
  */
194
248
  text: string;
249
+ /**
250
+ Additional provider-specific metadata. They are passed through
251
+ to the provider from the AI SDK and enable provider-specific
252
+ functionality that can be fully encapsulated in the provider.
253
+ */
254
+ experimental_providerMetadata?: ProviderMetadata;
195
255
  }
196
256
  /**
197
257
  Image content part of a prompt. It contains an image.
@@ -209,6 +269,12 @@ interface ImagePart {
209
269
  Optional mime type of the image.
210
270
  */
211
271
  mimeType?: string;
272
+ /**
273
+ Additional provider-specific metadata. They are passed through
274
+ to the provider from the AI SDK and enable provider-specific
275
+ functionality that can be fully encapsulated in the provider.
276
+ */
277
+ experimental_providerMetadata?: ProviderMetadata;
212
278
  }
213
279
  /**
214
280
  Tool call content part of a prompt. It contains a tool call (usually generated by the AI model).
@@ -249,6 +315,12 @@ interface ToolResultPart {
249
315
  Optional flag if the result is an error or an error message.
250
316
  */
251
317
  isError?: boolean;
318
+ /**
319
+ Additional provider-specific metadata. They are passed through
320
+ to the provider from the AI SDK and enable provider-specific
321
+ functionality that can be fully encapsulated in the provider.
322
+ */
323
+ experimental_providerMetadata?: ProviderMetadata;
252
324
  }
253
325
 
254
326
  /**
@@ -266,6 +338,12 @@ type CoreMessage = CoreSystemMessage | CoreUserMessage | CoreAssistantMessage |
266
338
  type CoreSystemMessage = {
267
339
  role: 'system';
268
340
  content: string;
341
+ /**
342
+ Additional provider-specific metadata. They are passed through
343
+ to the provider from the AI SDK and enable provider-specific
344
+ functionality that can be fully encapsulated in the provider.
345
+ */
346
+ experimental_providerMetadata?: ProviderMetadata;
269
347
  };
270
348
  /**
271
349
  A user message. It can contain text or a combination of text and images.
@@ -273,6 +351,12 @@ A user message. It can contain text or a combination of text and images.
273
351
  type CoreUserMessage = {
274
352
  role: 'user';
275
353
  content: UserContent;
354
+ /**
355
+ Additional provider-specific metadata. They are passed through
356
+ to the provider from the AI SDK and enable provider-specific
357
+ functionality that can be fully encapsulated in the provider.
358
+ */
359
+ experimental_providerMetadata?: ProviderMetadata;
276
360
  };
277
361
  /**
278
362
  Content of a user message. It can be a string or an array of text and image parts.
@@ -284,6 +368,12 @@ An assistant message. It can contain text, tool calls, or a combination of text
284
368
  type CoreAssistantMessage = {
285
369
  role: 'assistant';
286
370
  content: AssistantContent;
371
+ /**
372
+ Additional provider-specific metadata. They are passed through
373
+ to the provider from the AI SDK and enable provider-specific
374
+ functionality that can be fully encapsulated in the provider.
375
+ */
376
+ experimental_providerMetadata?: ProviderMetadata;
287
377
  };
288
378
  /**
289
379
  Content of an assistant message. It can be a string or an array of text and tool call parts.
@@ -295,6 +385,12 @@ A tool message. It contains the result of one or more tool calls.
295
385
  type CoreToolMessage = {
296
386
  role: 'tool';
297
387
  content: ToolContent;
388
+ /**
389
+ Additional provider-specific metadata. They are passed through
390
+ to the provider from the AI SDK and enable provider-specific
391
+ functionality that can be fully encapsulated in the provider.
392
+ */
393
+ experimental_providerMetadata?: ProviderMetadata;
298
394
  };
299
395
  /**
300
396
  Content of a tool message. It is an array of tool result parts.
@@ -319,54 +415,6 @@ type Prompt = {
319
415
  messages?: Array<CoreMessage>;
320
416
  };
321
417
 
322
- /**
323
- Represents the number of tokens used in a prompt and completion.
324
- */
325
- type CompletionTokenUsage = {
326
- /**
327
- The number of tokens used in the prompt.
328
- */
329
- promptTokens: number;
330
- /**
331
- The number of tokens used in the completion.
332
- */
333
- completionTokens: number;
334
- /**
335
- The total number of tokens used (promptTokens + completionTokens).
336
- */
337
- totalTokens: number;
338
- };
339
-
340
- /**
341
- Reason why a language model finished generating a response.
342
-
343
- Can be one of the following:
344
- - `stop`: model generated stop sequence
345
- - `length`: model generated maximum number of tokens
346
- - `content-filter`: content filter violation stopped the model
347
- - `tool-calls`: model triggered tool calls
348
- - `error`: model stopped because of an error
349
- - `other`: model stopped for other reasons
350
- */
351
- type FinishReason = LanguageModelV1FinishReason;
352
- /**
353
- Warning from the model provider for this call. The call will proceed, but e.g.
354
- some settings might not be supported, which can lead to suboptimal results.
355
- */
356
- type CallWarning = LanguageModelV1CallWarning;
357
- /**
358
- Tool choice for the generation. It supports the following settings:
359
-
360
- - `auto` (default): the model can choose whether and which tools to call.
361
- - `required`: the model must call a tool. It can choose which tool to call.
362
- - `none`: the model must not call tools
363
- - `{ type: 'tool', toolName: string (typed) }`: the model must call the specified tool
364
- */
365
- type CoreToolChoice<TOOLS extends Record<string, unknown>> = 'auto' | 'none' | 'required' | {
366
- type: 'tool';
367
- toolName: keyof TOOLS;
368
- };
369
-
370
418
  type Streamable$1 = ReactNode | Promise<ReactNode>;
371
419
  type Renderer$1<T extends Array<any>> = (...args: T) => Streamable$1 | Generator<Streamable$1, Streamable$1, void> | AsyncGenerator<Streamable$1, Streamable$1, void>;
372
420
  type RenderTool<PARAMETERS extends z.ZodTypeAny = any> = {