Skip to content

Commit

Permalink
feat: add smooth stream (vercel#722)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyphilemon authored Jan 22, 2025
1 parent 3f9d379 commit 5e8cddc
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 20 deletions.
2 changes: 2 additions & 0 deletions app/(chat)/api/chat/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type Message,
convertToCoreMessages,
createDataStreamResponse,
smoothStream,
streamText,
} from 'ai';

Expand Down Expand Up @@ -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 }),
Expand Down
2 changes: 2 additions & 0 deletions lib/ai/tools/create-document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { generateUUID } from '@/lib/utils';
import {
DataStreamWriter,
experimental_generateImage,
smoothStream,
streamObject,
streamText,
tool,
Expand Down Expand Up @@ -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,
});

Expand Down
2 changes: 2 additions & 0 deletions lib/ai/tools/update-document.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
DataStreamWriter,
experimental_generateImage,
smoothStream,
streamObject,
streamText,
tool,
Expand Down Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
64 changes: 45 additions & 19 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5e8cddc

Please sign in to comment.