Skip to content

Commit

Permalink
docs: use latest sonnet in example snippets (#625)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and RobertCraigie committed Dec 10, 2024
1 parent e58ba9a commit e8cd1aa
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async function main() {
const message = await client.messages.create({
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
});

console.log(message.content);
Expand All @@ -49,7 +49,7 @@ const client = new Anthropic();
const stream = await client.messages.create({
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
stream: true,
});
for await (const messageStreamEvent of stream) {
Expand All @@ -76,7 +76,7 @@ async function main() {
const params: Anthropic.MessageCreateParams = {
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
};
const message: Anthropic.Message = await client.messages.create(params);
}
Expand Down Expand Up @@ -108,7 +108,7 @@ const anthropic = new Anthropic();
async function main() {
const stream = anthropic.messages
.stream({
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
max_tokens: 1024,
messages: [
{
Expand Down Expand Up @@ -198,7 +198,7 @@ async function main() {
.create({
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
})
.catch(async (err) => {
if (err instanceof Anthropic.APIError) {
Expand Down Expand Up @@ -234,7 +234,7 @@ Error codes are as followed:
All object responses in the SDK provide a `_request_id` property which is added from the `request-id` response header so that you can quickly log failing requests and report them back to Anthropic.

```ts
const message = await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude' }], model: 'claude-3-opus-20240229' });
const message = await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude' }], model: 'claude-3-5-sonnet-latest' });
console.log(completion._request_id) // req_018EeWyXxfu5pfWkrYcMdjWG
```

Expand All @@ -255,7 +255,7 @@ const client = new Anthropic({
});

// Or, configure per-request:
await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude' }], model: 'claude-3-opus-20240229' }, {
await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude' }], model: 'claude-3-5-sonnet-latest' }, {
maxRetries: 5,
});
```
Expand All @@ -272,7 +272,7 @@ const client = new Anthropic({
});

// Override per-request:
await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude' }], model: 'claude-3-opus-20240229' }, {
await client.messages.create({ max_tokens: 1024, messages: [{ role: 'user', content: 'Hello, Claude' }], model: 'claude-3-5-sonnet-latest' }, {
timeout: 5 * 1000,
});
```
Expand Down Expand Up @@ -329,7 +329,7 @@ const message = await client.messages.create(
{
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
},
{ headers: { 'anthropic-version': 'My-Custom-Value' } },
);
Expand All @@ -351,7 +351,7 @@ const response = await client.messages
.create({
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
})
.asResponse();
console.log(response.headers.get('X-My-Header'));
Expand All @@ -361,7 +361,7 @@ const { data: message, response: raw } = await client.messages
.create({
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
})
.withResponse();
console.log(raw.headers.get('X-My-Header'));
Expand Down Expand Up @@ -473,7 +473,7 @@ await client.messages.create(
{
max_tokens: 1024,
messages: [{ role: 'user', content: 'Hello, Claude' }],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
},
{
httpAgent: new http.Agent({ keepAlive: false }),
Expand Down
2 changes: 1 addition & 1 deletion examples/cancellation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {
const question = 'Hey Claude! How can I recursively list all files in a directory in Rust?';

const stream = await client.messages.create({
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
stream: true,
max_tokens: 500,
messages: [{ role: 'user', content: question }],
Expand Down
2 changes: 1 addition & 1 deletion examples/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async function main() {
content: 'Hey Claude!?',
},
],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
max_tokens: 1024,
});
console.dir(result);
Expand Down
2 changes: 1 addition & 1 deletion examples/raw-streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const client = new Anthropic(); // gets API Key from environment variable ANTHRO

async function main() {
const stream = await client.messages.create({
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
stream: true,
max_tokens: 500,
messages: [
Expand Down
2 changes: 1 addition & 1 deletion examples/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ async function main() {
content: `Hey Claude! How can I recursively list all files in a directory in Rust?`,
},
],
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
max_tokens: 1024,
})
// Once a content block is fully streamed, this event will fire
Expand Down
4 changes: 2 additions & 2 deletions examples/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function main() {
];

const message = await client.messages.create({
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
max_tokens: 1024,
messages: [userMessage],
tools,
Expand All @@ -38,7 +38,7 @@ async function main() {
assert(tool);

const result = await client.messages.create({
model: 'claude-3-opus-20240229',
model: 'claude-3-5-sonnet-latest',
max_tokens: 1024,
messages: [
userMessage,
Expand Down

0 comments on commit e8cd1aa

Please sign in to comment.