Skip to content

Commit

Permalink
chore (ui): remove streamMode setting from useChat & useCompletion (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel authored Nov 6, 2024
1 parent 482c648 commit 7814c4b
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 61 deletions.
9 changes: 9 additions & 0 deletions .changeset/moody-kiwis-jog.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 1 addition & 7 deletions packages/react/src/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 1 addition & 7 deletions packages/react/src/use-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@ export function useCompletion({
credentials,
headers,
body,
streamMode,
streamProtocol,
streamProtocol = 'data',
fetch,
onResponse,
onFinish,
Expand All @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions packages/solid/src/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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?.(),
Expand Down
7 changes: 1 addition & 6 deletions packages/solid/src/use-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 1 addition & 7 deletions packages/svelte/src/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,7 @@ export function useChat({
initialMessages = [],
initialInput = '',
sendExtraMessageFields,
streamMode,
streamProtocol,
streamProtocol = 'data',
onResponse,
onFinish,
onError,
Expand All @@ -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++}`;

Expand Down
8 changes: 1 addition & 7 deletions packages/svelte/src/use-completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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++}`;

Expand Down
14 changes: 0 additions & 14 deletions packages/ui-utils/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
*/
Expand Down Expand Up @@ -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`.
*/
Expand Down
8 changes: 1 addition & 7 deletions packages/vue/src/use-chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ export function useChat(
initialMessages = [],
initialInput = '',
sendExtraMessageFields,
streamMode,
streamProtocol,
streamProtocol = 'data',
onResponse,
onFinish,
onError,
Expand All @@ -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++}`;

Expand Down

0 comments on commit 7814c4b

Please sign in to comment.