Skip to content
Dashboard

Introducing PDF support, computer use, and an xAI Grok provider

Copy link to headingPDF support

import { generateText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
const result = await generateText({
model: anthropic('claude-3-5-sonnet-20241022'),
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: 'What is an embedding model according to this document?',
},
{
type: 'file',
data: fs.readFileSync('./data/ai.pdf'),
mimeType: 'application/pdf',
},
],
},
],
});

Copy link to headingComputer use support (Anthropic)

import { generateText } from 'ai';
import { anthropic } from '@ai-sdk/anthropic';
import { executeComputerAction, getScreenshot } from '@/lib/ai'; // user-defined
const computerTool = anthropic.tools.computer_20241022({
displayWidthPx: 1920,
displayHeightPx: 1080,
execute: async ({ action, coordinate, text }) => {
switch (action) {
case 'screenshot': {
return {
type: 'image',
data: getScreenshot(),
};
}
default: {
return executeComputerAction(action, coordinate, text);
}
}
},
experimental_toToolResultContent: (result) => {
return typeof result === 'string'
? [{ type: 'text', text: result }]
: [{ type: 'image', data: result.data, mimeType: 'image/png' }];
},
});
const result = await generateText({
model: anthropic('claude-3-5-sonnet-20241022'),
prompt: 'Move the cursor to the center of the screen and take a screenshot',
tools: { computer: computerTool },
});

const result = await generateText({
model: anthropic('claude-3-5-sonnet-20241022'),
prompt: 'Summarize the AI news from this week.',
tools: { computer: computerTool, textEditor: textEditorTool, bash: bashTool },
maxSteps: 10,
});

Copy link to headingContinuation support

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
const result = await generateText({
model: openai('gpt-4o'),
maxSteps: 5,
experimental_continueSteps: true,
prompt:
'Write a book about Roman history, ' +
'from the founding of the city of Rome ' +
'to the fall of the Western Roman Empire. ' +
'Each chapter MUST HAVE at least 1000 words.',
});

Copy link to headingNew xAI Grok provider

pnpm install ai @ai-sdk/xai

import { xai } from '@ai-sdk/xai';
import { generateText } from 'ai';
const { text } = await generateText({
model: xai('grok-beta'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});

Copy link to headingAdditional provider updates

Copy link to headingUpdated chatbot template

Copy link to headingMigrating to AI SDK 4.0

Copy link to headingGetting started

Copy link to headingContributors

Ready to deploy?