Skip to content

Commit

Permalink
docs(readme): remove old migration guide (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Dec 19, 2023
1 parent 7c8f365 commit 65dff0a
Showing 1 changed file with 0 additions and 74 deletions.
74 changes: 0 additions & 74 deletions README.md
Expand Up @@ -6,80 +6,6 @@ This library provides convenient access to the Anthropic REST API from server-si

For the AWS Bedrock API, see [`@anthropic-ai/bedrock-sdk`](https://github.com/anthropics/anthropic-bedrock-typescript).

## Migration from v0.4.x and below

In `v0.5.0`, we introduced a fully rewritten SDK. The new version offers better error handling, a more robust and intuitive streaming implementation, and more.

Key interface changes:

1. `new Client(apiKey)``new Anthropic({ apiKey })`
2. `client.complete()``client.completions.create()`
3. `client.completeStream()``client.completions.create({ stream: true })`
1. `onUpdate` callback → `for await (const x of stream)`
2. full message in stream → delta of message in stream

<details>
<summary>Example diff</summary>

```diff ts
// Import "Anthropic" instead of "Client":
- import { Client, HUMAN_PROMPT, AI_PROMPT } from '@anthropic-ai/sdk';
+ import Anthropic, { HUMAN_PROMPT, AI_PROMPT } from '@anthropic-ai/sdk';

// Instantiate with "apiKey" as an object property:
- const client = new Client(apiKey);
+ const client = new Anthropic({ apiKey });
// or, simply provide an ANTHROPIC_API_KEY environment variable:
+ const client = new Anthropic();

async function main() {
// Request & response types are the same as before, but better-typed.
const params = {
prompt: `${HUMAN_PROMPT} How many toes do dogs have?${AI_PROMPT}`,
max_tokens_to_sample: 200,
model: "claude-1",
};

// Instead of "client.complete()", you now call "client.completions.create()":
- await client.complete(params);
+ await client.completions.create(params);

// Streaming requests now use async iterators instead of callbacks:
- client.completeStream(params, {
- onUpdate: (completion) => {
- console.log(completion.completion); // full text
- },
- });
+ const stream = await client.completions.create({ ...params, stream: true });
+ for await (const completion of stream) {
+ process.stdout.write(completion.completion); // incremental text
+ }

// And, since this library uses `Anthropic-Version: 2023-06-01`,
// completion streams are now incremental diffs of text
// rather than sending the whole message every time:
let text = '';
- await client.completeStream(params, {
- onUpdate: (completion) => {
- const diff = completion.completion.replace(text, "");
- text = completion.completion;
- process.stdout.write(diff);
- },
- });
+ const stream = await client.completions.create({ ...params, stream: true });
+ for await (const completion of stream) {
+ const diff = completion.completion;
+ text += diff;
+ process.stdout.write(diff);
+ }
console.log('Done; final text is:')
console.log(text)
}
main();
```

</details>

The API documentation can be found [here](https://docs.anthropic.com/claude/reference/).

## Installation
Expand Down

0 comments on commit 65dff0a

Please sign in to comment.