Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed Oct 30, 2023
1 parent 26b324c commit 715d4fa
Show file tree
Hide file tree
Showing 29 changed files with 522 additions and 84 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fern-api/hume",
"version": "0.0.10",
"version": "0.1.0",
"private": false,
"repository": "https://github.com/fern-hume/hume-typescript-sdk",
"main": "./index.js",
Expand All @@ -11,10 +11,11 @@
"prepack": "cp -rv dist/. ."
},
"dependencies": {
"@ungap/url-search-params": "0.2.2",
"url-join": "4.0.1",
"@types/url-join": "4.0.1",
"axios": "0.27.2"
"axios": "0.27.2",
"qs": "6.11.2",
"@types/qs": "6.9.8"
},
"devDependencies": {
"@types/node": "17.0.33",
Expand Down
90 changes: 54 additions & 36 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import * as environments from "./environments";
import * as core from "./core";
import * as Hume from "./api";
import { default as URLSearchParams } from "@ungap/url-search-params";
import urlJoin from "url-join";
import * as serializers from "./serialization";
import * as errors from "./errors";
Expand All @@ -15,62 +14,71 @@ export declare namespace HumeClient {
environment?: core.Supplier<environments.HumeEnvironment | string>;
apiKey: core.Supplier<string>;
}

interface RequestOptions {
timeoutInSeconds?: number;
maxRetries?: number;
}
}

export class HumeClient {
constructor(protected readonly options: HumeClient.Options) {}
constructor(protected readonly _options: HumeClient.Options) {}

/**
* Sort and filter jobs.
*/
public async listJobs(request: Hume.ListJobsRequest = {}): Promise<Hume.JobRequest[]> {
public async listJobs(
request: Hume.ListJobsRequest = {},
requestOptions?: HumeClient.RequestOptions
): Promise<Hume.JobRequest[]> {
const { limit, status, when, timestampMs, sortBy, direction } = request;
const _queryParams = new URLSearchParams();
const _queryParams: Record<string, string> = {};
if (limit != null) {
_queryParams.append("limit", limit.toString());
_queryParams["limit"] = limit.toString();
}

if (status != null) {
if (Array.isArray(status)) {
for (const _item of status) {
_queryParams.append("status", _item);
_queryParams["status"] = _item;
}
} else {
_queryParams.append("status", status);
_queryParams["status"] = status;
}
}

if (when != null) {
_queryParams.append("when", when);
_queryParams["when"] = when;
}

if (timestampMs != null) {
_queryParams.append("timestamp_ms", timestampMs.toString());
_queryParams["timestamp_ms"] = timestampMs.toString();
}

if (sortBy != null) {
_queryParams.append("sort_by", sortBy);
_queryParams["sort_by"] = sortBy;
}

if (direction != null) {
_queryParams.append("direction", direction);
_queryParams["direction"] = direction;
}

const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this.options.environment)) ?? environments.HumeEnvironment.Default,
(await core.Supplier.get(this._options.environment)) ?? environments.HumeEnvironment.Default,
"v0/batch/jobs"
),
method: "GET",
headers: {
"X-Hume-Api-Key": await core.Supplier.get(this.options.apiKey),
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@fern-api/hume",
"X-Fern-SDK-Version": "0.0.10",
"X-Fern-SDK-Version": "0.1.0",
},
contentType: "application/json",
queryParameters: _queryParams,
timeoutMs: 60000,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return await serializers.listJobs.Response.parseOrThrow(_response.body, {
Expand Down Expand Up @@ -106,22 +114,26 @@ export class HumeClient {
/**
* Start a new batch job.
*/
public async submitJob(request: Hume.BaseRequest = {}): Promise<Hume.JobId> {
public async submitJob(
request: Hume.BaseRequest = {},
requestOptions?: HumeClient.RequestOptions
): Promise<Hume.JobId> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this.options.environment)) ?? environments.HumeEnvironment.Default,
(await core.Supplier.get(this._options.environment)) ?? environments.HumeEnvironment.Default,
"v0/batch/jobs"
),
method: "POST",
headers: {
"X-Hume-Api-Key": await core.Supplier.get(this.options.apiKey),
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@fern-api/hume",
"X-Fern-SDK-Version": "0.0.10",
"X-Fern-SDK-Version": "0.1.0",
},
contentType: "application/json",
body: await serializers.BaseRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
timeoutMs: 60000,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return await serializers.JobId.parseOrThrow(_response.body, {
Expand Down Expand Up @@ -157,21 +169,25 @@ export class HumeClient {
/**
* Get the JSON predictions of a completed job.
*/
public async getJobPredictions(id: string): Promise<Hume.SourceResult[]> {
public async getJobPredictions(
id: string,
requestOptions?: HumeClient.RequestOptions
): Promise<Hume.SourceResult[]> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this.options.environment)) ?? environments.HumeEnvironment.Default,
(await core.Supplier.get(this._options.environment)) ?? environments.HumeEnvironment.Default,
`v0/batch/jobs/${id}/predictions`
),
method: "GET",
headers: {
"X-Hume-Api-Key": await core.Supplier.get(this.options.apiKey),
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@fern-api/hume",
"X-Fern-SDK-Version": "0.0.10",
"X-Fern-SDK-Version": "0.1.0",
},
contentType: "application/json",
timeoutMs: 60000,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return await serializers.getJobPredictions.Response.parseOrThrow(_response.body, {
Expand Down Expand Up @@ -207,22 +223,23 @@ export class HumeClient {
/**
* Get the artifacts ZIP of a completed job.
*/
public async getJobArtifacts(id: string): Promise<Blob> {
const _response = await core.fetcher({
public async getJobArtifacts(id: string, requestOptions?: HumeClient.RequestOptions): Promise<Blob> {
const _response = await core.fetcher<Blob>({
url: urlJoin(
(await core.Supplier.get(this.options.environment)) ?? environments.HumeEnvironment.Default,
(await core.Supplier.get(this._options.environment)) ?? environments.HumeEnvironment.Default,
`v0/batch/jobs/${id}/artifacts`
),
method: "GET",
headers: {
"X-Hume-Api-Key": await core.Supplier.get(this.options.apiKey),
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@fern-api/hume",
"X-Fern-SDK-Version": "0.0.10",
"X-Fern-SDK-Version": "0.1.0",
},
contentType: "application/json",
responseType: "blob",
timeoutMs: 60000,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return _response.body;
Expand Down Expand Up @@ -253,21 +270,22 @@ export class HumeClient {
/**
* Get the request details and state of a given job.
*/
public async getJobDetails(id: string): Promise<Hume.JobRequest> {
public async getJobDetails(id: string, requestOptions?: HumeClient.RequestOptions): Promise<Hume.JobRequest> {
const _response = await core.fetcher({
url: urlJoin(
(await core.Supplier.get(this.options.environment)) ?? environments.HumeEnvironment.Default,
(await core.Supplier.get(this._options.environment)) ?? environments.HumeEnvironment.Default,
`v0/batch/jobs/${id}`
),
method: "GET",
headers: {
"X-Hume-Api-Key": await core.Supplier.get(this.options.apiKey),
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "@fern-api/hume",
"X-Fern-SDK-Version": "0.0.10",
"X-Fern-SDK-Version": "0.1.0",
},
contentType: "application/json",
timeoutMs: 60000,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return await serializers.JobRequest.parseOrThrow(_response.body, {
Expand Down
8 changes: 4 additions & 4 deletions src/api/types/BoundingBox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
*/
export interface BoundingBox {
/** x-coordinate of bounding box top left corner. */
x: number;
x?: number;
/** y-coordinate of bounding box top left corner. */
y: number;
y?: number;
/** Bounding box width. */
w: number;
w?: number;
/** Bounding box height. */
h: number;
h?: number;
}
10 changes: 10 additions & 0 deletions src/api/types/EmotionEmbedding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as Hume from "..";

/**
* A high-dimensional embedding in emotion space.
*/
export type EmotionEmbedding = Hume.EmotionEmbeddingItem[];
10 changes: 10 additions & 0 deletions src/api/types/EmotionEmbeddingItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

export interface EmotionEmbeddingItem {
/** Name of the emotion being expressed. */
name?: string;
/** Embedding value for the emotion being expressed. */
score?: number;
}
12 changes: 12 additions & 0 deletions src/api/types/Sentiment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as Hume from "..";

/**
* 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).
*
* 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.
*/
export type Sentiment = Hume.SentimentItem[];
10 changes: 10 additions & 0 deletions src/api/types/SentimentItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

export interface SentimentItem {
/** Level of sentiment, ranging from 1 (negative) to 9 (positive) */
name?: string;
/** Prediction for this level of sentiment */
score?: number;
}
14 changes: 14 additions & 0 deletions src/api/types/TextPosition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

/**
* 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.
*
*/
export interface TextPosition {
/** The index of the first character in the text segment, inclusive. */
begin?: number;
/** The index of the last character in the text segment, exclusive. */
end?: number;
}
13 changes: 13 additions & 0 deletions src/api/types/TimeRange.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

/**
* A time range with a beginning and end, measured in seconds.
*/
export interface TimeRange {
/** Beginning of time range in seconds. */
begin?: number;
/** End of time range in seconds. */
end?: number;
}
10 changes: 10 additions & 0 deletions src/api/types/Toxicity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

import * as Hume from "..";

/**
* Toxicity predictions returned as probabilities that the text can be classified into the following categories: toxic, severe_toxic, obscene, threat, insult, and identity_hate.
*/
export type Toxicity = Hume.ToxicityItem[];
10 changes: 10 additions & 0 deletions src/api/types/ToxicityItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* This file was auto-generated by Fern from our API Definition.
*/

export interface ToxicityItem {
/** Category of toxicity. */
name?: string;
/** Prediction for this category of toxicity */
score?: number;
}
8 changes: 8 additions & 0 deletions src/api/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ export * from "./TranscriptionMetadata";
export * from "./Url";
export * from "./When";
export * from "./Window";
export * from "./EmotionEmbedding";
export * from "./EmotionEmbeddingItem";
export * from "./TimeRange";
export * from "./TextPosition";
export * from "./Sentiment";
export * from "./SentimentItem";
export * from "./Toxicity";
export * from "./ToxicityItem";
Loading

0 comments on commit 715d4fa

Please sign in to comment.