Skip to content

Commit 715d4fa

Browse files
committed
Release 0.1.0
1 parent 26b324c commit 715d4fa

29 files changed

+522
-84
lines changed

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@fern-api/hume",
3-
"version": "0.0.10",
3+
"version": "0.1.0",
44
"private": false,
55
"repository": "https://github.com/fern-hume/hume-typescript-sdk",
66
"main": "./index.js",
@@ -11,10 +11,11 @@
1111
"prepack": "cp -rv dist/. ."
1212
},
1313
"dependencies": {
14-
"@ungap/url-search-params": "0.2.2",
1514
"url-join": "4.0.1",
1615
"@types/url-join": "4.0.1",
17-
"axios": "0.27.2"
16+
"axios": "0.27.2",
17+
"qs": "6.11.2",
18+
"@types/qs": "6.9.8"
1819
},
1920
"devDependencies": {
2021
"@types/node": "17.0.33",

src/Client.ts

+54-36
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import * as environments from "./environments";
66
import * as core from "./core";
77
import * as Hume from "./api";
8-
import { default as URLSearchParams } from "@ungap/url-search-params";
98
import urlJoin from "url-join";
109
import * as serializers from "./serialization";
1110
import * as errors from "./errors";
@@ -15,62 +14,71 @@ export declare namespace HumeClient {
1514
environment?: core.Supplier<environments.HumeEnvironment | string>;
1615
apiKey: core.Supplier<string>;
1716
}
17+
18+
interface RequestOptions {
19+
timeoutInSeconds?: number;
20+
maxRetries?: number;
21+
}
1822
}
1923

2024
export class HumeClient {
21-
constructor(protected readonly options: HumeClient.Options) {}
25+
constructor(protected readonly _options: HumeClient.Options) {}
2226

2327
/**
2428
* Sort and filter jobs.
2529
*/
26-
public async listJobs(request: Hume.ListJobsRequest = {}): Promise<Hume.JobRequest[]> {
30+
public async listJobs(
31+
request: Hume.ListJobsRequest = {},
32+
requestOptions?: HumeClient.RequestOptions
33+
): Promise<Hume.JobRequest[]> {
2734
const { limit, status, when, timestampMs, sortBy, direction } = request;
28-
const _queryParams = new URLSearchParams();
35+
const _queryParams: Record<string, string> = {};
2936
if (limit != null) {
30-
_queryParams.append("limit", limit.toString());
37+
_queryParams["limit"] = limit.toString();
3138
}
3239

3340
if (status != null) {
3441
if (Array.isArray(status)) {
3542
for (const _item of status) {
36-
_queryParams.append("status", _item);
43+
_queryParams["status"] = _item;
3744
}
3845
} else {
39-
_queryParams.append("status", status);
46+
_queryParams["status"] = status;
4047
}
4148
}
4249

4350
if (when != null) {
44-
_queryParams.append("when", when);
51+
_queryParams["when"] = when;
4552
}
4653

4754
if (timestampMs != null) {
48-
_queryParams.append("timestamp_ms", timestampMs.toString());
55+
_queryParams["timestamp_ms"] = timestampMs.toString();
4956
}
5057

5158
if (sortBy != null) {
52-
_queryParams.append("sort_by", sortBy);
59+
_queryParams["sort_by"] = sortBy;
5360
}
5461

5562
if (direction != null) {
56-
_queryParams.append("direction", direction);
63+
_queryParams["direction"] = direction;
5764
}
5865

5966
const _response = await core.fetcher({
6067
url: urlJoin(
61-
(await core.Supplier.get(this.options.environment)) ?? environments.HumeEnvironment.Default,
68+
(await core.Supplier.get(this._options.environment)) ?? environments.HumeEnvironment.Default,
6269
"v0/batch/jobs"
6370
),
6471
method: "GET",
6572
headers: {
66-
"X-Hume-Api-Key": await core.Supplier.get(this.options.apiKey),
73+
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
6774
"X-Fern-Language": "JavaScript",
6875
"X-Fern-SDK-Name": "@fern-api/hume",
69-
"X-Fern-SDK-Version": "0.0.10",
76+
"X-Fern-SDK-Version": "0.1.0",
7077
},
7178
contentType: "application/json",
7279
queryParameters: _queryParams,
73-
timeoutMs: 60000,
80+
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
81+
maxRetries: requestOptions?.maxRetries,
7482
});
7583
if (_response.ok) {
7684
return await serializers.listJobs.Response.parseOrThrow(_response.body, {
@@ -106,22 +114,26 @@ export class HumeClient {
106114
/**
107115
* Start a new batch job.
108116
*/
109-
public async submitJob(request: Hume.BaseRequest = {}): Promise<Hume.JobId> {
117+
public async submitJob(
118+
request: Hume.BaseRequest = {},
119+
requestOptions?: HumeClient.RequestOptions
120+
): Promise<Hume.JobId> {
110121
const _response = await core.fetcher({
111122
url: urlJoin(
112-
(await core.Supplier.get(this.options.environment)) ?? environments.HumeEnvironment.Default,
123+
(await core.Supplier.get(this._options.environment)) ?? environments.HumeEnvironment.Default,
113124
"v0/batch/jobs"
114125
),
115126
method: "POST",
116127
headers: {
117-
"X-Hume-Api-Key": await core.Supplier.get(this.options.apiKey),
128+
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
118129
"X-Fern-Language": "JavaScript",
119130
"X-Fern-SDK-Name": "@fern-api/hume",
120-
"X-Fern-SDK-Version": "0.0.10",
131+
"X-Fern-SDK-Version": "0.1.0",
121132
},
122133
contentType: "application/json",
123134
body: await serializers.BaseRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
124-
timeoutMs: 60000,
135+
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
136+
maxRetries: requestOptions?.maxRetries,
125137
});
126138
if (_response.ok) {
127139
return await serializers.JobId.parseOrThrow(_response.body, {
@@ -157,21 +169,25 @@ export class HumeClient {
157169
/**
158170
* Get the JSON predictions of a completed job.
159171
*/
160-
public async getJobPredictions(id: string): Promise<Hume.SourceResult[]> {
172+
public async getJobPredictions(
173+
id: string,
174+
requestOptions?: HumeClient.RequestOptions
175+
): Promise<Hume.SourceResult[]> {
161176
const _response = await core.fetcher({
162177
url: urlJoin(
163-
(await core.Supplier.get(this.options.environment)) ?? environments.HumeEnvironment.Default,
178+
(await core.Supplier.get(this._options.environment)) ?? environments.HumeEnvironment.Default,
164179
`v0/batch/jobs/${id}/predictions`
165180
),
166181
method: "GET",
167182
headers: {
168-
"X-Hume-Api-Key": await core.Supplier.get(this.options.apiKey),
183+
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
169184
"X-Fern-Language": "JavaScript",
170185
"X-Fern-SDK-Name": "@fern-api/hume",
171-
"X-Fern-SDK-Version": "0.0.10",
186+
"X-Fern-SDK-Version": "0.1.0",
172187
},
173188
contentType: "application/json",
174-
timeoutMs: 60000,
189+
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
190+
maxRetries: requestOptions?.maxRetries,
175191
});
176192
if (_response.ok) {
177193
return await serializers.getJobPredictions.Response.parseOrThrow(_response.body, {
@@ -207,22 +223,23 @@ export class HumeClient {
207223
/**
208224
* Get the artifacts ZIP of a completed job.
209225
*/
210-
public async getJobArtifacts(id: string): Promise<Blob> {
211-
const _response = await core.fetcher({
226+
public async getJobArtifacts(id: string, requestOptions?: HumeClient.RequestOptions): Promise<Blob> {
227+
const _response = await core.fetcher<Blob>({
212228
url: urlJoin(
213-
(await core.Supplier.get(this.options.environment)) ?? environments.HumeEnvironment.Default,
229+
(await core.Supplier.get(this._options.environment)) ?? environments.HumeEnvironment.Default,
214230
`v0/batch/jobs/${id}/artifacts`
215231
),
216232
method: "GET",
217233
headers: {
218-
"X-Hume-Api-Key": await core.Supplier.get(this.options.apiKey),
234+
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
219235
"X-Fern-Language": "JavaScript",
220236
"X-Fern-SDK-Name": "@fern-api/hume",
221-
"X-Fern-SDK-Version": "0.0.10",
237+
"X-Fern-SDK-Version": "0.1.0",
222238
},
223239
contentType: "application/json",
224240
responseType: "blob",
225-
timeoutMs: 60000,
241+
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
242+
maxRetries: requestOptions?.maxRetries,
226243
});
227244
if (_response.ok) {
228245
return _response.body;
@@ -253,21 +270,22 @@ export class HumeClient {
253270
/**
254271
* Get the request details and state of a given job.
255272
*/
256-
public async getJobDetails(id: string): Promise<Hume.JobRequest> {
273+
public async getJobDetails(id: string, requestOptions?: HumeClient.RequestOptions): Promise<Hume.JobRequest> {
257274
const _response = await core.fetcher({
258275
url: urlJoin(
259-
(await core.Supplier.get(this.options.environment)) ?? environments.HumeEnvironment.Default,
276+
(await core.Supplier.get(this._options.environment)) ?? environments.HumeEnvironment.Default,
260277
`v0/batch/jobs/${id}`
261278
),
262279
method: "GET",
263280
headers: {
264-
"X-Hume-Api-Key": await core.Supplier.get(this.options.apiKey),
281+
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
265282
"X-Fern-Language": "JavaScript",
266283
"X-Fern-SDK-Name": "@fern-api/hume",
267-
"X-Fern-SDK-Version": "0.0.10",
284+
"X-Fern-SDK-Version": "0.1.0",
268285
},
269286
contentType: "application/json",
270-
timeoutMs: 60000,
287+
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
288+
maxRetries: requestOptions?.maxRetries,
271289
});
272290
if (_response.ok) {
273291
return await serializers.JobRequest.parseOrThrow(_response.body, {

src/api/types/BoundingBox.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
*/
88
export interface BoundingBox {
99
/** x-coordinate of bounding box top left corner. */
10-
x: number;
10+
x?: number;
1111
/** y-coordinate of bounding box top left corner. */
12-
y: number;
12+
y?: number;
1313
/** Bounding box width. */
14-
w: number;
14+
w?: number;
1515
/** Bounding box height. */
16-
h: number;
16+
h?: number;
1717
}

src/api/types/EmotionEmbedding.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
import * as Hume from "..";
6+
7+
/**
8+
* A high-dimensional embedding in emotion space.
9+
*/
10+
export type EmotionEmbedding = Hume.EmotionEmbeddingItem[];

src/api/types/EmotionEmbeddingItem.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
export interface EmotionEmbeddingItem {
6+
/** Name of the emotion being expressed. */
7+
name?: string;
8+
/** Embedding value for the emotion being expressed. */
9+
score?: number;
10+
}

src/api/types/Sentiment.ts

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
import * as Hume from "..";
6+
7+
/**
8+
* Sentiment predictions returned as a distribution. This model predicts the probability that a given text could be interpreted as having each sentiment level from 1 (negative) to 9 (positive).
9+
*
10+
* Compared to returning one estimate of sentiment, this enables a more nuanced analysis of a text's meaning. For example, a text with very neutral sentiment would have an average rating of 5. But also a text that could be interpreted as having very positive sentiment or very negative sentiment would also have an average rating of 5. The average sentiment is less informative than the distribution over sentiment, so this API returns a value for each sentiment level.
11+
*/
12+
export type Sentiment = Hume.SentimentItem[];

src/api/types/SentimentItem.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
export interface SentimentItem {
6+
/** Level of sentiment, ranging from 1 (negative) to 9 (positive) */
7+
name?: string;
8+
/** Prediction for this level of sentiment */
9+
score?: number;
10+
}

src/api/types/TextPosition.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
/**
6+
* Position of a segment of text within a larger document, measured in characters. Uses zero-based indexing. The beginning index is inclusive and the end index is exclusive.
7+
*
8+
*/
9+
export interface TextPosition {
10+
/** The index of the first character in the text segment, inclusive. */
11+
begin?: number;
12+
/** The index of the last character in the text segment, exclusive. */
13+
end?: number;
14+
}

src/api/types/TimeRange.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
/**
6+
* A time range with a beginning and end, measured in seconds.
7+
*/
8+
export interface TimeRange {
9+
/** Beginning of time range in seconds. */
10+
begin?: number;
11+
/** End of time range in seconds. */
12+
end?: number;
13+
}

src/api/types/Toxicity.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
import * as Hume from "..";
6+
7+
/**
8+
* Toxicity predictions returned as probabilities that the text can be classified into the following categories: toxic, severe_toxic, obscene, threat, insult, and identity_hate.
9+
*/
10+
export type Toxicity = Hume.ToxicityItem[];

src/api/types/ToxicityItem.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* This file was auto-generated by Fern from our API Definition.
3+
*/
4+
5+
export interface ToxicityItem {
6+
/** Category of toxicity. */
7+
name?: string;
8+
/** Prediction for this category of toxicity */
9+
score?: number;
10+
}

src/api/types/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,11 @@ export * from "./TranscriptionMetadata";
6262
export * from "./Url";
6363
export * from "./When";
6464
export * from "./Window";
65+
export * from "./EmotionEmbedding";
66+
export * from "./EmotionEmbeddingItem";
67+
export * from "./TimeRange";
68+
export * from "./TextPosition";
69+
export * from "./Sentiment";
70+
export * from "./SentimentItem";
71+
export * from "./Toxicity";
72+
export * from "./ToxicityItem";

0 commit comments

Comments
 (0)