Skip to content
Dashboard

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

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',
},
],
},
],
});

Thanks to the AI SDK's unified API, to use this functionality with Google or Vertex AI, all you need to change is the model string in the code above.

Link to headingComputer use support (Anthropic)

While Anthropic defines the tool interfaces, you'll need to implement the underlying execute function for each tool, defining how your application should handle actions like moving the mouse, capturing screenshots, or running terminal commands on your specific system.

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,
});

Note that Anthropic computer use is currently in beta, and it's recommended to implement appropriate safety measures such as using virtual machines and limiting access to sensitive data when building applications with this functionality. To learn more, check out our computer use guide.

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.',
});

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.',
});

Link to headingAdditional provider updates

Link to headingUpdated chatbot template

Link to headingMigrating to AI SDK 4.0

Link to headingGetting started

Link to headingContributors