Created
June 25, 2024 05:58
-
-
Save mizchi/5cafae4527454e18867bfdd277712365 to your computer and use it in GitHub Desktop.
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
import AnthropicAI from 'npm:@anthropic-ai/sdk@0.24.0'; | |
const client = new AnthropicAI({ | |
apiKey: Deno.env.get('ANTHROPIC_API_KEY')!, | |
}); | |
const write = (text: string) => { | |
Deno.stdout.write(new TextEncoder().encode(text)); | |
} | |
const stream = client.messages.stream({ | |
messages: [ | |
{ | |
role: 'user', | |
content: 'What is the capital of France?', | |
} | |
], | |
model: 'claude-3-5-sonnet-20240620', | |
max_tokens: 1024, | |
}).on('text', (text) => { | |
write(text); | |
}); | |
write('\n'); | |
const mes = await stream.finalMessage(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment