feat: add smooth stream (#722)
This commit is contained in:
parent
3f9d379a6a
commit
5e8cddc886
5 changed files with 52 additions and 20 deletions
|
|
@ -2,6 +2,7 @@ import {
|
|||
type Message,
|
||||
convertToCoreMessages,
|
||||
createDataStreamResponse,
|
||||
smoothStream,
|
||||
streamText,
|
||||
} from 'ai';
|
||||
|
||||
|
|
@ -99,6 +100,7 @@ export async function POST(request: Request) {
|
|||
messages: coreMessages,
|
||||
maxSteps: 5,
|
||||
experimental_activeTools: allTools,
|
||||
experimental_transform: smoothStream({ chunking: 'word' }),
|
||||
tools: {
|
||||
getWeather,
|
||||
createDocument: createDocument({ session, dataStream, model }),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { generateUUID } from '@/lib/utils';
|
|||
import {
|
||||
DataStreamWriter,
|
||||
experimental_generateImage,
|
||||
smoothStream,
|
||||
streamObject,
|
||||
streamText,
|
||||
tool,
|
||||
|
|
@ -60,6 +61,7 @@ export const createDocument = ({
|
|||
model: customModel(model.apiIdentifier),
|
||||
system:
|
||||
'Write about the given topic. Markdown is supported. Use headings wherever appropriate.',
|
||||
experimental_transform: smoothStream({ chunking: 'word' }),
|
||||
prompt: title,
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import {
|
||||
DataStreamWriter,
|
||||
experimental_generateImage,
|
||||
smoothStream,
|
||||
streamObject,
|
||||
streamText,
|
||||
tool,
|
||||
|
|
@ -52,6 +53,7 @@ export const updateDocument = ({
|
|||
const { fullStream } = streamText({
|
||||
model: customModel(model.apiIdentifier),
|
||||
system: updateDocumentPrompt(currentContent, 'text'),
|
||||
experimental_transform: smoothStream({ chunking: 'word' }),
|
||||
prompt: description,
|
||||
experimental_providerMetadata: {
|
||||
openai: {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@
|
|||
"@vercel/analytics": "^1.3.1",
|
||||
"@vercel/blob": "^0.24.1",
|
||||
"@vercel/postgres": "^0.10.0",
|
||||
"ai": "4.0.36",
|
||||
"ai": "4.1.1",
|
||||
"bcrypt-ts": "^5.0.2",
|
||||
"class-variance-authority": "^0.7.0",
|
||||
"classnames": "^2.5.1",
|
||||
|
|
|
|||
64
pnpm-lock.yaml
generated
64
pnpm-lock.yaml
generated
|
|
@ -66,8 +66,8 @@ importers:
|
|||
specifier: ^0.10.0
|
||||
version: 0.10.0
|
||||
ai:
|
||||
specifier: 4.0.36
|
||||
version: 4.0.36(react@19.0.0-rc-45804af1-20241021)(zod@3.23.8)
|
||||
specifier: 4.1.1
|
||||
version: 4.1.1(react@19.0.0-rc-45804af1-20241021)(zod@3.23.8)
|
||||
bcrypt-ts:
|
||||
specifier: ^5.0.2
|
||||
version: 5.0.2
|
||||
|
|
@ -255,12 +255,25 @@ packages:
|
|||
zod:
|
||||
optional: true
|
||||
|
||||
'@ai-sdk/provider-utils@2.1.1':
|
||||
resolution: {integrity: sha512-+FRXSAdzPJFJN6TpyvyGWLo7WJuoBKI1g66UL+sli1HrxlldXSwxRPeb8tMMmNcyi3VKQogg2VsoJjlt4ort5w==}
|
||||
engines: {node: '>=18'}
|
||||
peerDependencies:
|
||||
zod: ^3.0.0
|
||||
peerDependenciesMeta:
|
||||
zod:
|
||||
optional: true
|
||||
|
||||
'@ai-sdk/provider@1.0.4':
|
||||
resolution: {integrity: sha512-lJi5zwDosvvZER3e/pB8lj1MN3o3S7zJliQq56BRr4e9V3fcRyFtwP0JRxaRS5vHYX3OJ154VezVoQNrk0eaKw==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
'@ai-sdk/react@1.0.11':
|
||||
resolution: {integrity: sha512-ndBPA7dx2DqUr7s4zO1cRAPkFGS+wWvSri6OWfCuhfyTAADQ4vdd56vFP9zdTZl4cyL27Vh0hKLfFJMGx83MUQ==}
|
||||
'@ai-sdk/provider@1.0.5':
|
||||
resolution: {integrity: sha512-KATFp9CNXtMEzs8KBwLYK2+rGkkeED6p1+4koQveszyscIavObXIRW7vjr0MoZ9HFIHOUlrcak+3s/Xt3UXmAg==}
|
||||
engines: {node: '>=18'}
|
||||
|
||||
'@ai-sdk/react@1.1.1':
|
||||
resolution: {integrity: sha512-7LX/YF8sis8UM7p8ftUcu0xySG86/TBddcB42w/+mWOXL6hjYzcuGD8G121TobHsnxVxbsBlF/ykps/GYVvLNg==}
|
||||
engines: {node: '>=18'}
|
||||
peerDependencies:
|
||||
react: ^18 || ^19 || ^19.0.0-rc
|
||||
|
|
@ -271,8 +284,8 @@ packages:
|
|||
zod:
|
||||
optional: true
|
||||
|
||||
'@ai-sdk/ui-utils@1.0.10':
|
||||
resolution: {integrity: sha512-wZfZNH2IloTx5b1O8CU7/R/icm8EsmURElPckYwNYj2YZrKk9X5XeYSDBF/1/J83obzsn0i7VKkIf40qhRzVVA==}
|
||||
'@ai-sdk/ui-utils@1.1.1':
|
||||
resolution: {integrity: sha512-lkTxGoebnEgs8HtKeWut0AglXN7zpWQwYmun4yuhpiup7DxPWTmt3vGiYvqQTBOFAmyoea3uzIKjHwRHuayr2w==}
|
||||
engines: {node: '>=18'}
|
||||
peerDependencies:
|
||||
zod: ^3.0.0
|
||||
|
|
@ -1613,8 +1626,8 @@ packages:
|
|||
engines: {node: '>=0.4.0'}
|
||||
hasBin: true
|
||||
|
||||
ai@4.0.36:
|
||||
resolution: {integrity: sha512-KeXQe+eKQK57WYzN+K6VUBZqj/n70V+cCwrXAhXa7enbZCAsErvQKqrnxkF1qm9UfPuNKNEFV5BRoMKJ5gRfAw==}
|
||||
ai@4.1.1:
|
||||
resolution: {integrity: sha512-oZTzQfrvrXuXnAJhoCsGcLUxSMWWYKkqrk2LfCzcukvB8us7ZUnFBgs9drhXuFP3JkWVbeIZHXjDexZIZcbi8g==}
|
||||
engines: {node: '>=18'}
|
||||
peerDependencies:
|
||||
react: ^18 || ^19 || ^19.0.0-rc
|
||||
|
|
@ -3753,24 +3766,37 @@ snapshots:
|
|||
optionalDependencies:
|
||||
zod: 3.23.8
|
||||
|
||||
'@ai-sdk/provider-utils@2.1.1(zod@3.23.8)':
|
||||
dependencies:
|
||||
'@ai-sdk/provider': 1.0.5
|
||||
eventsource-parser: 3.0.0
|
||||
nanoid: 3.3.8
|
||||
secure-json-parse: 2.7.0
|
||||
optionalDependencies:
|
||||
zod: 3.23.8
|
||||
|
||||
'@ai-sdk/provider@1.0.4':
|
||||
dependencies:
|
||||
json-schema: 0.4.0
|
||||
|
||||
'@ai-sdk/react@1.0.11(react@19.0.0-rc-45804af1-20241021)(zod@3.23.8)':
|
||||
'@ai-sdk/provider@1.0.5':
|
||||
dependencies:
|
||||
'@ai-sdk/provider-utils': 2.0.7(zod@3.23.8)
|
||||
'@ai-sdk/ui-utils': 1.0.10(zod@3.23.8)
|
||||
json-schema: 0.4.0
|
||||
|
||||
'@ai-sdk/react@1.1.1(react@19.0.0-rc-45804af1-20241021)(zod@3.23.8)':
|
||||
dependencies:
|
||||
'@ai-sdk/provider-utils': 2.1.1(zod@3.23.8)
|
||||
'@ai-sdk/ui-utils': 1.1.1(zod@3.23.8)
|
||||
swr: 2.2.5(react@19.0.0-rc-45804af1-20241021)
|
||||
throttleit: 2.1.0
|
||||
optionalDependencies:
|
||||
react: 19.0.0-rc-45804af1-20241021
|
||||
zod: 3.23.8
|
||||
|
||||
'@ai-sdk/ui-utils@1.0.10(zod@3.23.8)':
|
||||
'@ai-sdk/ui-utils@1.1.1(zod@3.23.8)':
|
||||
dependencies:
|
||||
'@ai-sdk/provider': 1.0.4
|
||||
'@ai-sdk/provider-utils': 2.0.7(zod@3.23.8)
|
||||
'@ai-sdk/provider': 1.0.5
|
||||
'@ai-sdk/provider-utils': 2.1.1(zod@3.23.8)
|
||||
zod-to-json-schema: 3.24.1(zod@3.23.8)
|
||||
optionalDependencies:
|
||||
zod: 3.23.8
|
||||
|
|
@ -4870,12 +4896,12 @@ snapshots:
|
|||
|
||||
acorn@8.14.0: {}
|
||||
|
||||
ai@4.0.36(react@19.0.0-rc-45804af1-20241021)(zod@3.23.8):
|
||||
ai@4.1.1(react@19.0.0-rc-45804af1-20241021)(zod@3.23.8):
|
||||
dependencies:
|
||||
'@ai-sdk/provider': 1.0.4
|
||||
'@ai-sdk/provider-utils': 2.0.7(zod@3.23.8)
|
||||
'@ai-sdk/react': 1.0.11(react@19.0.0-rc-45804af1-20241021)(zod@3.23.8)
|
||||
'@ai-sdk/ui-utils': 1.0.10(zod@3.23.8)
|
||||
'@ai-sdk/provider': 1.0.5
|
||||
'@ai-sdk/provider-utils': 2.1.1(zod@3.23.8)
|
||||
'@ai-sdk/react': 1.1.1(react@19.0.0-rc-45804af1-20241021)(zod@3.23.8)
|
||||
'@ai-sdk/ui-utils': 1.1.1(zod@3.23.8)
|
||||
'@opentelemetry/api': 1.9.0
|
||||
jsondiffpatch: 0.6.0
|
||||
optionalDependencies:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue