diff --git a/.pnp.cjs b/.pnp.cjs index e29f77b56..efd85b3be 100755 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -7055,6 +7055,7 @@ const RAW_RUNTIME_STATE = ["@types/yaml", "npm:1.9.7"],\ ["@typescript-eslint/eslint-plugin", "virtual:36b10b38a2f3e49d8cd162fbeda8e49e065ae2d0ebbbd25b0a3339d0203e0ec0394d852d27989cf9f4297d5cf181367ebbc4ea51690fe53337f9c0c2783178a4#npm:6.9.0"],\ ["@typescript-eslint/parser", "virtual:36b10b38a2f3e49d8cd162fbeda8e49e065ae2d0ebbbd25b0a3339d0203e0ec0394d852d27989cf9f4297d5cf181367ebbc4ea51690fe53337f9c0c2783178a4#npm:6.9.0"],\ + ["assemblyai", "npm:3.0.1"],\ ["autoevals", "npm:0.0.26"],\ ["crypto-js", "npm:4.1.1"],\ ["emittery", "npm:1.0.1"],\ @@ -11452,6 +11453,16 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }]\ ]],\ + ["assemblyai", [\ + ["npm:3.0.1", {\ + "packageLocation": "./.yarn/cache/assemblyai-npm-3.0.1-41a2932ec5-bfa7c25c89.zip/node_modules/assemblyai/",\ + "packageDependencies": [\ + ["assemblyai", "npm:3.0.1"],\ + ["ws", "virtual:41a2932ec57dd2cd1a341c0608ef13d6640c3fd069a4ff63bcb6df738241512b3dcf072b1883b6b5389ebd428878606e1146ebd4ea8b50438ca40a7d86e23323#npm:8.13.0"]\ + ],\ + "linkType": "HARD"\ + }]\ + ]],\ ["ast-types-flow", [\ ["npm:0.0.7", {\ "packageLocation": "./.yarn/cache/ast-types-flow-npm-0.0.7-7d32a3abf5-663b90e99b.zip/node_modules/ast-types-flow/",\ @@ -12092,7 +12103,7 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }],\ ["npm:1.0.5", {\ - "packageLocation": "./.yarn/cache/call-bind-npm-1.0.5-65600fae47-246d44db6e.zip/node_modules/call-bind/",\ + "packageLocation": "./.yarn/cache/call-bind-npm-1.0.5-65600fae47-878d30c1f2.zip/node_modules/call-bind/",\ "packageDependencies": [\ ["call-bind", "npm:1.0.5"],\ ["function-bind", "npm:1.1.2"],\ @@ -13428,7 +13439,7 @@ const RAW_RUNTIME_STATE = ]],\ ["define-data-property", [\ ["npm:1.1.1", {\ - "packageLocation": "./.yarn/cache/define-data-property-npm-1.1.1-2b5156d112-5573c8df96.zip/node_modules/define-data-property/",\ + "packageLocation": "./.yarn/cache/define-data-property-npm-1.1.1-2b5156d112-ba1eff4710.zip/node_modules/define-data-property/",\ "packageDependencies": [\ ["define-data-property", "npm:1.1.1"],\ ["get-intrinsic", "npm:1.2.1"],\ @@ -16411,7 +16422,7 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }],\ ["npm:1.1.2", {\ - "packageLocation": "./.yarn/cache/function-bind-npm-1.1.2-7a55be9b03-185e20d20f.zip/node_modules/function-bind/",\ + "packageLocation": "./.yarn/cache/function-bind-npm-1.1.2-7a55be9b03-0b7e4d0c3f.zip/node_modules/function-bind/",\ "packageDependencies": [\ ["function-bind", "npm:1.1.2"]\ ],\ @@ -16959,7 +16970,7 @@ const RAW_RUNTIME_STATE = ]],\ ["hasown", [\ ["npm:2.0.0", {\ - "packageLocation": "./.yarn/cache/hasown-npm-2.0.0-78b794ceef-c330f8d93f.zip/node_modules/hasown/",\ + "packageLocation": "./.yarn/cache/hasown-npm-2.0.0-78b794ceef-99a39452e2.zip/node_modules/hasown/",\ "packageDependencies": [\ ["hasown", "npm:2.0.0"],\ ["function-bind", "npm:1.1.2"]\ @@ -17736,7 +17747,7 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }],\ ["npm:2.13.1", {\ - "packageLocation": "./.yarn/cache/is-core-module-npm-2.13.1-36e17434f9-d53bd0cc24.zip/node_modules/is-core-module/",\ + "packageLocation": "./.yarn/cache/is-core-module-npm-2.13.1-36e17434f9-3e562fc6da.zip/node_modules/is-core-module/",\ "packageDependencies": [\ ["is-core-module", "npm:2.13.1"],\ ["hasown", "npm:2.0.0"]\ @@ -17809,7 +17820,7 @@ const RAW_RUNTIME_STATE = ]],\ ["is-generator-function", [\ ["npm:1.0.10", {\ - "packageLocation": "./.yarn/cache/is-generator-function-npm-1.0.10-1d0f3809ef-499a3ce636.zip/node_modules/is-generator-function/",\ + "packageLocation": "./.yarn/cache/is-generator-function-npm-1.0.10-1d0f3809ef-5ddb05cd61.zip/node_modules/is-generator-function/",\ "packageDependencies": [\ ["is-generator-function", "npm:1.0.10"],\ ["has-tostringtag", "npm:1.0.0"]\ @@ -18076,7 +18087,7 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }],\ ["npm:1.1.12", {\ - "packageLocation": "./.yarn/cache/is-typed-array-npm-1.1.12-6135c91b1a-d953adfd3c.zip/node_modules/is-typed-array/",\ + "packageLocation": "./.yarn/cache/is-typed-array-npm-1.1.12-6135c91b1a-bbc1e04914.zip/node_modules/is-typed-array/",\ "packageDependencies": [\ ["is-typed-array", "npm:1.1.12"],\ ["which-typed-array", "npm:1.1.13"]\ @@ -23034,7 +23045,7 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }],\ ["patch:resolve@npm%3A1.22.8#optional!builtin::version=1.22.8&hash=c3c19d", {\ - "packageLocation": "./.yarn/cache/resolve-patch-4254c24959-f345cd37f5.zip/node_modules/resolve/",\ + "packageLocation": "./.yarn/cache/resolve-patch-4254c24959-cee9035c50.zip/node_modules/resolve/",\ "packageDependencies": [\ ["resolve", "patch:resolve@npm%3A1.22.8#optional!builtin::version=1.22.8&hash=c3c19d"],\ ["is-core-module", "npm:2.13.1"],\ @@ -23537,7 +23548,7 @@ const RAW_RUNTIME_STATE = ]],\ ["set-function-length", [\ ["npm:1.1.1", {\ - "packageLocation": "./.yarn/cache/set-function-length-npm-1.1.1-d362bf8221-745ed1d7dc.zip/node_modules/set-function-length/",\ + "packageLocation": "./.yarn/cache/set-function-length-npm-1.1.1-d362bf8221-7e1b509986.zip/node_modules/set-function-length/",\ "packageDependencies": [\ ["set-function-length", "npm:1.1.1"],\ ["define-data-property", "npm:1.1.1"],\ @@ -25573,7 +25584,7 @@ const RAW_RUNTIME_STATE = ]],\ ["util", [\ ["npm:0.12.5", {\ - "packageLocation": "./.yarn/cache/util-npm-0.12.5-3668276f26-61a10de775.zip/node_modules/util/",\ + "packageLocation": "./.yarn/cache/util-npm-0.12.5-3668276f26-b64a6d3e8a.zip/node_modules/util/",\ "packageDependencies": [\ ["util", "npm:0.12.5"],\ ["inherits", "npm:2.0.4"],\ @@ -26080,7 +26091,7 @@ const RAW_RUNTIME_STATE = ["webpack", "virtual:f1ed609ca21ae2f2bda9d96bcd93b7be4ca68ee222eb0657a1aabcd7a4b8874d2284ee552d265ab7ceb1b5cde37ad4273d3ac4f6933ff3477d1624cb2f5760b4#npm:5.87.0"],\ ["webpack-cli", null],\ ["webpack-dev-middleware", "virtual:3cee627136e3222935f2f0574998a299414f2997be4d2273e90c3717e54c7ad49885ef603e817dc15b21193b05a7719a630fbd40250061090ae31e6a388b57d3#npm:5.3.3"],\ - ["ws", "virtual:3cee627136e3222935f2f0574998a299414f2997be4d2273e90c3717e54c7ad49885ef603e817dc15b21193b05a7719a630fbd40250061090ae31e6a388b57d3#npm:8.13.0"]\ + ["ws", "virtual:41a2932ec57dd2cd1a341c0608ef13d6640c3fd069a4ff63bcb6df738241512b3dcf072b1883b6b5389ebd428878606e1146ebd4ea8b50438ca40a7d86e23323#npm:8.13.0"]\ ],\ "packagePeers": [\ "@types/webpack-cli",\ @@ -26245,7 +26256,7 @@ const RAW_RUNTIME_STATE = "linkType": "HARD"\ }],\ ["npm:1.1.13", {\ - "packageLocation": "./.yarn/cache/which-typed-array-npm-1.1.13-92c18b4878-605e3e10b7.zip/node_modules/which-typed-array/",\ + "packageLocation": "./.yarn/cache/which-typed-array-npm-1.1.13-92c18b4878-8abaaf5f70.zip/node_modules/which-typed-array/",\ "packageDependencies": [\ ["which-typed-array", "npm:1.1.13"],\ ["available-typed-arrays", "npm:1.0.5"],\ @@ -26392,10 +26403,10 @@ const RAW_RUNTIME_STATE = ],\ "linkType": "SOFT"\ }],\ - ["virtual:3cee627136e3222935f2f0574998a299414f2997be4d2273e90c3717e54c7ad49885ef603e817dc15b21193b05a7719a630fbd40250061090ae31e6a388b57d3#npm:8.13.0", {\ - "packageLocation": "./.yarn/__virtual__/ws-virtual-893882e133/0/cache/ws-npm-8.13.0-26ffa3016a-1769532b6f.zip/node_modules/ws/",\ + ["virtual:41a2932ec57dd2cd1a341c0608ef13d6640c3fd069a4ff63bcb6df738241512b3dcf072b1883b6b5389ebd428878606e1146ebd4ea8b50438ca40a7d86e23323#npm:8.13.0", {\ + "packageLocation": "./.yarn/__virtual__/ws-virtual-a67b218817/0/cache/ws-npm-8.13.0-26ffa3016a-1769532b6f.zip/node_modules/ws/",\ "packageDependencies": [\ - ["ws", "virtual:3cee627136e3222935f2f0574998a299414f2997be4d2273e90c3717e54c7ad49885ef603e817dc15b21193b05a7719a630fbd40250061090ae31e6a388b57d3#npm:8.13.0"],\ + ["ws", "virtual:41a2932ec57dd2cd1a341c0608ef13d6640c3fd069a4ff63bcb6df738241512b3dcf072b1883b6b5389ebd428878606e1146ebd4ea8b50438ca40a7d86e23323#npm:8.13.0"],\ ["@types/bufferutil", null],\ ["@types/utf-8-validate", null],\ ["bufferutil", null],\ diff --git a/.yarn/cache/assemblyai-npm-3.0.1-41a2932ec5-bfa7c25c89.zip b/.yarn/cache/assemblyai-npm-3.0.1-41a2932ec5-bfa7c25c89.zip new file mode 100644 index 000000000..5541140f8 Binary files /dev/null and b/.yarn/cache/assemblyai-npm-3.0.1-41a2932ec5-bfa7c25c89.zip differ diff --git a/.yarn/cache/call-bind-npm-1.0.5-65600fae47-246d44db6e.zip b/.yarn/cache/call-bind-npm-1.0.5-65600fae47-246d44db6e.zip deleted file mode 100644 index fe8a1c1b8..000000000 Binary files a/.yarn/cache/call-bind-npm-1.0.5-65600fae47-246d44db6e.zip and /dev/null differ diff --git a/.yarn/cache/call-bind-npm-1.0.5-65600fae47-878d30c1f2.zip b/.yarn/cache/call-bind-npm-1.0.5-65600fae47-878d30c1f2.zip new file mode 100644 index 000000000..55c8822cc Binary files /dev/null and b/.yarn/cache/call-bind-npm-1.0.5-65600fae47-878d30c1f2.zip differ diff --git a/.yarn/cache/define-data-property-npm-1.1.1-2b5156d112-5573c8df96.zip b/.yarn/cache/define-data-property-npm-1.1.1-2b5156d112-5573c8df96.zip deleted file mode 100644 index fefce510b..000000000 Binary files a/.yarn/cache/define-data-property-npm-1.1.1-2b5156d112-5573c8df96.zip and /dev/null differ diff --git a/.yarn/cache/define-data-property-npm-1.1.1-2b5156d112-ba1eff4710.zip b/.yarn/cache/define-data-property-npm-1.1.1-2b5156d112-ba1eff4710.zip new file mode 100644 index 000000000..67cb32d5b Binary files /dev/null and b/.yarn/cache/define-data-property-npm-1.1.1-2b5156d112-ba1eff4710.zip differ diff --git a/.yarn/cache/function-bind-npm-1.1.2-7a55be9b03-0b7e4d0c3f.zip b/.yarn/cache/function-bind-npm-1.1.2-7a55be9b03-0b7e4d0c3f.zip new file mode 100644 index 000000000..6cd6b4783 Binary files /dev/null and b/.yarn/cache/function-bind-npm-1.1.2-7a55be9b03-0b7e4d0c3f.zip differ diff --git a/.yarn/cache/function-bind-npm-1.1.2-7a55be9b03-185e20d20f.zip b/.yarn/cache/function-bind-npm-1.1.2-7a55be9b03-185e20d20f.zip deleted file mode 100644 index 216a4c3c4..000000000 Binary files a/.yarn/cache/function-bind-npm-1.1.2-7a55be9b03-185e20d20f.zip and /dev/null differ diff --git a/.yarn/cache/hasown-npm-2.0.0-78b794ceef-99a39452e2.zip b/.yarn/cache/hasown-npm-2.0.0-78b794ceef-99a39452e2.zip new file mode 100644 index 000000000..0d274c0cb Binary files /dev/null and b/.yarn/cache/hasown-npm-2.0.0-78b794ceef-99a39452e2.zip differ diff --git a/.yarn/cache/hasown-npm-2.0.0-78b794ceef-c330f8d93f.zip b/.yarn/cache/hasown-npm-2.0.0-78b794ceef-c330f8d93f.zip deleted file mode 100644 index 0fe02c086..000000000 Binary files a/.yarn/cache/hasown-npm-2.0.0-78b794ceef-c330f8d93f.zip and /dev/null differ diff --git a/.yarn/cache/is-core-module-npm-2.13.1-36e17434f9-3e562fc6da.zip b/.yarn/cache/is-core-module-npm-2.13.1-36e17434f9-3e562fc6da.zip new file mode 100644 index 000000000..83c85c6a5 Binary files /dev/null and b/.yarn/cache/is-core-module-npm-2.13.1-36e17434f9-3e562fc6da.zip differ diff --git a/.yarn/cache/is-core-module-npm-2.13.1-36e17434f9-d53bd0cc24.zip b/.yarn/cache/is-core-module-npm-2.13.1-36e17434f9-d53bd0cc24.zip deleted file mode 100644 index 028f4dd8c..000000000 Binary files a/.yarn/cache/is-core-module-npm-2.13.1-36e17434f9-d53bd0cc24.zip and /dev/null differ diff --git a/.yarn/cache/is-generator-function-npm-1.0.10-1d0f3809ef-499a3ce636.zip b/.yarn/cache/is-generator-function-npm-1.0.10-1d0f3809ef-499a3ce636.zip deleted file mode 100644 index c6c479b82..000000000 Binary files a/.yarn/cache/is-generator-function-npm-1.0.10-1d0f3809ef-499a3ce636.zip and /dev/null differ diff --git a/.yarn/cache/is-generator-function-npm-1.0.10-1d0f3809ef-5ddb05cd61.zip b/.yarn/cache/is-generator-function-npm-1.0.10-1d0f3809ef-5ddb05cd61.zip new file mode 100644 index 000000000..19cf41e10 Binary files /dev/null and b/.yarn/cache/is-generator-function-npm-1.0.10-1d0f3809ef-5ddb05cd61.zip differ diff --git a/.yarn/cache/is-typed-array-npm-1.1.12-6135c91b1a-bbc1e04914.zip b/.yarn/cache/is-typed-array-npm-1.1.12-6135c91b1a-bbc1e04914.zip new file mode 100644 index 000000000..ea2ea9841 Binary files /dev/null and b/.yarn/cache/is-typed-array-npm-1.1.12-6135c91b1a-bbc1e04914.zip differ diff --git a/.yarn/cache/is-typed-array-npm-1.1.12-6135c91b1a-d953adfd3c.zip b/.yarn/cache/is-typed-array-npm-1.1.12-6135c91b1a-d953adfd3c.zip deleted file mode 100644 index 33e41b97f..000000000 Binary files a/.yarn/cache/is-typed-array-npm-1.1.12-6135c91b1a-d953adfd3c.zip and /dev/null differ diff --git a/.yarn/cache/resolve-npm-1.22.8-098f379dfe-38d9faa138.zip b/.yarn/cache/resolve-npm-1.22.8-098f379dfe-38d9faa138.zip new file mode 100644 index 000000000..6072a8967 Binary files /dev/null and b/.yarn/cache/resolve-npm-1.22.8-098f379dfe-38d9faa138.zip differ diff --git a/.yarn/cache/resolve-npm-1.22.8-098f379dfe-c473506ee0.zip b/.yarn/cache/resolve-npm-1.22.8-098f379dfe-c473506ee0.zip deleted file mode 100644 index 7de6b6a00..000000000 Binary files a/.yarn/cache/resolve-npm-1.22.8-098f379dfe-c473506ee0.zip and /dev/null differ diff --git a/.yarn/cache/resolve-patch-4254c24959-cee9035c50.zip b/.yarn/cache/resolve-patch-4254c24959-cee9035c50.zip new file mode 100644 index 000000000..e5dcc8029 Binary files /dev/null and b/.yarn/cache/resolve-patch-4254c24959-cee9035c50.zip differ diff --git a/.yarn/cache/resolve-patch-4254c24959-f345cd37f5.zip b/.yarn/cache/resolve-patch-4254c24959-f345cd37f5.zip deleted file mode 100644 index dd75c4f66..000000000 Binary files a/.yarn/cache/resolve-patch-4254c24959-f345cd37f5.zip and /dev/null differ diff --git a/.yarn/cache/set-function-length-npm-1.1.1-d362bf8221-745ed1d7dc.zip b/.yarn/cache/set-function-length-npm-1.1.1-d362bf8221-745ed1d7dc.zip deleted file mode 100644 index bac49ab8b..000000000 Binary files a/.yarn/cache/set-function-length-npm-1.1.1-d362bf8221-745ed1d7dc.zip and /dev/null differ diff --git a/.yarn/cache/set-function-length-npm-1.1.1-d362bf8221-7e1b509986.zip b/.yarn/cache/set-function-length-npm-1.1.1-d362bf8221-7e1b509986.zip new file mode 100644 index 000000000..418c58d4f Binary files /dev/null and b/.yarn/cache/set-function-length-npm-1.1.1-d362bf8221-7e1b509986.zip differ diff --git a/.yarn/cache/util-npm-0.12.5-3668276f26-61a10de775.zip b/.yarn/cache/util-npm-0.12.5-3668276f26-61a10de775.zip deleted file mode 100644 index cc910d402..000000000 Binary files a/.yarn/cache/util-npm-0.12.5-3668276f26-61a10de775.zip and /dev/null differ diff --git a/.yarn/cache/util-npm-0.12.5-3668276f26-b64a6d3e8a.zip b/.yarn/cache/util-npm-0.12.5-3668276f26-b64a6d3e8a.zip new file mode 100644 index 000000000..7bfe0257f Binary files /dev/null and b/.yarn/cache/util-npm-0.12.5-3668276f26-b64a6d3e8a.zip differ diff --git a/.yarn/cache/which-typed-array-npm-1.1.13-92c18b4878-605e3e10b7.zip b/.yarn/cache/which-typed-array-npm-1.1.13-92c18b4878-605e3e10b7.zip deleted file mode 100644 index d186ff72f..000000000 Binary files a/.yarn/cache/which-typed-array-npm-1.1.13-92c18b4878-605e3e10b7.zip and /dev/null differ diff --git a/.yarn/cache/which-typed-array-npm-1.1.13-92c18b4878-8abaaf5f70.zip b/.yarn/cache/which-typed-array-npm-1.1.13-92c18b4878-8abaaf5f70.zip new file mode 100644 index 000000000..96f9c8c68 Binary files /dev/null and b/.yarn/cache/which-typed-array-npm-1.1.13-92c18b4878-8abaaf5f70.zip differ diff --git a/packages/core/package.json b/packages/core/package.json index 8acc62394..ee9349e8f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -45,6 +45,7 @@ "dependencies": { "@gentrace/core": "^2.2.5", "@huggingface/inference": "^2.6.4", + "assemblyai": "^3.0.1", "autoevals": "^0.0.26", "crypto-js": "^4.1.1", "emittery": "^1.0.1", diff --git a/packages/core/src/plugins/assemblyAi/LemurActionItemsNode.ts b/packages/core/src/plugins/assemblyAi/LemurActionItemsNode.ts index e5e02aca2..738ffa406 100644 --- a/packages/core/src/plugins/assemblyAi/LemurActionItemsNode.ts +++ b/packages/core/src/plugins/assemblyAi/LemurActionItemsNode.ts @@ -1,5 +1,6 @@ import { nanoid } from 'nanoid/non-secure'; import { dedent } from 'ts-dedent'; +import { AssemblyAI, type LemurActionItemsParameters } from 'assemblyai'; import { type ChartNode, type EditorDefinition, @@ -16,7 +17,6 @@ import { import { pluginNodeDefinition } from '../../model/NodeDefinition.js'; import { type LemurNodeData, - type LemurParams, getApiKey, getLemurParams, lemurEditorDefinitions, @@ -25,9 +25,7 @@ import { export type LemurActionItemsNode = ChartNode<'assemblyAiLemurActionItems', LemurActionItemsNodeData>; -export type LemurActionItemsNodeData = LemurNodeData & { - answer_format?: string; -}; +export type LemurActionItemsNodeData = LemurNodeData; export const LemurActionItemsNodeImpl: PluginNodeImpl = { create(): LemurActionItemsNode { @@ -95,15 +93,11 @@ export const LemurActionItemsNodeImpl: PluginNodeImpl = { async process(data, inputs: Inputs, context: InternalProcessContext): Promise { const apiKey = getApiKey(context); - const params: LemurParams & { - answer_format?: string; - } = getLemurParams(inputs, data); + const client = new AssemblyAI({ apiKey }); - if (data.answer_format) { - params.answer_format = data.answer_format; - } + const params: LemurActionItemsParameters = getLemurParams(inputs, data); - const { response } = await runLemurActionItems(apiKey, params); + const { response } = await client.lemur.actionItems(params); return { ['response' as PortId]: { @@ -114,21 +108,4 @@ export const LemurActionItemsNodeImpl: PluginNodeImpl = { }, }; -async function runLemurActionItems(apiToken: string, params: object) { - const response = await fetch('https://api.assemblyai.com/lemur/v3/generate/action-items', { - method: 'POST', - body: JSON.stringify(params), - headers: { - authorization: apiToken, - }, - }); - const body = await response.json(); - if (response.status !== 200) { - if ('error' in body) throw new Error(body.error); - throw new Error(`LeMUR Action Items failed with status ${response.status}`); - } - - return body as { response: string }; -} - export const lemurActionItemsNode = pluginNodeDefinition(LemurActionItemsNodeImpl, 'LeMUR Action Items'); diff --git a/packages/core/src/plugins/assemblyAi/LemurQaNode.ts b/packages/core/src/plugins/assemblyAi/LemurQaNode.ts index e28ac089c..f6a80a165 100644 --- a/packages/core/src/plugins/assemblyAi/LemurQaNode.ts +++ b/packages/core/src/plugins/assemblyAi/LemurQaNode.ts @@ -20,7 +20,6 @@ import { } from '../../index.js'; import { type LemurNodeData, - type LemurParams, getApiKey, getLemurParams, lemurEditorDefinitions, @@ -28,6 +27,7 @@ import { } from './lemurHelpers.js'; import { coerceType } from '../../utils/coerceType.js'; import { pluginNodeDefinition } from '../../model/NodeDefinition.js'; +import { AssemblyAI, type LemurQuestion, type LemurQuestionAnswerParameters } from 'assemblyai'; export type LemurQaNode = ChartNode<'assemblyAiLemurQa', LemurQaNodeData>; @@ -123,17 +123,16 @@ export const LemurQaNodeImpl = { async process(data, inputs: Inputs, context: InternalProcessContext): Promise { const apiKey = getApiKey(context); + const client = new AssemblyAI({ apiKey }); const questions = getQuestions(inputs).map((question) => applyQuestionEditors(data, question)); - const params: LemurParams & { - questions: Question[]; - } = { + const params: LemurQuestionAnswerParameters = { questions, ...getLemurParams(inputs, data), }; - const { response } = await runLemurQa(apiKey, params); + const { response } = await client.lemur.questionAnswer(params); return { ['response' as PortId]: { type: 'object[]', @@ -143,7 +142,7 @@ export const LemurQaNodeImpl = { }, } satisfies PluginNodeImpl; -function getQuestions(inputs: Inputs): Question[] { +function getQuestions(inputs: Inputs): LemurQuestion[] { const input = inputs['questions' as PortId] as | StringDataValue | StringArrayDataValue @@ -163,9 +162,9 @@ function getQuestions(inputs: Inputs): Question[] { } else if (input.type === 'string[]') { return coerceType(input, 'string[]').map((question) => ({ question })); } else if (input.type === 'object') { - return [coerceType(input, 'object')] as Question[]; + return [coerceType(input, 'object')] as LemurQuestion[]; } else if (input.type === 'object[]') { - return coerceType(input, 'object[]') as unknown as Question[]; + return coerceType(input, 'object[]') as unknown as LemurQuestion[]; } else if (input.type === 'any' && typeof input.value === 'string') { return [ { @@ -173,11 +172,11 @@ function getQuestions(inputs: Inputs): Question[] { }, ]; } else if ((input.type === 'any' && Array.isArray(input.value)) || input.type === 'any[]') { - return (input.value as any[]).map((question: any) => { + return (input.value as any[]).map((question: any) => { if (typeof question === 'string') { return { question }; } else if (typeof question === 'object') { - return question as Question; + return question as LemurQuestion; } else { throw new Error('Question must be a string or object.'); } @@ -186,7 +185,7 @@ function getQuestions(inputs: Inputs): Question[] { throw new Error('Questions must be a string, string[], a question object, or an array of question objects.'); } -function applyQuestionEditors(data: LemurQaNodeData, question: Question): Question { +function applyQuestionEditors(data: LemurQaNodeData, question: LemurQuestion): LemurQuestion { if (!('answer_format' in question) && data.questions_answer_format) { question.answer_format = data.questions_answer_format; } @@ -200,32 +199,4 @@ function applyQuestionEditors(data: LemurQaNodeData, question: Question): Questi return question; } -async function runLemurQa(apiToken: string, params: object) { - const response = await fetch('https://api.assemblyai.com/lemur/v3/generate/question-answer', { - method: 'POST', - body: JSON.stringify(params), - headers: { - authorization: apiToken, - }, - }); - const body = await response.json(); - if (response.status !== 200) { - if ('error' in body) throw new Error(body.error); - throw new Error(`LeMUR QA failed with status ${response.status}`); - } - - return body as { response: QuestionAnswer[] }; -} - -type Question = { - question: string; - context?: string; - answer_format?: string; - answer_options?: string[]; -}; -type QuestionAnswer = { - question: string; - answer: string; -}; - export const lemurQaNode = pluginNodeDefinition(LemurQaNodeImpl, 'LeMUR Q&A'); diff --git a/packages/core/src/plugins/assemblyAi/LemurSummaryNode.ts b/packages/core/src/plugins/assemblyAi/LemurSummaryNode.ts index f833f4a00..47f6880bd 100644 --- a/packages/core/src/plugins/assemblyAi/LemurSummaryNode.ts +++ b/packages/core/src/plugins/assemblyAi/LemurSummaryNode.ts @@ -1,5 +1,6 @@ import { nanoid } from 'nanoid/non-secure'; import { dedent } from 'ts-dedent'; +import { AssemblyAI, type LemurSummaryParameters } from 'assemblyai'; import { type ChartNode, type EditorDefinition, @@ -15,7 +16,6 @@ import { } from '../../index.js'; import { type LemurNodeData, - type LemurParams, getApiKey, getLemurParams, lemurEditorDefinitions, @@ -95,15 +95,14 @@ export const LemurSummaryNodeImpl: PluginNodeImpl = { async process(data, inputs: Inputs, context: InternalProcessContext): Promise { const apiKey = getApiKey(context); - const params: LemurParams & { - answer_format?: string; - } = getLemurParams(inputs, data); + const client = new AssemblyAI({ apiKey }); + const params: LemurSummaryParameters = getLemurParams(inputs, data); if (data.answer_format) { params.answer_format = data.answer_format; } - const { response } = await runLemurSummary(apiKey, params); + const { response } = await client.lemur.summary(params); return { ['response' as PortId]: { @@ -114,21 +113,4 @@ export const LemurSummaryNodeImpl: PluginNodeImpl = { }, }; -async function runLemurSummary(apiToken: string, params: object) { - const response = await fetch('https://api.assemblyai.com/lemur/v3/generate/summary', { - method: 'POST', - body: JSON.stringify(params), - headers: { - authorization: apiToken, - }, - }); - const body = await response.json(); - if (response.status !== 200) { - if ('error' in body) throw new Error(body.error); - throw new Error(`LeMUR Summary failed with status ${response.status}`); - } - - return body as { response: string }; -} - export const lemurSummaryNode = pluginNodeDefinition(LemurSummaryNodeImpl, 'LeMUR Summary'); diff --git a/packages/core/src/plugins/assemblyAi/LemurTaskNode.ts b/packages/core/src/plugins/assemblyAi/LemurTaskNode.ts index 35284a391..e68e58c3c 100644 --- a/packages/core/src/plugins/assemblyAi/LemurTaskNode.ts +++ b/packages/core/src/plugins/assemblyAi/LemurTaskNode.ts @@ -1,5 +1,6 @@ import { nanoid } from 'nanoid/non-secure'; import { dedent } from 'ts-dedent'; +import { AssemblyAI, type LemurTaskParameters } from 'assemblyai'; import { type ChartNode, type EditorDefinition, @@ -15,7 +16,6 @@ import { } from '../../index.js'; import { type LemurNodeData, - type LemurParams, getApiKey, getLemurParams, lemurEditorDefinitions, @@ -96,15 +96,14 @@ export const LemurTaskNodeImpl: PluginNodeImpl = { async process(data, inputs: Inputs, context: InternalProcessContext): Promise { const apiKey = getApiKey(context); - const params: Omit & { - prompt: string; - } = { + const client = new AssemblyAI({ apiKey }); + const params: LemurTaskParameters = { prompt: coerceTypeOptional(inputs['prompt' as PortId], 'string') || data.prompt || '', ...getLemurParams(inputs, data), }; if (!params.prompt) throw new Error('Prompt must be provided.'); - const { response } = await runLemurTask(apiKey, params); + const { response } = await client.lemur.task(params); return { ['response' as PortId]: { @@ -115,21 +114,4 @@ export const LemurTaskNodeImpl: PluginNodeImpl = { }, }; -async function runLemurTask(apiToken: string, params: object) { - const response = await fetch('https://api.assemblyai.com/lemur/v3/generate/task', { - method: 'POST', - body: JSON.stringify(params), - headers: { - authorization: apiToken, - }, - }); - const body = await response.json(); - if (response.status !== 200) { - if ('error' in body) throw new Error(body.error); - throw new Error(`LeMUR Task failed with status ${response.status}`); - } - - return body as { response: string }; -} - export const lemurTaskNode = pluginNodeDefinition(LemurTaskNodeImpl, 'LeMUR Task'); diff --git a/packages/core/src/plugins/assemblyAi/TranscribeAudioNode.ts b/packages/core/src/plugins/assemblyAi/TranscribeAudioNode.ts index 98553aeef..bfe69fa28 100644 --- a/packages/core/src/plugins/assemblyAi/TranscribeAudioNode.ts +++ b/packages/core/src/plugins/assemblyAi/TranscribeAudioNode.ts @@ -1,5 +1,6 @@ import { nanoid } from 'nanoid/non-secure'; import { dedent } from 'ts-dedent'; +import { AssemblyAI } from 'assemblyai'; import { type AnyDataValue, type AudioDataValue, @@ -93,11 +94,12 @@ export const TranscribeAudioNodeImpl: PluginNodeImpl = { if (!input) throw new Error('Audio input is required.'); const apiKey = getApiKey(context); + const client = new AssemblyAI({ apiKey }); let audioUrl: string; if (input.type === 'audio') { const audio = coerceType(inputs['audio' as PortId], 'audio'); - audioUrl = await uploadData(apiKey, audio as { data: Uint8Array }); + audioUrl = await client.files.upload(audio.data); } else if (input.type === 'string' || input.type === 'any') { audioUrl = coerceType(inputs['audio' as PortId], 'string'); } else { @@ -106,12 +108,12 @@ export const TranscribeAudioNodeImpl: PluginNodeImpl = { validateUrl(audioUrl); - const transcript = await transcribeAudio(apiKey, audioUrl); + const transcript = await client.transcripts.create({ audio_url: audioUrl }); return { ['text' as PortId]: { type: 'string', - value: transcript.text, + value: transcript.text as string, }, ['id' as PortId]: { type: 'string', @@ -125,79 +127,6 @@ export const TranscribeAudioNodeImpl: PluginNodeImpl = { }, }; -// Function to upload a local file to the AssemblyAI API -async function uploadData(apiToken: string, data: { data: Uint8Array }) { - const url = 'https://api.assemblyai.com/v2/upload'; - - // Send a POST request to the API to upload the file, passing in the headers and the file data - const response = await fetch(url, { - method: 'POST', - body: new Blob([data.data]), - headers: { - 'Content-Type': 'application/octet-stream', - Authorization: apiToken, - }, - }); - const body = await response.json(); - - if (response.status !== 200) { - if ('error' in body) throw new Error(body.error); - throw new Error(`Upload failed with status ${response.status} - ${response.statusText}`); - } - - return body.upload_url; -} - -// Async function that sends a request to the AssemblyAI transcription API and retrieves the transcript -async function transcribeAudio(apiToken: string, audioUrl: string) { - // Set the headers for the request, including the API token and content type - const headers = { - authorization: apiToken, - 'content-type': 'application/json', - }; - - // Send a POST request to the transcription API with the audio URL in the request body - const response = await fetch('https://api.assemblyai.com/v2/transcript', { - method: 'POST', - body: JSON.stringify({ audio_url: audioUrl }), - headers, - }); - const body = await response.json(); - - if (response.status !== 200) { - if ('error' in body) throw new Error(body.error); - throw new Error(`Create transcript failed with status ${response.status} - ${response.statusText}}`); - } - - const transcriptId = body.id; - - // Construct the polling endpoint URL using the transcript ID - const pollingEndpoint = `https://api.assemblyai.com/v2/transcript/${transcriptId}`; - - // Poll the transcription API until the transcript is ready - while (true) { - // Send a GET request to the polling endpoint to retrieve the status of the transcript - const pollingResponse = await fetch(pollingEndpoint, { method: 'GET', headers }); - const pollingBody = await pollingResponse.json(); - - if (pollingResponse.status !== 200) { - if ('error' in pollingBody) throw new Error(pollingBody.error); - throw new Error(`Get transcript failed with status ${pollingResponse.status}`); - } - - // If the transcription is complete, return the transcript object - if (pollingBody.status === 'completed') { - return pollingBody; - } else if (pollingBody.status === 'error') { - // If the transcription has failed, throw an error with the error message - throw new Error(`Transcription failed: ${pollingBody.error}`); - } else { - // If the transcription is still in progress, wait for a few seconds before polling again - await new Promise((resolve) => setTimeout(resolve, 1000)); - } - } -} - function validateUrl(audioUrl: string) { if (audioUrl === null) throw new Error('Audio URL cannot be null.'); if (audioUrl === undefined) throw new Error('Audio URL cannot be undefined.'); diff --git a/packages/core/src/plugins/assemblyAi/lemurHelpers.ts b/packages/core/src/plugins/assemblyAi/lemurHelpers.ts index c081ac5dc..05edf000b 100644 --- a/packages/core/src/plugins/assemblyAi/lemurHelpers.ts +++ b/packages/core/src/plugins/assemblyAi/lemurHelpers.ts @@ -1,3 +1,4 @@ +import type { LemurBaseParameters } from 'assemblyai'; import { type AnyDataValue, type ArrayDataValue, @@ -37,8 +38,8 @@ export function getApiKey(context: InternalProcessContext) { return apiKey; } -export function getLemurParams(inputs: Inputs, editorData: LemurNodeData): LemurParams { - const params: LemurParams = { +export function getLemurParams(inputs: Inputs, editorData: LemurNodeData): LemurBaseParameters { + const params: LemurBaseParameters = { transcript_ids: getTranscriptIds(inputs), context: coerceTypeOptional(inputs['context' as PortId], 'string') || editorData.context || undefined, final_model: editorData.final_model && editorData.final_model !== 'default' ? editorData.final_model : undefined, @@ -79,13 +80,6 @@ export const lemurEditorDefinitions = [ export type FinalModel = 'default' | 'basic'; -export type LemurParams = { - transcript_ids: string[]; - context?: string; - final_model?: FinalModel; - max_output_size?: number; -}; - export type LemurNodeData = { context?: string; final_model?: FinalModel; diff --git a/yarn.lock b/yarn.lock index 7b12831b6..751534911 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4174,6 +4174,7 @@ __metadata: "@types/yaml": "npm:^1.9.7" "@typescript-eslint/eslint-plugin": "npm:^6.9.0" "@typescript-eslint/parser": "npm:^6.9.0" + assemblyai: "npm:^3.0.1" autoevals: "npm:^0.0.26" crypto-js: "npm:^4.1.1" emittery: "npm:^1.0.1" @@ -7488,6 +7489,15 @@ __metadata: languageName: node linkType: hard +"assemblyai@npm:^3.0.1": + version: 3.0.1 + resolution: "assemblyai@npm:3.0.1" + dependencies: + ws: "npm:^8.13.0" + checksum: bfa7c25c89f8b6d05e59f9e8aa8f47fdb9f5a33d09e54ecef7f515e698e250fee9b71939be6b325f2aa2bb01855ae91cfd13ea1bbc66af00f9c39c5e353420ab + languageName: node + linkType: hard + "ast-types-flow@npm:^0.0.7": version: 0.0.7 resolution: "ast-types-flow@npm:0.0.7" @@ -8007,7 +8017,7 @@ __metadata: function-bind: "npm:^1.1.2" get-intrinsic: "npm:^1.2.1" set-function-length: "npm:^1.1.1" - checksum: 246d44db6ef9bbd418828dbd5337f80b46be4398d522eded015f31554cbb2ea33025b0203b75c7ab05a1a255b56ef218880cca1743e4121e306729f9e414da39 + checksum: 878d30c1f2b67a45f65dc75128fb3db9122ae125da8d44c6488d715df992621d9c3c53a212e4b21aedf03e6b9b06c8f3c1ca5f192597931f4683bfb372e06b5b languageName: node linkType: hard @@ -9079,7 +9089,7 @@ __metadata: get-intrinsic: "npm:^1.2.1" gopd: "npm:^1.0.1" has-property-descriptors: "npm:^1.0.0" - checksum: 5573c8df96b5857408cad64d9b91b69152e305ce4b06218e5f49b59c6cafdbb90a8bd8a0bb83c7bc67a8d479c04aa697063c9bc28d849b7282f9327586d6bc7b + checksum: ba1eff4710cc7e184aa0353877a746e1c16d119c81a7cb891c9dcdf706627106efb16c922d2919079616971368ee1c68aba483f369168598d2e84723fd157fac languageName: node linkType: hard @@ -11052,7 +11062,7 @@ __metadata: "function-bind@npm:^1.1.2": version: 1.1.2 resolution: "function-bind@npm:1.1.2" - checksum: 185e20d20f10c8d661d59aac0f3b63b31132d492e1b11fcc2a93cb2c47257ebaee7407c38513efd2b35cafdf972d9beb2ea4593c1e0f3bf8f2744836928d7454 + checksum: 0b7e4d0c3fcfa16999aceaadd1ae760404ef10b98f88d992971de3e4f4d79079651eeec472971ea02a300ffcddd44adcd33d3c39c735d2784d6ad3e711e4ddd0 languageName: node linkType: hard @@ -11545,7 +11555,7 @@ __metadata: resolution: "hasown@npm:2.0.0" dependencies: function-bind: "npm:^1.1.2" - checksum: c330f8d93f9d23fe632c719d4db3d698ef7d7c367d51548b836069e06a90fa9151e868c8e67353cfe98d67865bf7354855db28fa36eb1b18fa5d4a3f4e7f1c90 + checksum: 99a39452e239bd0400822554cd6a745c696820b5d5b2d0fa6f6feefa8d4ff712378a5e70f8d022817b17e5a07213d6e2a287fcbec09f298717ca42dcade0d563 languageName: node linkType: hard @@ -12225,7 +12235,7 @@ __metadata: resolution: "is-core-module@npm:2.13.1" dependencies: hasown: "npm:^2.0.0" - checksum: d53bd0cc24b0a0351fb4b206ee3908f71b9bbf1c47e9c9e14e5f06d292af1663704d2abd7e67700d6487b2b7864e0d0f6f10a1edf1892864bdffcb197d1845a2 + checksum: 3e562fc6da2b0c3fc3726539096903b8e8ccadabe6cd6e2dc6dedb86e88ff930dca5c12a08f400d32fb8d3b6973c45f82420251a6662bdf7771bdababb906cc4 languageName: node linkType: hard @@ -12280,7 +12290,7 @@ __metadata: resolution: "is-generator-function@npm:1.0.10" dependencies: has-tostringtag: "npm:^1.0.0" - checksum: 499a3ce6361064c3bd27fbff5c8000212d48506ebe1977842bbd7b3e708832d0deb1f4cc69186ece3640770e8c4f1287b24d99588a0b8058b2dbdd344bc1f47f + checksum: 5ddb05cd61c043348eaee42bd003d52fa2307827dd1690e6cdb6b205a6b62750f4e41d34d0a6a84793dda6dc6b147405e0ba349e631996beea00631302e36294 languageName: node linkType: hard @@ -12509,7 +12519,7 @@ __metadata: resolution: "is-typed-array@npm:1.1.12" dependencies: which-typed-array: "npm:^1.1.11" - checksum: d953adfd3c41618d5e01b2a10f21817e4cdc9572772fa17211100aebb3811b6e3c2e308a0558cc87d218a30504cb90154b833013437776551bfb70606fb088ca + checksum: bbc1e04914affd083808bb10a49b30e59106367560b5a20a696f277f47cd1a96263eda2bc5193811f8cb5677e247865bd8f77863864b2db687d956f059509e5d languageName: node linkType: hard @@ -16177,7 +16187,7 @@ __metadata: supports-preserve-symlinks-flag: "npm:^1.0.0" bin: resolve: bin/resolve - checksum: c473506ee01eb45cbcfefb68652ae5759e092e6b0fb64547feadf9736a6394f258fbc6f88e00c5ca36d5477fbb65388b272432a3600fa223062e54333c156753 + checksum: 38d9faa1385ac05c7f8bf7316a2af94098925eca981031c9f770a6b335d033b8cbed29cb140b5781ac8b834d39ab1782368468cf75994403f3e71cab38cf9fe7 languageName: node linkType: hard @@ -16216,7 +16226,7 @@ __metadata: supports-preserve-symlinks-flag: "npm:^1.0.0" bin: resolve: bin/resolve - checksum: f345cd37f56a2c0275e3fe062517c650bb673815d885e7507566df589375d165bbbf4bdb6aa95600a9bc55f4744b81f452b5a63f95b9f10a72787dba3c90890a + checksum: cee9035c5088dcd6f631dfbdc45b35f98750658e47e80b94fc89325bf7d288265b9c85cdd8105a313b0b3a3d617c3191f59e522daa031d7a823d338f90366d68 languageName: node linkType: hard @@ -16686,7 +16696,7 @@ __metadata: get-intrinsic: "npm:^1.2.1" gopd: "npm:^1.0.1" has-property-descriptors: "npm:^1.0.0" - checksum: 745ed1d7dc69a6185e0820082fe73838ab3dfd01e75cce83a41e4c1d68bbf34bc5fb38f32ded542ae0b557536b5d2781594499b5dcd19e7db138e06292a76c7b + checksum: 7e1b50998678d1279dfca46588cf68681b0146023fdf609c6b8ab0323108c04ed3ded80c5764286a85913bffc20b33b323c712d7f03e60f44bfa70a948c9c0c4 languageName: node linkType: hard @@ -18288,7 +18298,7 @@ __metadata: is-generator-function: "npm:^1.0.7" is-typed-array: "npm:^1.1.3" which-typed-array: "npm:^1.1.2" - checksum: 61a10de7753353dd4d744c917f74cdd7d21b8b46379c1e48e1c4fd8e83f8190e6bd9978fc4e5102ab6a10ebda6019d1b36572fa4a325e175ec8b789a121f6147 + checksum: b64a6d3e8ab48037b0f3fb38b6df96e180ab8c430d49386be8444fa2402f26450239bc1fd13aa29c02f3165be380f01aaf88eadb284e77f14df63664a5536e92 languageName: node linkType: hard @@ -18800,7 +18810,7 @@ __metadata: for-each: "npm:^0.3.3" gopd: "npm:^1.0.1" has-tostringtag: "npm:^1.0.0" - checksum: 605e3e10b7118af904a0e79d0d50b95275102f06ec902734024989cd71354929f7acee50de43529d3baf5858e2e4eb32c75e6ebd226c888ad976d8140e4a3e71 + checksum: 8abaaf5f706407f4816c1644f6adca955dceb845ca3b72a51fa32aafb621c59d3a20c8012d4d80f8b1a14a73c208fce686ee2c7df63a68e0228e924fb5d53c21 languageName: node linkType: hard