0.2.3 • Published 6 months ago

@fern-api/hume v0.2.3

Weekly downloads
-
License
-
Repository
github
Last release
6 months ago

Documentation

API reference documentation is available here.

Installation

npm install --save @fern-api/hume
# or
yarn add @fern-api/hume

Batch Client

The SDK exports a batch client which you can use to hit our REST APIs.

import { HumeBatchClient } from "@fern-api/hume";

const client = new HumeBatchClient({
    apiKey: "YOUR_API_KEY",
});

const job = await client.submitJob({
    urls: ["https://tinyurl.com/hume-img"],
    models: {
        face: {},
    },
});

console.log("Running...");
await job.awaitCompletion();

Streaming Client

The SDK exports a streaming client which you can use to hit our WebSocket APIs.

import { HumeStreamingClient } from "@fern-api/hume";

const client = new HumeStreamingClient({
    apiKey: "YOUR_API_KEY",
});

const stream = await client.connect({
    configs: {
        language: {},
    },
    onMessage: (response) => {
        if (response.language != null) {
            console.log(response.language.predictions);
        }
    },
    onError: (err) => {
      console.log(err);
    }
});

stream.sendText({
    text: "Mary had a little lamb,"
});

Errors

When the API returns a non-success status code (4xx or 5xx response), a subclass of [HumeError](./src/errors/HumeError.ts) will be thrown:

import { HumeError, HumeTimeoutError } from "@fern-api/hume";

try {
    await hume.submitJob(/* ... */);
} catch (err) {
    if (err instanceof HumeTimeoutError) {
        console.log("Request timed out", err);
    } else if (err instanceof HumeError) {
        // catch all errros
        console.log(err.statusCode);
        console.log(err.message);
        console.log(err.body);
    }
}

Retries

409 Conflict, 429 Rate Limit, and >=500 Internal errors will all be retried twice with exponential bakcoff. You can use the maxRetries option to configure this behavior:

await hume.submitJob(..., {
    maxRetries: 0, // disable retries
});

Timeouts

By default, the SDK has a timeout of 60s. You can use the timeoutInSeconds option to configure this behavior

await hume.submitJob(..., {
    timeoutInSeconds: 10, // timeout after 10 seconds
});

Beta status

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning the package version to a specific version in your package.json file. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

0.1.0

6 months ago

0.2.1

6 months ago

0.1.1

6 months ago

0.2.3

6 months ago

0.1.4

6 months ago

0.2.2

6 months ago

0.1.3

6 months ago

0.1.5

6 months ago

0.0.10

12 months ago

0.0.7

12 months ago

0.0.6

12 months ago

0.0.5

12 months ago

0.0.4

12 months ago

0.0.3

12 months ago

0.0.2

12 months ago

0.0.1

12 months ago