-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (provider/anthropic): pdf support (#3458)
- Loading branch information
Showing
11 changed files
with
554 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@ai-sdk/anthropic': patch | ||
--- | ||
|
||
feat (provider/anthropic): pdf support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { anthropic } from '@ai-sdk/anthropic'; | ||
import { generateText } from 'ai'; | ||
import 'dotenv/config'; | ||
import fs from 'node:fs'; | ||
|
||
async function main() { | ||
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', | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
console.log(result.text); | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { anthropic } from '@ai-sdk/anthropic'; | ||
import { streamText } from 'ai'; | ||
import 'dotenv/config'; | ||
import fs from 'node:fs'; | ||
|
||
async function main() { | ||
const result = await streamText({ | ||
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', | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
for await (const textPart of result.textStream) { | ||
process.stdout.write(textPart); | ||
} | ||
} | ||
|
||
main().catch(console.error); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.