hume 0.3.2 → 0.4.0

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/Client.js CHANGED
@@ -94,7 +94,7 @@ class HumeClient {
94
94
  "X-Hume-Api-Key": yield core.Supplier.get(this._options.apiKey),
95
95
  "X-Fern-Language": "JavaScript",
96
96
  "X-Fern-SDK-Name": "hume",
97
- "X-Fern-SDK-Version": "0.3.2",
97
+ "X-Fern-SDK-Version": "0.4.0",
98
98
  },
99
99
  contentType: "application/json",
100
100
  queryParameters: _queryParams,
@@ -143,7 +143,7 @@ class HumeClient {
143
143
  "X-Hume-Api-Key": yield core.Supplier.get(this._options.apiKey),
144
144
  "X-Fern-Language": "JavaScript",
145
145
  "X-Fern-SDK-Name": "hume",
146
- "X-Fern-SDK-Version": "0.3.2",
146
+ "X-Fern-SDK-Version": "0.4.0",
147
147
  },
148
148
  contentType: "application/json",
149
149
  body: yield serializers.BaseRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
@@ -195,7 +195,7 @@ class HumeClient {
195
195
  "X-Hume-Api-Key": yield core.Supplier.get(this._options.apiKey),
196
196
  "X-Fern-Language": "JavaScript",
197
197
  "X-Fern-SDK-Name": "hume",
198
- "X-Fern-SDK-Version": "0.3.2",
198
+ "X-Fern-SDK-Version": "0.4.0",
199
199
  },
200
200
  contentType: "application/json",
201
201
  timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
@@ -243,7 +243,7 @@ class HumeClient {
243
243
  "X-Hume-Api-Key": yield core.Supplier.get(this._options.apiKey),
244
244
  "X-Fern-Language": "JavaScript",
245
245
  "X-Fern-SDK-Name": "hume",
246
- "X-Fern-SDK-Version": "0.3.2",
246
+ "X-Fern-SDK-Version": "0.4.0",
247
247
  },
248
248
  contentType: "application/json",
249
249
  responseType: "streaming",
@@ -287,7 +287,7 @@ class HumeClient {
287
287
  "X-Hume-Api-Key": yield core.Supplier.get(this._options.apiKey),
288
288
  "X-Fern-Language": "JavaScript",
289
289
  "X-Fern-SDK-Name": "hume",
290
- "X-Fern-SDK-Version": "0.3.2",
290
+ "X-Fern-SDK-Version": "0.4.0",
291
291
  },
292
292
  contentType: "application/json",
293
293
  timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
package/README.md CHANGED
@@ -62,23 +62,35 @@ const client = new HumeStreamingClient({
62
62
  apiKey: "YOUR_API_KEY",
63
63
  });
64
64
 
65
- const stream = await client.connect({
65
+ const stream = client.connect({
66
66
  configs: {
67
67
  language: {},
68
68
  },
69
- onMessage: (response) => {
70
- if (response.language != null) {
71
- console.log(response.language.predictions);
72
- }
73
- },
74
- onError: (err) => {
75
- console.log(err);
76
- }
69
+ onMessage: (response) => { console.log("Socket opened") },
70
+ onWarning: (warning) => { console.log(warning)},
71
+ onError: (error) => { console.log(error)},
72
+ onClose: () => { console.log("Socket closed")},
77
73
  });
78
74
 
79
- stream.sendText({
75
+ const response = await stream.sendText({
80
76
  text: "Mary had a little lamb,"
81
77
  });
78
+ console.log(response);
79
+ ```
80
+
81
+ ### Sending Files
82
+ You can use the `sendFile` method to upload files.
83
+
84
+ ```typescript
85
+ const response = await socket.sendFile({
86
+ file: fs.createReadStream(path.join(__dirname, "obama.png")),
87
+ config: {
88
+ face: {
89
+ identifyFaces: true,
90
+ },
91
+ },
92
+ });
93
+ console.log(response);
82
94
  ```
83
95
 
84
96
  ## Errors
@@ -124,3 +136,17 @@ await hume.submitJob(..., {
124
136
  timeoutInSeconds: 10, // timeout after 10 seconds
125
137
  });
126
138
  ```
139
+
140
+ ## Beta Status
141
+ This SDK is in beta, and there may be breaking changes between versions without a major
142
+ version update. Therefore, we recommend pinning the package version to a specific version.
143
+ This way, you can install the same version each time without breaking changes.
144
+
145
+ ## Contributing
146
+ While we value open-source contributions to this SDK, this library is generated programmatically.
147
+ Additions made directly to this library would have to be moved over to our generation code,
148
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a
149
+ proof of concept, but know that we will not be able to merge it as-is. We suggest opening an
150
+ issue first to discuss with us!
151
+
152
+ On the other hand, contributions to the README are always very welcome!
package/dist/Client.js CHANGED
@@ -94,7 +94,7 @@ class HumeClient {
94
94
  "X-Hume-Api-Key": yield core.Supplier.get(this._options.apiKey),
95
95
  "X-Fern-Language": "JavaScript",
96
96
  "X-Fern-SDK-Name": "hume",
97
- "X-Fern-SDK-Version": "0.3.2",
97
+ "X-Fern-SDK-Version": "0.4.0",
98
98
  },
99
99
  contentType: "application/json",
100
100
  queryParameters: _queryParams,
@@ -143,7 +143,7 @@ class HumeClient {
143
143
  "X-Hume-Api-Key": yield core.Supplier.get(this._options.apiKey),
144
144
  "X-Fern-Language": "JavaScript",
145
145
  "X-Fern-SDK-Name": "hume",
146
- "X-Fern-SDK-Version": "0.3.2",
146
+ "X-Fern-SDK-Version": "0.4.0",
147
147
  },
148
148
  contentType: "application/json",
149
149
  body: yield serializers.BaseRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
@@ -195,7 +195,7 @@ class HumeClient {
195
195
  "X-Hume-Api-Key": yield core.Supplier.get(this._options.apiKey),
196
196
  "X-Fern-Language": "JavaScript",
197
197
  "X-Fern-SDK-Name": "hume",
198
- "X-Fern-SDK-Version": "0.3.2",
198
+ "X-Fern-SDK-Version": "0.4.0",
199
199
  },
200
200
  contentType: "application/json",
201
201
  timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
@@ -243,7 +243,7 @@ class HumeClient {
243
243
  "X-Hume-Api-Key": yield core.Supplier.get(this._options.apiKey),
244
244
  "X-Fern-Language": "JavaScript",
245
245
  "X-Fern-SDK-Name": "hume",
246
- "X-Fern-SDK-Version": "0.3.2",
246
+ "X-Fern-SDK-Version": "0.4.0",
247
247
  },
248
248
  contentType: "application/json",
249
249
  responseType: "streaming",
@@ -287,7 +287,7 @@ class HumeClient {
287
287
  "X-Hume-Api-Key": yield core.Supplier.get(this._options.apiKey),
288
288
  "X-Fern-Language": "JavaScript",
289
289
  "X-Fern-SDK-Name": "hume",
290
- "X-Fern-SDK-Version": "0.3.2",
290
+ "X-Fern-SDK-Version": "0.4.0",
291
291
  },
292
292
  contentType: "application/json",
293
293
  timeoutMs: (requestOptions === null || requestOptions === void 0 ? void 0 : requestOptions.timeoutInSeconds) != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
@@ -1,23 +1,28 @@
1
1
  import * as Hume from "../api";
2
- import * as core from "../core";
3
2
  import { StreamSocket } from "./StreamSocket";
3
+ import WebSocket from "ws";
4
4
  export declare namespace HumeStreamingClient {
5
5
  interface Options {
6
- apiKey: core.Supplier<string>;
6
+ apiKey: string;
7
7
  openTimeoutInSeconds?: number;
8
8
  }
9
9
  interface ConnectArgs {
10
10
  config: Hume.ModelConfig;
11
11
  streamWindowMs?: number;
12
- onOpen?: () => void;
12
+ onOpen?: (event: WebSocket.Event) => void;
13
13
  onMessage?: (message: Hume.ModelResponse) => void;
14
14
  onWarning?: (error: Hume.ModelsWarning) => void;
15
15
  onError?: (error: Hume.ModelsError) => void;
16
- onClose?: () => void;
16
+ onClose?: (event: WebSocket.Event) => void;
17
17
  }
18
18
  }
19
19
  export declare class HumeStreamingClient {
20
20
  protected readonly _options: HumeStreamingClient.Options;
21
21
  constructor(_options: HumeStreamingClient.Options);
22
- connect(args: HumeStreamingClient.ConnectArgs): Promise<StreamSocket>;
22
+ connect(args: HumeStreamingClient.ConnectArgs): StreamSocket;
23
23
  }
24
+ export declare function parse(data: WebSocket.Data, args?: {
25
+ onMessage?: (message: Hume.ModelResponse) => void;
26
+ onWarning?: (error: Hume.ModelsWarning) => void;
27
+ onError?: (error: Hume.ModelsError) => void;
28
+ }): Promise<Hume.ModelResponse | Hume.ModelsWarning | Hume.ModelsError | undefined>;
@@ -35,8 +35,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
35
35
  return (mod && mod.__esModule) ? mod : { "default": mod };
36
36
  };
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.HumeStreamingClient = void 0;
39
- const core = __importStar(require("../core"));
38
+ exports.parse = exports.HumeStreamingClient = void 0;
40
39
  const serializers = __importStar(require("../serialization"));
41
40
  const StreamSocket_1 = require("./StreamSocket");
42
41
  const ws_1 = __importDefault(require("ws"));
@@ -45,81 +44,76 @@ class HumeStreamingClient {
45
44
  this._options = _options;
46
45
  }
47
46
  connect(args) {
48
- return __awaiter(this, void 0, void 0, function* () {
49
- const websocket = new ws_1.default(`wss://api.hume.ai/v0/stream/models`, {
50
- headers: {
51
- "X-Hume-Api-Key": yield core.Supplier.get(this._options.apiKey),
52
- },
53
- timeout: this._options.openTimeoutInSeconds,
54
- });
55
- websocket.addEventListener("open", () => {
56
- var _a;
57
- (_a = args.onOpen) === null || _a === void 0 ? void 0 : _a.call(args);
58
- });
59
- websocket.addEventListener("error", (e) => {
60
- var _a;
61
- (_a = args.onError) === null || _a === void 0 ? void 0 : _a.call(args, {
62
- code: e.type,
63
- error: e.message,
64
- });
65
- });
66
- websocket.addEventListener("message", ({ data }) => __awaiter(this, void 0, void 0, function* () {
67
- var _a, _b, _c;
68
- const body = JSON.parse(data);
69
- const parsedResponse = yield serializers.ModelResponse.parse(body, {
70
- unrecognizedObjectKeys: "passthrough",
71
- allowUnrecognizedUnionMembers: true,
72
- allowUnrecognizedEnumValues: true,
73
- breadcrumbsPrefix: ["response"],
74
- });
75
- if (parsedResponse.ok) {
76
- (_a = args.onMessage) === null || _a === void 0 ? void 0 : _a.call(args, parsedResponse.value);
77
- return;
78
- }
79
- const parsedWarning = yield serializers.ModelsWarning.parse(body, {
80
- unrecognizedObjectKeys: "passthrough",
81
- allowUnrecognizedUnionMembers: true,
82
- allowUnrecognizedEnumValues: true,
83
- breadcrumbsPrefix: ["response"],
84
- });
85
- if (parsedWarning.ok) {
86
- (_b = args.onWarning) === null || _b === void 0 ? void 0 : _b.call(args, parsedWarning.value);
87
- return;
88
- }
89
- const parsedError = yield serializers.ModelsError.parse(body, {
90
- unrecognizedObjectKeys: "passthrough",
91
- allowUnrecognizedUnionMembers: true,
92
- allowUnrecognizedEnumValues: true,
93
- breadcrumbsPrefix: ["response"],
94
- });
95
- if (parsedError.ok) {
96
- (_c = args.onError) === null || _c === void 0 ? void 0 : _c.call(args, parsedError.value);
97
- return;
98
- }
99
- }));
100
- websocket.addEventListener("close", () => {
101
- var _a;
102
- (_a = args.onClose) === null || _a === void 0 ? void 0 : _a.call(args);
47
+ const websocket = new ws_1.default(`wss://api.hume.ai/v0/stream/models`, {
48
+ headers: {
49
+ "X-Hume-Api-Key": this._options.apiKey,
50
+ },
51
+ timeout: this._options.openTimeoutInSeconds,
52
+ });
53
+ websocket.addEventListener("open", (event) => {
54
+ var _a;
55
+ (_a = args.onOpen) === null || _a === void 0 ? void 0 : _a.call(args, event);
56
+ });
57
+ websocket.addEventListener("error", (e) => {
58
+ var _a;
59
+ (_a = args.onError) === null || _a === void 0 ? void 0 : _a.call(args, {
60
+ code: e.type,
61
+ error: e.message,
103
62
  });
104
- return new Promise((resolve) => {
105
- if (websocket && websocket.readyState !== websocket.OPEN) {
106
- websocket.addEventListener("open", () => {
107
- resolve(new StreamSocket_1.StreamSocket({
108
- websocket,
109
- streamWindowMs: args.streamWindowMs,
110
- config: args.config,
111
- }));
112
- });
113
- }
114
- else {
115
- resolve(new StreamSocket_1.StreamSocket({
116
- websocket,
117
- streamWindowMs: args.streamWindowMs,
118
- config: args.config,
119
- }));
120
- }
63
+ });
64
+ websocket.addEventListener("message", ({ data }) => __awaiter(this, void 0, void 0, function* () {
65
+ parse(data, {
66
+ onMessage: args.onMessage,
67
+ onWarning: args.onWarning,
68
+ onError: args.onError,
121
69
  });
70
+ }));
71
+ websocket.addEventListener("close", (event) => {
72
+ var _a;
73
+ (_a = args.onClose) === null || _a === void 0 ? void 0 : _a.call(args, event);
74
+ });
75
+ return new StreamSocket_1.StreamSocket({
76
+ websocket,
77
+ streamWindowMs: args.streamWindowMs,
78
+ config: args.config,
122
79
  });
123
80
  }
124
81
  }
125
82
  exports.HumeStreamingClient = HumeStreamingClient;
83
+ function parse(data, args = {}) {
84
+ var _a, _b, _c;
85
+ return __awaiter(this, void 0, void 0, function* () {
86
+ const message = JSON.parse(data);
87
+ const parsedResponse = yield serializers.ModelResponse.parse(message, {
88
+ unrecognizedObjectKeys: "passthrough",
89
+ allowUnrecognizedUnionMembers: true,
90
+ allowUnrecognizedEnumValues: true,
91
+ breadcrumbsPrefix: ["response"],
92
+ });
93
+ if (parsedResponse.ok) {
94
+ (_a = args.onMessage) === null || _a === void 0 ? void 0 : _a.call(args, parsedResponse.value);
95
+ return parsedResponse.value;
96
+ }
97
+ const parsedWarning = yield serializers.ModelsWarning.parse(message, {
98
+ unrecognizedObjectKeys: "passthrough",
99
+ allowUnrecognizedUnionMembers: true,
100
+ allowUnrecognizedEnumValues: true,
101
+ breadcrumbsPrefix: ["response"],
102
+ });
103
+ if (parsedWarning.ok) {
104
+ (_b = args.onWarning) === null || _b === void 0 ? void 0 : _b.call(args, parsedWarning.value);
105
+ return parsedWarning.value;
106
+ }
107
+ const parsedError = yield serializers.ModelsError.parse(message, {
108
+ unrecognizedObjectKeys: "passthrough",
109
+ allowUnrecognizedUnionMembers: true,
110
+ allowUnrecognizedEnumValues: true,
111
+ breadcrumbsPrefix: ["response"],
112
+ });
113
+ if (parsedError.ok) {
114
+ (_c = args.onError) === null || _c === void 0 ? void 0 : _c.call(args, parsedError.value);
115
+ return parsedError.value;
116
+ }
117
+ });
118
+ }
119
+ exports.parse = parse;
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import WebSocket from "ws";
3
3
  import * as Hume from "../api";
4
+ import * as fs from "fs";
4
5
  export declare namespace StreamSocket {
5
6
  interface Args {
6
7
  websocket: WebSocket;
@@ -14,29 +15,16 @@ export declare class StreamSocket {
14
15
  private config;
15
16
  constructor({ websocket, config, streamWindowMs }: StreamSocket.Args);
16
17
  /**
17
- * Send a file on the `StreamSocket`
18
+ * Send file on the `StreamSocket`
18
19
  *
19
- * @param filepath Path to media file to send on socket connection
20
- * @param config List of model configurations.
21
- * If set these configurations will overwrite any configurations
22
- * set when initializing the `StreamSocket`
23
- */
24
- sendFile({ filepath, config, }: {
25
- filepath: string;
26
- config?: Hume.ModelConfig;
27
- }): Promise<void>;
28
- /**
29
- * Send raw bytes on the `StreamSocket`
30
- *
31
- * @param buffer Raw bytes of media to send on socket connection
32
- * @param config List of model configurations.
33
- * If set these configurations will overwrite any configurations
34
- * set when initializing the `StreamSocket`
20
+ * @param file A fs.ReadStream | File | Blob
21
+ * @param config This method is intended for use with a `LanguageConfig`.
22
+ * When the socket is configured for other modalities this method will fail.
35
23
  */
36
- sendBuffer({ buffer, config, }: {
37
- buffer: Buffer;
24
+ sendFile({ file, config, }: {
25
+ file: fs.ReadStream | Blob;
38
26
  config?: Hume.ModelConfig;
39
- }): void;
27
+ }): Promise<Hume.ModelResponse>;
40
28
  /**
41
29
  * Send text on the `StreamSocket`
42
30
  *
@@ -44,10 +32,10 @@ export declare class StreamSocket {
44
32
  * @param config This method is intended for use with a `LanguageConfig`.
45
33
  * When the socket is configured for other modalities this method will fail.
46
34
  */
47
- sendText({ text, config, }: {
35
+ sendText({ text, config }: {
48
36
  text: string;
49
37
  config?: Hume.ModelConfig;
50
- }): void;
38
+ }): Promise<Hume.ModelResponse>;
51
39
  /**
52
40
  * Send facemesh landmarks on the `StreamSocket`
53
41
  *
@@ -61,7 +49,7 @@ export declare class StreamSocket {
61
49
  sendFacemesh({ landmarks, config, }: {
62
50
  landmarks: number[][][];
63
51
  config?: Hume.ModelConfig;
64
- }): void;
52
+ }): Promise<Hume.ModelResponse>;
65
53
  /**
66
54
  *
67
55
  * Reset the streaming sliding window.
@@ -69,15 +57,17 @@ export declare class StreamSocket {
69
57
  * Call this method when some media has been fully processed and you want to continue using the same
70
58
  * streaming connection without leaking context across media samples.
71
59
  */
72
- reset(): void;
60
+ reset(): Promise<void>;
73
61
  /**
74
62
  *
75
63
  * Get details associated with the current streaming connection.
76
64
  *
77
65
  */
78
- getJobDetails(): void;
66
+ getJobDetails(): Promise<void>;
79
67
  /**
80
68
  * Closes the underlying socket.
81
69
  */
82
70
  close(): void;
71
+ private send;
72
+ private tillSocketOpen;
83
73
  }