From 7814c4b9fee60d9170f5d144b99abe40e4e531be Mon Sep 17 00:00:00 2001 From: Lars Grammel Date: Wed, 6 Nov 2024 10:16:22 +0100 Subject: [PATCH] chore (ui): remove streamMode setting from useChat & useCompletion (#3494) --- .changeset/moody-kiwis-jog.md | 9 +++++++++ .../01-migration-guide/04-migration-guide-4-0.mdx | 5 +++++ packages/react/src/use-chat.ts | 8 +------- packages/react/src/use-completion.ts | 8 +------- packages/solid/src/use-chat.ts | 8 ++------ packages/solid/src/use-completion.ts | 7 +------ packages/svelte/src/use-chat.ts | 8 +------- packages/svelte/src/use-completion.ts | 8 +------- packages/ui-utils/src/types.ts | 14 -------------- packages/vue/src/use-chat.ts | 8 +------- 10 files changed, 22 insertions(+), 61 deletions(-) create mode 100644 .changeset/moody-kiwis-jog.md diff --git a/.changeset/moody-kiwis-jog.md b/.changeset/moody-kiwis-jog.md new file mode 100644 index 000000000000..fee065c48bc1 --- /dev/null +++ b/.changeset/moody-kiwis-jog.md @@ -0,0 +1,9 @@ +--- +'@ai-sdk/ui-utils': major +'@ai-sdk/svelte': major +'@ai-sdk/react': major +'@ai-sdk/solid': major +'@ai-sdk/vue': major +--- + +chore (ui): remove streamMode setting from useChat & useCompletion diff --git a/content/docs/08-troubleshooting/01-migration-guide/04-migration-guide-4-0.mdx b/content/docs/08-troubleshooting/01-migration-guide/04-migration-guide-4-0.mdx index 82d971e579b0..3fc9929d40a1 100644 --- a/content/docs/08-troubleshooting/01-migration-guide/04-migration-guide-4-0.mdx +++ b/content/docs/08-troubleshooting/01-migration-guide/04-migration-guide-4-0.mdx @@ -62,3 +62,8 @@ Please use the `headers` and `body` parameters instead. ### Removed `name` from UI message The `name` property from the `Message` type has been removed. + +### Removed `streamMode` from `useChat` and `useCompletion` + +The `streamMode` parameter has been removed from the `useChat` and `useCompletion` hooks. +Please use the `streamProtocol` parameter instead. diff --git a/packages/react/src/use-chat.ts b/packages/react/src/use-chat.ts index 4243600c1e9c..adb0e2693e59 100644 --- a/packages/react/src/use-chat.ts +++ b/packages/react/src/use-chat.ts @@ -182,8 +182,7 @@ export function useChat({ maxAutomaticRoundtrips = experimental_maxAutomaticRoundtrips, maxToolRoundtrips = maxAutomaticRoundtrips, maxSteps = maxToolRoundtrips != null ? maxToolRoundtrips + 1 : 1, - streamMode, - streamProtocol, + streamProtocol = 'data', onResponse, onFinish, onError, @@ -271,11 +270,6 @@ By default, it's set to 1, which means that only a single LLM call is made. result: any; }) => void; } { - // streamMode is deprecated, use streamProtocol instead. - if (streamMode) { - streamProtocol ??= streamMode === 'text' ? 'text' : undefined; - } - // Generate a unique id for the chat if not provided. const hookId = useId(); const idKey = id ?? hookId; diff --git a/packages/react/src/use-completion.ts b/packages/react/src/use-completion.ts index 5870ad0684b0..fedd8c314154 100644 --- a/packages/react/src/use-completion.ts +++ b/packages/react/src/use-completion.ts @@ -72,8 +72,7 @@ export function useCompletion({ credentials, headers, body, - streamMode, - streamProtocol, + streamProtocol = 'data', fetch, onResponse, onFinish, @@ -86,11 +85,6 @@ export function useCompletion({ */ experimental_throttle?: number; } = {}): UseCompletionHelpers { - // streamMode is deprecated, use streamProtocol instead. - if (streamMode) { - streamProtocol ??= streamMode === 'text' ? 'text' : undefined; - } - // Generate an unique id for the completion if not provided. const hookId = useId(); const completionId = id || hookId; diff --git a/packages/solid/src/use-chat.ts b/packages/solid/src/use-chat.ts index f56b89753c60..ee8f906b0c2d 100644 --- a/packages/solid/src/use-chat.ts +++ b/packages/solid/src/use-chat.ts @@ -101,7 +101,7 @@ const processStreamedResponse = async ( messagesRef: Message[], abortController: AbortController | null, generateId: IdGenerator, - streamProtocol: UseChatOptions['streamProtocol'], + streamProtocol: UseChatOptions['streamProtocol'] = 'data', onFinish: UseChatOptions['onFinish'], onResponse: UseChatOptions['onResponse'] | undefined, onToolCall: UseChatOptions['onToolCall'] | undefined, @@ -269,11 +269,7 @@ export function useChat( messagesRef, abortController, generateId(), - // streamMode is deprecated, use streamProtocol instead: - useChatOptions().streamProtocol?.() ?? - useChatOptions().streamMode?.() === 'text' - ? 'text' - : undefined, + useChatOptions().streamProtocol?.(), useChatOptions().onFinish?.(), useChatOptions().onResponse?.(), useChatOptions().onToolCall?.(), diff --git a/packages/solid/src/use-completion.ts b/packages/solid/src/use-completion.ts index d64759cb9abb..e3ae3366295e 100644 --- a/packages/solid/src/use-completion.ts +++ b/packages/solid/src/use-completion.ts @@ -135,12 +135,7 @@ export function useCompletion( ...extraMetadata.body, ...options?.body, }, - // streamMode is deprecated, use streamProtocol instead: - streamProtocol: - useCompletionOptions().streamProtocol?.() ?? - useCompletionOptions().streamMode?.() === 'text' - ? 'text' - : undefined, + streamProtocol: useCompletionOptions().streamProtocol?.(), setCompletion: mutate, setLoading: setIsLoading, setError, diff --git a/packages/svelte/src/use-chat.ts b/packages/svelte/src/use-chat.ts index 66f15ee95899..deaf1bbc45d6 100644 --- a/packages/svelte/src/use-chat.ts +++ b/packages/svelte/src/use-chat.ts @@ -208,8 +208,7 @@ export function useChat({ initialMessages = [], initialInput = '', sendExtraMessageFields, - streamMode, - streamProtocol, + streamProtocol = 'data', onResponse, onFinish, onError, @@ -231,11 +230,6 @@ export function useChat({ result: any; }) => void; } { - // streamMode is deprecated, use streamProtocol instead. - if (streamMode) { - streamProtocol ??= streamMode === 'text' ? 'text' : undefined; - } - // Generate a unique id for the chat if not provided. const chatId = id || `chat-${uniqueId++}`; diff --git a/packages/svelte/src/use-completion.ts b/packages/svelte/src/use-completion.ts index a415621c0a01..9ec49858ce60 100644 --- a/packages/svelte/src/use-completion.ts +++ b/packages/svelte/src/use-completion.ts @@ -60,18 +60,12 @@ export function useCompletion({ credentials, headers, body, - streamMode, - streamProtocol, + streamProtocol = 'data', onResponse, onFinish, onError, fetch, }: UseCompletionOptions = {}): UseCompletionHelpers { - // streamMode is deprecated, use streamProtocol instead. - if (streamMode) { - streamProtocol ??= streamMode === 'text' ? 'text' : undefined; - } - // Generate an unique id for the completion if not provided. const completionId = id || `completion-${uniqueId++}`; diff --git a/packages/ui-utils/src/types.ts b/packages/ui-utils/src/types.ts index 07a268e74d28..2424df11bdd7 100644 --- a/packages/ui-utils/src/types.ts +++ b/packages/ui-utils/src/types.ts @@ -256,13 +256,6 @@ either synchronously or asynchronously. */ sendExtraMessageFields?: boolean; - /** - * Stream mode (default to "stream-data") - * - * @deprecated Use `streamProtocol` instead. - */ - streamMode?: 'stream-data' | 'text'; - /** Streaming protocol that is used. Defaults to `data`. */ @@ -339,13 +332,6 @@ export type UseCompletionOptions = { */ body?: object; - /** - * Stream mode (default to "stream-data") - * - * @deprecated Use `streamProtocol` instead. - */ - streamMode?: 'stream-data' | 'text'; - /** Streaming protocol that is used. Defaults to `data`. */ diff --git a/packages/vue/src/use-chat.ts b/packages/vue/src/use-chat.ts index ab2276a146c2..e9d4ecab511c 100644 --- a/packages/vue/src/use-chat.ts +++ b/packages/vue/src/use-chat.ts @@ -88,8 +88,7 @@ export function useChat( initialMessages = [], initialInput = '', sendExtraMessageFields, - streamMode, - streamProtocol, + streamProtocol = 'data', onResponse, onFinish, onError, @@ -112,11 +111,6 @@ export function useChat( maxSteps: 1, }, ): UseChatHelpers { - // streamMode is deprecated, use streamProtocol instead. - if (streamMode) { - streamProtocol ??= streamMode === 'text' ? 'text' : undefined; - } - // Generate a unique ID for the chat if not provided. const chatId = id || `chat-${uniqueId++}`;