@anthropic-ai/sdk 0.2.4 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,10 +1,24 @@
1
- # Anthropic TypeScript SDK
1
+ # Anthropic TypeScript SDK [![npm](https://img.shields.io/npm/v/@anthropic-ai/sdk)](https://www.npmjs.com/package/@anthropic-ai/sdk)
2
2
 
3
3
  This package provides access to Anthropic's safety-first language model APIs.
4
4
 
5
5
  For more information on our APIs, please check the confidential documentation portal.
6
6
 
7
- ## Getting started
7
+ ## Installation
8
+
9
+ Install using your package manager of choice. For example:
10
+
11
+ ```sh
12
+ npm install @anthropic-ai/sdk
13
+ ```
14
+
15
+ … or:
16
+
17
+ ```sh
18
+ yarn add @anthropic-ai/sdk
19
+ ```
20
+
21
+ ## Development and testing
8
22
 
9
23
  Examples are available in the [examples/](examples/) folder.
10
24
 
@@ -4,7 +4,8 @@ export type SamplingParameters = {
4
4
  stop_sequences: string[];
5
5
  max_tokens_to_sample: number;
6
6
  };
7
- export type OnSampleChange = (completion: CompletionResponse) => void | Promise<void>;
7
+ export type OnOpen = (response: Response) => void | Promise<void>;
8
+ export type OnUpdate = (completion: CompletionResponse) => void | Promise<void>;
8
9
  export declare const HUMAN_PROMPT = "\n\nHuman:";
9
10
  export declare const AI_PROMPT = "\n\nAssistant:";
10
11
  export type CompletionResponse = {
@@ -22,5 +23,8 @@ export declare class Client {
22
23
  apiUrl?: string;
23
24
  });
24
25
  complete(params: SamplingParameters): Promise<CompletionResponse>;
25
- completeStream(params: SamplingParameters, onSampleChange: OnSampleChange): Promise<CompletionResponse>;
26
+ completeStream(params: SamplingParameters, { onOpen, onUpdate }: {
27
+ onOpen?: OnOpen;
28
+ onUpdate?: OnUpdate;
29
+ }): Promise<CompletionResponse>;
26
30
  }
@@ -13,7 +13,7 @@ exports.Client = exports.AI_PROMPT = exports.HUMAN_PROMPT = void 0;
13
13
  const fetch_event_source_1 = require("@fortaine/fetch-event-source");
14
14
  exports.HUMAN_PROMPT = "\n\nHuman:";
15
15
  exports.AI_PROMPT = "\n\nAssistant:";
16
- const CLIENT_ID = "anthropic-typescript/0.2.3";
16
+ const CLIENT_ID = "anthropic-typescript/0.3.1";
17
17
  const DEFAULT_API_URL = "https://api.anthropic.com";
18
18
  var Event;
19
19
  (function (Event) {
@@ -46,7 +46,7 @@ class Client {
46
46
  return completion;
47
47
  });
48
48
  }
49
- completeStream(params, onSampleChange) {
49
+ completeStream(params, { onOpen, onUpdate }) {
50
50
  const abortController = new AbortController();
51
51
  return new Promise((resolve, reject) => {
52
52
  (0, fetch_event_source_1.fetchEventSource)(`${this.apiUrl}/v1/complete`, {
@@ -64,6 +64,9 @@ class Client {
64
64
  abortController.abort();
65
65
  return reject(Error(`Failed to open sampling stream, HTTP status code ${response.status}: ${response.statusText}`));
66
66
  }
67
+ if (onOpen) {
68
+ yield Promise.resolve(onOpen(response));
69
+ }
67
70
  }),
68
71
  onmessage: (ev) => {
69
72
  if (ev.event === Event.Ping) {
@@ -74,8 +77,8 @@ class Client {
74
77
  abortController.abort();
75
78
  return resolve(completion);
76
79
  }
77
- if (onSampleChange) {
78
- Promise.resolve(onSampleChange(completion)).catch((error) => {
80
+ if (onUpdate) {
81
+ Promise.resolve(onUpdate(completion)).catch((error) => {
79
82
  abortController.abort();
80
83
  reject(error);
81
84
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anthropic-ai/sdk",
3
- "version": "0.2.4",
3
+ "version": "0.3.1",
4
4
  "description": "Library for accessing the Anthropic API",
5
5
  "repository": "https://github.com/anthropics/anthropic-sdk-typescript",
6
6
  "license": "MIT",