Skip to content

Commit

Permalink
anthropc
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel committed Oct 25, 2024
1 parent a2f7192 commit 091c045
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions content/providers/01-ai-sdk-providers/05-anthropic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,36 @@ const computerTool = anthropic.tools.computer_20241022({
displayWidthPx: 1920,
displayHeightPx: 1080,
displayNumber: 0, // Optional, for X11 environments

execute: async ({ action, coordinate, text }) => {
// Implement your computer control logic here
// Return the result of the action

// Example code:
switch (action) {
case 'screenshot': {
// multipart result:
return {
type: 'image',
data: fs
.readFileSync('./data/screenshot-editor.png')
.toString('base64'),
};
}
default: {
console.log('Action:', action);
console.log('Coordinate:', coordinate);
console.log('Text:', text);
return `executed ${action}`;
}
}
},

// map to tool result content for LLM consumption:
experimental_toToolResultContent(result) {
return typeof result === 'string'
? [{ type: 'text', text: result }]
: [{ type: 'image', data: result.data, mimeType: 'image/png' }];
},
});
```
Expand Down

0 comments on commit 091c045

Please sign in to comment.