From acaef9ffd9dc92f65950cad64241ccc1e5dd2747 Mon Sep 17 00:00:00 2001 From: Norman Bukingolts <78187320+norman-codes@users.noreply.github.com> Date: Wed, 3 Jul 2024 13:51:31 -0700 Subject: [PATCH] Updates and adds the raw-text-processor example (#71) Co-authored-by: Norman Bukingolts Co-authored-by: zach --- README.md | 33 +- evi-typescript-example/package.json | 2 +- typescript-raw-text-processor/.env.example | 1 + typescript-raw-text-processor/.gitignore | 2 + typescript-raw-text-processor/README.md | 29 ++ .../package-lock.json | 414 ++++++++++++++++++ typescript-raw-text-processor/package.json | 24 + typescript-raw-text-processor/src/index.ts | 56 +++ typescript-raw-text-processor/tsconfig.json | 14 + 9 files changed, 558 insertions(+), 17 deletions(-) create mode 100644 typescript-raw-text-processor/.env.example create mode 100644 typescript-raw-text-processor/.gitignore create mode 100644 typescript-raw-text-processor/README.md create mode 100644 typescript-raw-text-processor/package-lock.json create mode 100644 typescript-raw-text-processor/package.json create mode 100644 typescript-raw-text-processor/src/index.ts create mode 100644 typescript-raw-text-processor/tsconfig.json diff --git a/README.md b/README.md index 356c971..39f6033 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,24 @@ This repository contains examples of how to use the [Hume API](https://docs.hume ## [Empathic Voice Interface (EVI)](https://dev.hume.ai/docs/empathic-voice-interface-evi/overview) -| Name | Language | Framework | -| ------------------------------------------------------------------- | ---------- | --------- | -| [`evi-custom-language-model`](/evi-custom-language-model/README.md) | Python | | -| [`evi-modal-clm`](/evi-modal-clm/README.md) | Python | Modal | -| [`evi-next-js-app-router`](/evi-next-js-app-router/README.md) | Typescript | Next.js | -| [`evi-next-js-pages-router`](/evi-next-js-pages-router/README.md) | Typescript | Next.js | -| [`evi-typescript-example`](/evi-typescript-example/README.md) | Typescript | | -| [`evi-embed-vue`](/evi-embed-vue/README.md) | Typescript | Vue | +| Name | Language | Framework | +| ------------------------------------------------------------------- | ---------- | --------------- | +| [`evi-custom-language-model`](/evi-custom-language-model/README.md) | Python | | +| [`evi-modal-clm`](/evi-modal-clm/README.md) | Python | Modal | +| [`evi-next-js-app-router`](/evi-next-js-app-router/README.md) | Typescript | Next.js | +| [`evi-next-js-pages-router`](/evi-next-js-pages-router/README.md) | Typescript | Next.js | +| [`evi-typescript-example`](/evi-typescript-example/README.md) | Typescript | | +| [`evi-embed-vue`](/evi-embed-vue/README.md) | Typescript | Vue | | [`evi-python-example`](/evi-python-example/README.md) | Python | Hume Python SDK | -| [`evi-python-api-example`](/evi-python-api-example/README.md) | Python | | -| [`meld`](/meld/README.md) (`evi-react-example`) | Typescript | React | +| [`evi-python-api-example`](/evi-python-api-example/README.md) | Python | | +| [`meld`](/meld/README.md) (`evi-react-example`) | Typescript | React | ## [Expression Measurement API](https://dev.hume.ai/docs/expression-measurement-api/overview) -| Name | Models | Language | Framework | -| -------------------------------------------------------------------------- | ------------------------------------- | ---------- | --------- | -| [`python-top-emotions`](/python-top-emotions/top_emotions.py) | `face` | Python | | -| [`visualization-example`](./visualization-example/example-notebook.ipynb) | `face` | Python | | -| [`typescript-next-api-language`](./typescript-next-api-language/README.md) | `language` | Typescript | Next.js | -| [`typescript-streaming-sandbox`](./typescript-streaming-sandbox/README.md) | `language`, `face`, `burst`, `speech` | Typescript | Next.js | +| Name | Models | Language | Framework | +| ---------------------------------------------------------------------------- | ------------------------------------- | ---------- | --------- | +| [`python-top-emotions`](/python-top-emotions/top_emotions.py) | `face` | Python | | +| [`visualization-example`](./visualization-example/example-notebook.ipynb) | `face` | Python | | +| [`typescript-next-api-language`](./typescript-next-api-language/README.md) | `language` | Typescript | Next.js | +| [`typescript-streaming-sandbox`](./typescript-streaming-sandbox/README.md) | `language`, `face`, `burst`, `speech` | Typescript | Next.js | +| [`typescript-raw-text-processor`](./typescript-raw-text-processor/README.md) | `language` | Typescript | | diff --git a/evi-typescript-example/package.json b/evi-typescript-example/package.json index 6ea5080..6749f1c 100644 --- a/evi-typescript-example/package.json +++ b/evi-typescript-example/package.json @@ -9,7 +9,7 @@ "preview": "vite preview" }, "dependencies": { - "hume": "^0.7.0" + "hume": "^0.7.2" }, "devDependencies": { "typescript": "^5.2.2", diff --git a/typescript-raw-text-processor/.env.example b/typescript-raw-text-processor/.env.example new file mode 100644 index 0000000..7c57108 --- /dev/null +++ b/typescript-raw-text-processor/.env.example @@ -0,0 +1 @@ +HUME_API_KEY='' \ No newline at end of file diff --git a/typescript-raw-text-processor/.gitignore b/typescript-raw-text-processor/.gitignore new file mode 100644 index 0000000..76add87 --- /dev/null +++ b/typescript-raw-text-processor/.gitignore @@ -0,0 +1,2 @@ +node_modules +dist \ No newline at end of file diff --git a/typescript-raw-text-processor/README.md b/typescript-raw-text-processor/README.md new file mode 100644 index 0000000..3b53836 --- /dev/null +++ b/typescript-raw-text-processor/README.md @@ -0,0 +1,29 @@ +# Hume Raw Text Processor + +## Summary + +This project serves as an example implementation of our Expression Measurement (REST) API processing raw text using our [Typescript SDK](https://www.npmjs.com/package/hume). + +## Running Locally + +1. Clone the repo with `git clone origin https://github.com/HumeAI/hume-api-examples.git` + +2. Navigate to project directory `cd typescript-raw-text-processor` + +3. Install dependencies with `npm i` + +4. Setup environment variables + + a. Create `.env` file based off of `.env.example` + + b. Copy/paste your API key in from the [Portal](https://beta.hume.ai/settings/keys). + +5. Set configurations within the `src/index.ts` file. + + a. Specify which language. + + b. Copy and paste the text to be processed. + + c. Set Language Model configurations. + +6. Run `npm run start` to process the specified text with the specified configurations and log predictions to the console. diff --git a/typescript-raw-text-processor/package-lock.json b/typescript-raw-text-processor/package-lock.json new file mode 100644 index 0000000..164e0eb --- /dev/null +++ b/typescript-raw-text-processor/package-lock.json @@ -0,0 +1,414 @@ +{ + "name": "hume-raw-text-processor", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "hume-raw-text-processor", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "dotenv": "^16.4.5", + "hume": "^0.7.2" + }, + "devDependencies": { + "@types/node": "^20.8.7", + "typescript": "^5.2.2" + } + }, + "node_modules/@types/node": { + "version": "20.8.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.8.7.tgz", + "integrity": "sha512-21TKHHh3eUHIi2MloeptJWALuCu5H7HQTdTrWIFReA8ad+aggoX+lRes3ex7/FtpC+sVUpFMQ+QTfYr74mruiQ==", + "dev": true, + "dependencies": { + "undici-types": "~5.25.1" + } + }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==" + }, + "node_modules/call-bind": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dependencies": { + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/form-data-encoder": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-4.0.2.tgz", + "integrity": "sha512-KQVhvhK8ZkWzxKxOr56CPulAhH3dobtuQ4+hNQ+HekH/Wp5gSOafqRAeTphQUJAIk0GBvHZgJ2ZGRWd5kphMuw==", + "engines": { + "node": ">= 18" + } + }, + "node_modules/formdata-node": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-6.0.3.tgz", + "integrity": "sha512-8e1++BCiTzUno9v5IZ2J6bv4RU+3UKDmqWUQD0MIMVCd9AdhWkO1gw57oo1mNEX1dMq2EGI+FbWz4B92pscSQg==", + "engines": { + "node": ">= 18" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "dependencies": { + "es-define-property": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-proto": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/hume": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/hume/-/hume-0.7.2.tgz", + "integrity": "sha512-92TGLCJICJG9lXqcTv1+tAXvqxwPFdEW0Q+C70X9H6IVWwO1ZToU28yNAie9vBpVnjsJio9vThmONZXtdPVZGg==", + "dependencies": { + "form-data": "4.0.0", + "form-data-encoder": "^4.0.2", + "formdata-node": "^6.0.3", + "node-fetch": "2.7.0", + "qs": "6.11.2", + "url-join": "4.0.1", + "uuid": "9.0.1", + "ws": "^8.14.2" + } + }, + "node_modules/mime-db": { + "version": "1.52.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", + "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "2.1.35", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz", + "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", + "dependencies": { + "mime-db": "1.52.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-fetch": { + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/object-inspect": { + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.2.tgz", + "integrity": "sha512-IRZSRuzJiynemAXPYtPe5BoI/RESNYR7TYm50MC5Mqbd3Jmw5y790sErYw3V6SryFJD64b74qQQs9wn5Bg/k3g==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/qs": { + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz", + "integrity": "sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==", + "dependencies": { + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/side-channel": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", + "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", + "dependencies": { + "call-bind": "^1.0.7", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.4", + "object-inspect": "^1.13.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, + "node_modules/typescript": { + "version": "5.2.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.2.2.tgz", + "integrity": "sha512-mI4WrpHsbCIcwT9cF4FZvr80QUeKvsUsUvKDoR+X/7XHQH98xYD8YHZg7ANtz2GtZt/CBq2QJ0thkGJMHfqc1w==", + "dev": true, + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "5.25.3", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.25.3.tgz", + "integrity": "sha512-Ga1jfYwRn7+cP9v8auvEXN1rX3sWqlayd4HP7OKk4mZWylEmu3KzXDUGrQUN6Ol7qo1gPvB2e5gX6udnyEPgdA==", + "dev": true + }, + "node_modules/url-join": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", + "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" + }, + "node_modules/uuid": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz", + "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/ws": { + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/ws/-/ws-8.17.1.tgz", + "integrity": "sha512-6XQFvXTkbfUOZOKKILFG1PDK2NDQs4azKQl26T0YS5CxqWLgXajbPZ+h4gZekJyRqFU8pvnbAbbs/3TgRPy+GQ==", + "engines": { + "node": ">=10.0.0" + }, + "peerDependencies": { + "bufferutil": "^4.0.1", + "utf-8-validate": ">=5.0.2" + }, + "peerDependenciesMeta": { + "bufferutil": { + "optional": true + }, + "utf-8-validate": { + "optional": true + } + } + } + } +} diff --git a/typescript-raw-text-processor/package.json b/typescript-raw-text-processor/package.json new file mode 100644 index 0000000..ec98c37 --- /dev/null +++ b/typescript-raw-text-processor/package.json @@ -0,0 +1,24 @@ +{ + "name": "hume-raw-text-processor", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "module", + "scripts": { + "start": "tsc && node dist/index.js", + "build": "tsc", + "lint": "eslint 'src/**/*.{ts,tsx}'", + "format": "prettier --write 'src/**/*.{ts,tsx}'" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "dotenv": "^16.4.5", + "hume": "^0.7.2" + }, + "devDependencies": { + "@types/node": "^20.8.7", + "typescript": "^5.2.2" + } +} diff --git a/typescript-raw-text-processor/src/index.ts b/typescript-raw-text-processor/src/index.ts new file mode 100644 index 0000000..15548ce --- /dev/null +++ b/typescript-raw-text-processor/src/index.ts @@ -0,0 +1,56 @@ +import { Hume, HumeClient } from 'hume'; +import dotenv from 'dotenv'; + +dotenv.config(); + +(async () => { + /** + * Specify which language is used for the input text. + * See our documentation on supported languages: + * - https://dev.hume.ai/docs/expression-measurement-api/faq#which-languages-are-supported + */ + const language: Hume.expressionMeasurement.Bcp47Tag = 'en'; // English (default) + + /** + * Specify the raw text to be processed. + */ + const text: string = 'Hello world!'; + + /** + * Specify language model configuration for the Expression Measurement API + * See our documentation on our Language Model + * - https://dev.hume.ai/docs/resources/science#emotional-language + * - https://dev.hume.ai/reference/expression-measurement-api/batch/start-inference-job#request.body.models.language.granularity + */ + const languageModelConfig: Hume.expressionMeasurement.Language = { + granularity: Hume.expressionMeasurement.Granularity.Sentence, + // sentiment: {}, // uncomment to include sentiment analysis in predictions + // toxicity: {}, // uncomment to include toxicity analysis in predictions + identifySpeakers: false, // set to true to include speaker diarization + }; + + // Instantiate hume client with API key + const humeClient = new HumeClient({ + apiKey: String(process.env.HUME_API_KEY), + }); + + // Specify job configuration + const jobConfig: Hume.expressionMeasurement.InferenceBaseRequest = { + text: [text], + models: { language: languageModelConfig }, + transcription: { language }, + }; + + // Submit Job + const job = await humeClient.expressionMeasurement.batch.startInferenceJob(jobConfig); + + // Await Job to complete + await job.awaitCompletion(); + + // Fetch Job predictions by Job ID + const results = await humeClient.expressionMeasurement.batch.getJobPredictions(job.jobId); + + // Log Job predictions to the console and close the program + console.log(JSON.stringify(results, null, 2)); + process.exit(0); +})(); diff --git a/typescript-raw-text-processor/tsconfig.json b/typescript-raw-text-processor/tsconfig.json new file mode 100644 index 0000000..d6d748f --- /dev/null +++ b/typescript-raw-text-processor/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "target": "ES6", + "module": "ES6", + "moduleResolution": "node", + "outDir": "./dist", + "rootDir": "./src", + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true + }, + "include": ["src"], + "exclude": ["node_modules", "dist"] +}