Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌿 Fern Regeneration -- April 10, 2024 #15

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hume",
"version": "0.4.2",
"version": "0.5.0",
"private": false,
"repository": "https://github.com/HumeAI/hume-typescript-sdk",
"main": "./index.js",
Expand Down
324 changes: 12 additions & 312 deletions src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

import * as environments from "./environments";
import * as core from "./core";
import * as Hume from "./api";
import urlJoin from "url-join";
import * as serializers from "./serialization";
import * as errors from "./errors";
import * as stream from "stream";
import { CustomModels } from "./api/resources/customModels/client/Client";
import { ExpressionMeasurement } from "./api/resources/expressionMeasurement/client/Client";

export declare namespace HumeClient {
interface Options {
environment?: core.Supplier<environments.HumeEnvironment | string>;
apiKey: core.Supplier<string>;
apiKey?: core.Supplier<string | undefined>;
accountToken?: core.Supplier<string | undefined>;
fetcher?: core.FetchFunction;
}

interface RequestOptions {
Expand All @@ -23,316 +22,17 @@ export declare namespace HumeClient {
}

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

/**
* Sort and filter jobs.
*
* @example
* await hume.listJobs({})
*/
public async listJobs(
request: Hume.ListJobsRequest = {},
requestOptions?: HumeClient.RequestOptions
): Promise<Hume.JobRequest[]> {
const { limit, status, when, timestampMs, sortBy, direction } = request;
const _queryParams: Record<string, string | string[]> = {};
if (limit != null) {
_queryParams["limit"] = limit.toString();
}
protected _customModels: CustomModels | undefined;

if (status != null) {
if (Array.isArray(status)) {
_queryParams["status"] = status.map((item) => item);
} else {
_queryParams["status"] = status;
}
}

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

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

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

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

const _response = await core.fetcher({
url: urlJoin(
(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-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "hume",
"X-Fern-SDK-Version": "0.4.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
queryParameters: _queryParams,
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return await serializers.listJobs.Response.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
}

if (_response.error.reason === "status-code") {
throw new errors.HumeError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}

switch (_response.error.reason) {
case "non-json":
throw new errors.HumeError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.HumeTimeoutError();
case "unknown":
throw new errors.HumeError({
message: _response.error.errorMessage,
});
}
}

/**
* Start a new batch job.
*
* @example
* await hume.submitJob({})
*/
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,
"v0/batch/jobs"
),
method: "POST",
headers: {
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "hume",
"X-Fern-SDK-Version": "0.4.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
body: await serializers.BaseRequest.jsonOrThrow(request, { unrecognizedObjectKeys: "strip" }),
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return await serializers.JobId.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
}

if (_response.error.reason === "status-code") {
throw new errors.HumeError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}

switch (_response.error.reason) {
case "non-json":
throw new errors.HumeError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.HumeTimeoutError();
case "unknown":
throw new errors.HumeError({
message: _response.error.errorMessage,
});
}
}

/**
* Get the JSON predictions of a completed job.
*
* @example
* await hume.getJobPredictions("id")
*/
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,
`v0/batch/jobs/${id}/predictions`
),
method: "GET",
headers: {
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "hume",
"X-Fern-SDK-Version": "0.4.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return await serializers.getJobPredictions.Response.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
}

if (_response.error.reason === "status-code") {
throw new errors.HumeError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}

switch (_response.error.reason) {
case "non-json":
throw new errors.HumeError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.HumeTimeoutError();
case "unknown":
throw new errors.HumeError({
message: _response.error.errorMessage,
});
}
public get customModels(): CustomModels {
return (this._customModels ??= new CustomModels(this._options));
}

/**
* Get the artifacts ZIP of a completed job.
*/
public async getJobArtifacts(id: string, requestOptions?: HumeClient.RequestOptions): Promise<stream.Readable> {
const _response = await core.fetcher<stream.Readable>({
url: urlJoin(
(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-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "hume",
"X-Fern-SDK-Version": "0.4.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
responseType: "streaming",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return _response.body;
}

if (_response.error.reason === "status-code") {
throw new errors.HumeError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}

switch (_response.error.reason) {
case "non-json":
throw new errors.HumeError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.HumeTimeoutError();
case "unknown":
throw new errors.HumeError({
message: _response.error.errorMessage,
});
}
}

/**
* Get the request details and state of a given job.
*/
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,
`v0/batch/jobs/${id}`
),
method: "GET",
headers: {
"X-Hume-Api-Key": await core.Supplier.get(this._options.apiKey),
"X-Fern-Language": "JavaScript",
"X-Fern-SDK-Name": "hume",
"X-Fern-SDK-Version": "0.4.2",
"X-Fern-Runtime": core.RUNTIME.type,
"X-Fern-Runtime-Version": core.RUNTIME.version,
},
contentType: "application/json",
timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000,
maxRetries: requestOptions?.maxRetries,
});
if (_response.ok) {
return await serializers.JobRequest.parseOrThrow(_response.body, {
unrecognizedObjectKeys: "passthrough",
allowUnrecognizedUnionMembers: true,
allowUnrecognizedEnumValues: true,
breadcrumbsPrefix: ["response"],
});
}

if (_response.error.reason === "status-code") {
throw new errors.HumeError({
statusCode: _response.error.statusCode,
body: _response.error.body,
});
}
protected _expressionMeasurement: ExpressionMeasurement | undefined;

switch (_response.error.reason) {
case "non-json":
throw new errors.HumeError({
statusCode: _response.error.statusCode,
body: _response.error.rawBody,
});
case "timeout":
throw new errors.HumeTimeoutError();
case "unknown":
throw new errors.HumeError({
message: _response.error.errorMessage,
});
}
public get expressionMeasurement(): ExpressionMeasurement {
return (this._expressionMeasurement ??= new ExpressionMeasurement(this._options));
}
}
2 changes: 0 additions & 2 deletions src/api/client/requests/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from "./types";
export * from "./client";
export * from "./resources";
Loading
Loading