Skip to content

Instantly share code, notes, and snippets.

@mizchi
Created June 25, 2024 05:58
Show Gist options
  • Save mizchi/5cafae4527454e18867bfdd277712365 to your computer and use it in GitHub Desktop.
Save mizchi/5cafae4527454e18867bfdd277712365 to your computer and use it in GitHub Desktop.
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