-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (docs): add anthropic 8192 token example (#2751)
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 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
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,29 @@ | ||
import { anthropic } from '@ai-sdk/anthropic'; | ||
import { streamText } from 'ai'; | ||
import dotenv from 'dotenv'; | ||
|
||
dotenv.config(); | ||
|
||
async function main() { | ||
const result = await streamText({ | ||
model: anthropic('claude-3-5-sonnet-20240620'), | ||
|
||
headers: { 'anthropic-beta': 'max-tokens-3-5-sonnet-2024-07-15' }, | ||
maxTokens: 8192, // important: specify max tokens | ||
|
||
system: | ||
"Don't shy away from generating long text. Follow the user's instructions'", | ||
prompt: | ||
'Invent a new holiday and describe its traditions. Write at least 20 pages.', | ||
}); | ||
|
||
for await (const textPart of result.textStream) { | ||
process.stdout.write(textPart); | ||
} | ||
|
||
console.log(); | ||
console.log('Token usage:', await result.usage); | ||
console.log('Finish reason:', await result.finishReason); | ||
} | ||
|
||
main().catch(console.error); |