From 421ab237898e0e98ac1feef9622a6965695bae90 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Fri, 4 Oct 2024 19:28:57 -0700 Subject: [PATCH] Add models to Modus AssemblyScript SDK (#428) --- CHANGELOG.md | 1 + cspell.json | 3 + .../testdata/build/testdata.wasm | Bin 115310 -> 115310 bytes .../assemblyscript/testdata/package-lock.json | 5 +- .../anthropic-functions/assembly/index.ts | 2 +- .../anthropic-functions/package-lock.json | 78 +- .../examples/anthropic-functions/package.json | 1 - .../examples/classification/assembly/index.ts | 2 +- .../examples/classification/package-lock.json | 78 +- .../examples/classification/package.json | 1 - .../examples/collection/assembly/index.ts | 2 +- .../examples/collection/package-lock.json | 78 +- .../examples/collection/package.json | 1 - .../examples/dgraph/package-lock.json | 70 +- .../examples/embedding/assembly/index.ts | 4 +- .../examples/embedding/package-lock.json | 78 +- .../examples/embedding/package.json | 1 - .../examples/graphql/package-lock.json | 70 +- .../examples/http/package-lock.json | 70 +- .../examples/postgresql/package-lock.json | 70 +- .../examples/simple/package-lock.json | 70 +- .../examples/textgeneration/assembly/index.ts | 4 +- .../examples/textgeneration/package-lock.json | 78 +- .../examples/textgeneration/package.json | 1 - sdk/assemblyscript/scripts/install-all.sh | 19 + sdk/assemblyscript/src/assembly/models.ts | 50 +- .../src/assembly/models/anthropic/messages.ts | 385 +++++++++ .../src/models/anthropic/messages.ts | 394 +++++++++ .../src/models/experimental/classification.ts | 91 +++ .../src/models/experimental/embeddings.ts | 51 ++ .../src/models/gemini/generate.ts | 571 ++++++++++++++ sdk/assemblyscript/src/models/meta/llama.ts | 97 +++ sdk/assemblyscript/src/models/openai/chat.ts | 746 ++++++++++++++++++ .../src/models/openai/embeddings.ts | 207 +++++ sdk/assemblyscript/src/models/tsconfig.json | 4 + sdk/assemblyscript/src/package-lock.json | 9 - sdk/assemblyscript/src/package.json | 3 +- 37 files changed, 2988 insertions(+), 407 deletions(-) create mode 100755 sdk/assemblyscript/scripts/install-all.sh create mode 100644 sdk/assemblyscript/src/assembly/models/anthropic/messages.ts create mode 100644 sdk/assemblyscript/src/models/anthropic/messages.ts create mode 100644 sdk/assemblyscript/src/models/experimental/classification.ts create mode 100644 sdk/assemblyscript/src/models/experimental/embeddings.ts create mode 100644 sdk/assemblyscript/src/models/gemini/generate.ts create mode 100644 sdk/assemblyscript/src/models/meta/llama.ts create mode 100644 sdk/assemblyscript/src/models/openai/chat.ts create mode 100644 sdk/assemblyscript/src/models/openai/embeddings.ts create mode 100644 sdk/assemblyscript/src/models/tsconfig.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 25fecf6b..2c023464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - Add Local Model Invocation Support [#421](https://github.com/hypermodeinc/modus/pull/421) - Remove HTTP Timeout, Add Context Timeout on Collections [#422](https://github.com/hypermodeinc/modus/pull/422) - Add Modus AssemblyScript SDK [#423](https://github.com/hypermodeinc/modus/pull/423) +- Add models to Modus AssemblyScript SDK [#428](https://github.com/hypermodeinc/modus/pull/428) ## 2024-10-02 - Version 0.12.7 diff --git a/cspell.json b/cspell.json index fa717619..51fcc46f 100644 --- a/cspell.json +++ b/cspell.json @@ -115,6 +115,8 @@ "nquads", "objs", "offsetof", + "omitif", + "omitnull", "openai", "operationreport", "pgconn", @@ -150,6 +152,7 @@ "tsrv", "typedarray", "uids", + "uncategorized", "unmarshalling", "unnest", "upsert", diff --git a/runtime/languages/assemblyscript/testdata/build/testdata.wasm b/runtime/languages/assemblyscript/testdata/build/testdata.wasm index 5c3b857ec48433cfcfc1ce986a06a86f1d1e9273..81f5523829fdc4c11451fcbf1fd0074901cbbd94 100644 GIT binary patch delta 115 zcmaFY!v3y>yHKYsE^5h1KwxTaU|?#NW|C%PVPceOl9ps(Vqj!wZeU_; RX=rY4lw`iWvW@YpH2@NsA)NpK delta 115 zcmaFY!v3y>y=21.1.0" } }, + "../../src/node_modules/@humanfs/core": { + "version": "0.19.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "../../src/node_modules/@humanfs/node": { + "version": "0.16.5", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, "../../src/node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "dev": true, @@ -162,7 +180,7 @@ } }, "../../src/node_modules/@humanwhocodes/retry": { - "version": "0.3.0", + "version": "0.3.1", "dev": true, "license": "Apache-2.0", "engines": { @@ -173,13 +191,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "../../src/node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "../../src/node_modules/@isaacs/cliui": { "version": "8.0.2", "dev": true, @@ -798,7 +809,7 @@ } }, "../../src/node_modules/eslint": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "dependencies": { @@ -807,11 +818,11 @@ "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.1", + "@eslint/js": "9.12.0", "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -819,9 +830,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -831,13 +842,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { @@ -859,7 +868,7 @@ } }, "../../src/node_modules/eslint-scope": { - "version": "8.0.2", + "version": "8.1.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -885,7 +894,7 @@ } }, "../../src/node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -896,13 +905,13 @@ } }, "../../src/node_modules/espree": { - "version": "10.1.0", + "version": "10.2.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -912,7 +921,7 @@ } }, "../../src/node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -1179,14 +1188,6 @@ "node": ">=0.12.0" } }, - "../../src/node_modules/is-path-inside": { - "version": "3.0.3", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "../../src/node_modules/isexe": { "version": "2.0.0", "dev": true, @@ -2090,13 +2091,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "node_modules/@hypermode/modus-sdk-as": { "resolved": "../../src", "link": true diff --git a/sdk/assemblyscript/examples/anthropic-functions/package.json b/sdk/assemblyscript/examples/anthropic-functions/package.json index 2beb837f..0592f76b 100644 --- a/sdk/assemblyscript/examples/anthropic-functions/package.json +++ b/sdk/assemblyscript/examples/anthropic-functions/package.json @@ -13,7 +13,6 @@ }, "dependencies": { "@hypermode/modus-sdk-as": "../../src", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21" }, "devDependencies": { diff --git a/sdk/assemblyscript/examples/classification/assembly/index.ts b/sdk/assemblyscript/examples/classification/assembly/index.ts index 83269fd7..13602df1 100644 --- a/sdk/assemblyscript/examples/classification/assembly/index.ts +++ b/sdk/assemblyscript/examples/classification/assembly/index.ts @@ -8,7 +8,7 @@ import { models } from "@hypermode/modus-sdk-as"; import { ClassificationModel, ClassifierResult, -} from "@hypermode/models-as/models/experimental/classification"; +} from "@hypermode/modus-sdk-as/models/experimental/classification"; // This model name should match one defined in the hypermode.json manifest file. const modelName: string = "my-classifier"; diff --git a/sdk/assemblyscript/examples/classification/package-lock.json b/sdk/assemblyscript/examples/classification/package-lock.json index bdd79744..9e8589ef 100644 --- a/sdk/assemblyscript/examples/classification/package-lock.json +++ b/sdk/assemblyscript/examples/classification/package-lock.json @@ -7,7 +7,6 @@ "name": "classification-example", "license": "Apache-2.0", "dependencies": { - "@hypermode/models-as": "^0.2.4", "@hypermode/modus-sdk-as": "../../src", "json-as": "^0.9.21" }, @@ -30,19 +29,18 @@ "license": "Apache-2.0", "dependencies": { "@assemblyscript/wasi-shim": "^0.1.0", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21", "semver": "^7.6.3", "xid-ts": "^1.1.4" }, "devDependencies": { - "@eslint/js": "^9.11.1", + "@eslint/js": "^9.12.0", "@types/eslint__js": "^8.42.3", "@types/node": "^20.16.10", "as-test": "^0.3.4", "assemblyscript": "^0.27.30", "assemblyscript-prettier": "^3.0.1", - "eslint": "^9.11.1", + "eslint": "^9.12.0", "prettier": "^3.3.3", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0", @@ -123,7 +121,7 @@ } }, "../../src/node_modules/@eslint/js": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "engines": { @@ -149,6 +147,26 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "../../src/node_modules/@humanfs/core": { + "version": "0.19.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "../../src/node_modules/@humanfs/node": { + "version": "0.16.5", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, "../../src/node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "dev": true, @@ -162,7 +180,7 @@ } }, "../../src/node_modules/@humanwhocodes/retry": { - "version": "0.3.0", + "version": "0.3.1", "dev": true, "license": "Apache-2.0", "engines": { @@ -173,13 +191,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "../../src/node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "../../src/node_modules/@isaacs/cliui": { "version": "8.0.2", "dev": true, @@ -798,7 +809,7 @@ } }, "../../src/node_modules/eslint": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "dependencies": { @@ -807,11 +818,11 @@ "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.1", + "@eslint/js": "9.12.0", "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -819,9 +830,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -831,13 +842,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { @@ -859,7 +868,7 @@ } }, "../../src/node_modules/eslint-scope": { - "version": "8.0.2", + "version": "8.1.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -885,7 +894,7 @@ } }, "../../src/node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -896,13 +905,13 @@ } }, "../../src/node_modules/espree": { - "version": "10.1.0", + "version": "10.2.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -912,7 +921,7 @@ } }, "../../src/node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -1179,14 +1188,6 @@ "node": ">=0.12.0" } }, - "../../src/node_modules/is-path-inside": { - "version": "3.0.3", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "../../src/node_modules/isexe": { "version": "2.0.0", "dev": true, @@ -2090,13 +2091,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "node_modules/@hypermode/modus-sdk-as": { "resolved": "../../src", "link": true diff --git a/sdk/assemblyscript/examples/classification/package.json b/sdk/assemblyscript/examples/classification/package.json index e43ad556..4f4e1c24 100644 --- a/sdk/assemblyscript/examples/classification/package.json +++ b/sdk/assemblyscript/examples/classification/package.json @@ -13,7 +13,6 @@ }, "dependencies": { "@hypermode/modus-sdk-as": "../../src", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21" }, "devDependencies": { diff --git a/sdk/assemblyscript/examples/collection/assembly/index.ts b/sdk/assemblyscript/examples/collection/assembly/index.ts index d076064a..12d31560 100644 --- a/sdk/assemblyscript/examples/collection/assembly/index.ts +++ b/sdk/assemblyscript/examples/collection/assembly/index.ts @@ -6,7 +6,7 @@ import { collections } from "@hypermode/modus-sdk-as"; import { models } from "@hypermode/modus-sdk-as"; -import { OpenAIEmbeddingsModel } from "@hypermode/models-as/models/openai/embeddings"; +import { OpenAIEmbeddingsModel } from "@hypermode/modus-sdk-as/models/openai/embeddings"; // These names should match the ones defined in the hypermode.json manifest file. const modelName: string = "embeddings"; diff --git a/sdk/assemblyscript/examples/collection/package-lock.json b/sdk/assemblyscript/examples/collection/package-lock.json index d6ca94ff..20e2c415 100644 --- a/sdk/assemblyscript/examples/collection/package-lock.json +++ b/sdk/assemblyscript/examples/collection/package-lock.json @@ -7,7 +7,6 @@ "name": "collection-example", "license": "Apache-2.0", "dependencies": { - "@hypermode/models-as": "^0.2.4", "@hypermode/modus-sdk-as": "../../src", "json-as": "^0.9.21" }, @@ -30,19 +29,18 @@ "license": "Apache-2.0", "dependencies": { "@assemblyscript/wasi-shim": "^0.1.0", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21", "semver": "^7.6.3", "xid-ts": "^1.1.4" }, "devDependencies": { - "@eslint/js": "^9.11.1", + "@eslint/js": "^9.12.0", "@types/eslint__js": "^8.42.3", "@types/node": "^20.16.10", "as-test": "^0.3.4", "assemblyscript": "^0.27.30", "assemblyscript-prettier": "^3.0.1", - "eslint": "^9.11.1", + "eslint": "^9.12.0", "prettier": "^3.3.3", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0", @@ -123,7 +121,7 @@ } }, "../../src/node_modules/@eslint/js": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "engines": { @@ -149,6 +147,26 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "../../src/node_modules/@humanfs/core": { + "version": "0.19.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "../../src/node_modules/@humanfs/node": { + "version": "0.16.5", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, "../../src/node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "dev": true, @@ -162,7 +180,7 @@ } }, "../../src/node_modules/@humanwhocodes/retry": { - "version": "0.3.0", + "version": "0.3.1", "dev": true, "license": "Apache-2.0", "engines": { @@ -173,13 +191,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "../../src/node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "../../src/node_modules/@isaacs/cliui": { "version": "8.0.2", "dev": true, @@ -798,7 +809,7 @@ } }, "../../src/node_modules/eslint": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "dependencies": { @@ -807,11 +818,11 @@ "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.1", + "@eslint/js": "9.12.0", "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -819,9 +830,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -831,13 +842,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { @@ -859,7 +868,7 @@ } }, "../../src/node_modules/eslint-scope": { - "version": "8.0.2", + "version": "8.1.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -885,7 +894,7 @@ } }, "../../src/node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -896,13 +905,13 @@ } }, "../../src/node_modules/espree": { - "version": "10.1.0", + "version": "10.2.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -912,7 +921,7 @@ } }, "../../src/node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -1179,14 +1188,6 @@ "node": ">=0.12.0" } }, - "../../src/node_modules/is-path-inside": { - "version": "3.0.3", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "../../src/node_modules/isexe": { "version": "2.0.0", "dev": true, @@ -2090,13 +2091,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "node_modules/@hypermode/modus-sdk-as": { "resolved": "../../src", "link": true diff --git a/sdk/assemblyscript/examples/collection/package.json b/sdk/assemblyscript/examples/collection/package.json index 6be42269..92504070 100644 --- a/sdk/assemblyscript/examples/collection/package.json +++ b/sdk/assemblyscript/examples/collection/package.json @@ -13,7 +13,6 @@ }, "dependencies": { "@hypermode/modus-sdk-as": "../../src", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21" }, "devDependencies": { diff --git a/sdk/assemblyscript/examples/dgraph/package-lock.json b/sdk/assemblyscript/examples/dgraph/package-lock.json index 6db7df92..934b7d1b 100644 --- a/sdk/assemblyscript/examples/dgraph/package-lock.json +++ b/sdk/assemblyscript/examples/dgraph/package-lock.json @@ -29,19 +29,18 @@ "license": "Apache-2.0", "dependencies": { "@assemblyscript/wasi-shim": "^0.1.0", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21", "semver": "^7.6.3", "xid-ts": "^1.1.4" }, "devDependencies": { - "@eslint/js": "^9.11.1", + "@eslint/js": "^9.12.0", "@types/eslint__js": "^8.42.3", "@types/node": "^20.16.10", "as-test": "^0.3.4", "assemblyscript": "^0.27.30", "assemblyscript-prettier": "^3.0.1", - "eslint": "^9.11.1", + "eslint": "^9.12.0", "prettier": "^3.3.3", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0", @@ -122,7 +121,7 @@ } }, "../../src/node_modules/@eslint/js": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "engines": { @@ -148,6 +147,26 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "../../src/node_modules/@humanfs/core": { + "version": "0.19.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "../../src/node_modules/@humanfs/node": { + "version": "0.16.5", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, "../../src/node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "dev": true, @@ -161,7 +180,7 @@ } }, "../../src/node_modules/@humanwhocodes/retry": { - "version": "0.3.0", + "version": "0.3.1", "dev": true, "license": "Apache-2.0", "engines": { @@ -172,13 +191,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "../../src/node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "../../src/node_modules/@isaacs/cliui": { "version": "8.0.2", "dev": true, @@ -797,7 +809,7 @@ } }, "../../src/node_modules/eslint": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "dependencies": { @@ -806,11 +818,11 @@ "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.1", + "@eslint/js": "9.12.0", "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -818,9 +830,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -830,13 +842,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { @@ -858,7 +868,7 @@ } }, "../../src/node_modules/eslint-scope": { - "version": "8.0.2", + "version": "8.1.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -884,7 +894,7 @@ } }, "../../src/node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -895,13 +905,13 @@ } }, "../../src/node_modules/espree": { - "version": "10.1.0", + "version": "10.2.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -911,7 +921,7 @@ } }, "../../src/node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -1178,14 +1188,6 @@ "node": ">=0.12.0" } }, - "../../src/node_modules/is-path-inside": { - "version": "3.0.3", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "../../src/node_modules/isexe": { "version": "2.0.0", "dev": true, diff --git a/sdk/assemblyscript/examples/embedding/assembly/index.ts b/sdk/assemblyscript/examples/embedding/assembly/index.ts index 706bb275..d0927f14 100644 --- a/sdk/assemblyscript/examples/embedding/assembly/index.ts +++ b/sdk/assemblyscript/examples/embedding/assembly/index.ts @@ -5,8 +5,8 @@ */ import { models } from "@hypermode/modus-sdk-as"; -import { EmbeddingsModel } from "@hypermode/models-as/models/experimental/embeddings"; -import { OpenAIEmbeddingsModel } from "@hypermode/models-as/models/openai/embeddings"; +import { EmbeddingsModel } from "@hypermode/modus-sdk-as/models/experimental/embeddings"; +import { OpenAIEmbeddingsModel } from "@hypermode/modus-sdk-as/models/openai/embeddings"; // In this example, we will create embedding vectors from input text strings. // For comparison, we'll do this with two different models. diff --git a/sdk/assemblyscript/examples/embedding/package-lock.json b/sdk/assemblyscript/examples/embedding/package-lock.json index 2412e05a..3fc8d3f3 100644 --- a/sdk/assemblyscript/examples/embedding/package-lock.json +++ b/sdk/assemblyscript/examples/embedding/package-lock.json @@ -7,7 +7,6 @@ "name": "embedding-example", "license": "Apache-2.0", "dependencies": { - "@hypermode/models-as": "^0.2.4", "@hypermode/modus-sdk-as": "../../src", "json-as": "^0.9.21" }, @@ -30,19 +29,18 @@ "license": "Apache-2.0", "dependencies": { "@assemblyscript/wasi-shim": "^0.1.0", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21", "semver": "^7.6.3", "xid-ts": "^1.1.4" }, "devDependencies": { - "@eslint/js": "^9.11.1", + "@eslint/js": "^9.12.0", "@types/eslint__js": "^8.42.3", "@types/node": "^20.16.10", "as-test": "^0.3.4", "assemblyscript": "^0.27.30", "assemblyscript-prettier": "^3.0.1", - "eslint": "^9.11.1", + "eslint": "^9.12.0", "prettier": "^3.3.3", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0", @@ -123,7 +121,7 @@ } }, "../../src/node_modules/@eslint/js": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "engines": { @@ -149,6 +147,26 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "../../src/node_modules/@humanfs/core": { + "version": "0.19.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "../../src/node_modules/@humanfs/node": { + "version": "0.16.5", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, "../../src/node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "dev": true, @@ -162,7 +180,7 @@ } }, "../../src/node_modules/@humanwhocodes/retry": { - "version": "0.3.0", + "version": "0.3.1", "dev": true, "license": "Apache-2.0", "engines": { @@ -173,13 +191,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "../../src/node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "../../src/node_modules/@isaacs/cliui": { "version": "8.0.2", "dev": true, @@ -798,7 +809,7 @@ } }, "../../src/node_modules/eslint": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "dependencies": { @@ -807,11 +818,11 @@ "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.1", + "@eslint/js": "9.12.0", "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -819,9 +830,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -831,13 +842,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { @@ -859,7 +868,7 @@ } }, "../../src/node_modules/eslint-scope": { - "version": "8.0.2", + "version": "8.1.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -885,7 +894,7 @@ } }, "../../src/node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -896,13 +905,13 @@ } }, "../../src/node_modules/espree": { - "version": "10.1.0", + "version": "10.2.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -912,7 +921,7 @@ } }, "../../src/node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -1179,14 +1188,6 @@ "node": ">=0.12.0" } }, - "../../src/node_modules/is-path-inside": { - "version": "3.0.3", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "../../src/node_modules/isexe": { "version": "2.0.0", "dev": true, @@ -2090,13 +2091,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "node_modules/@hypermode/modus-sdk-as": { "resolved": "../../src", "link": true diff --git a/sdk/assemblyscript/examples/embedding/package.json b/sdk/assemblyscript/examples/embedding/package.json index 822f1cfe..c0b97556 100644 --- a/sdk/assemblyscript/examples/embedding/package.json +++ b/sdk/assemblyscript/examples/embedding/package.json @@ -13,7 +13,6 @@ }, "dependencies": { "@hypermode/modus-sdk-as": "../../src", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21" }, "devDependencies": { diff --git a/sdk/assemblyscript/examples/graphql/package-lock.json b/sdk/assemblyscript/examples/graphql/package-lock.json index 8ea939ac..ea8bcb14 100644 --- a/sdk/assemblyscript/examples/graphql/package-lock.json +++ b/sdk/assemblyscript/examples/graphql/package-lock.json @@ -29,19 +29,18 @@ "license": "Apache-2.0", "dependencies": { "@assemblyscript/wasi-shim": "^0.1.0", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21", "semver": "^7.6.3", "xid-ts": "^1.1.4" }, "devDependencies": { - "@eslint/js": "^9.11.1", + "@eslint/js": "^9.12.0", "@types/eslint__js": "^8.42.3", "@types/node": "^20.16.10", "as-test": "^0.3.4", "assemblyscript": "^0.27.30", "assemblyscript-prettier": "^3.0.1", - "eslint": "^9.11.1", + "eslint": "^9.12.0", "prettier": "^3.3.3", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0", @@ -122,7 +121,7 @@ } }, "../../src/node_modules/@eslint/js": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "engines": { @@ -148,6 +147,26 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "../../src/node_modules/@humanfs/core": { + "version": "0.19.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "../../src/node_modules/@humanfs/node": { + "version": "0.16.5", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, "../../src/node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "dev": true, @@ -161,7 +180,7 @@ } }, "../../src/node_modules/@humanwhocodes/retry": { - "version": "0.3.0", + "version": "0.3.1", "dev": true, "license": "Apache-2.0", "engines": { @@ -172,13 +191,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "../../src/node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "../../src/node_modules/@isaacs/cliui": { "version": "8.0.2", "dev": true, @@ -797,7 +809,7 @@ } }, "../../src/node_modules/eslint": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "dependencies": { @@ -806,11 +818,11 @@ "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.1", + "@eslint/js": "9.12.0", "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -818,9 +830,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -830,13 +842,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { @@ -858,7 +868,7 @@ } }, "../../src/node_modules/eslint-scope": { - "version": "8.0.2", + "version": "8.1.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -884,7 +894,7 @@ } }, "../../src/node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -895,13 +905,13 @@ } }, "../../src/node_modules/espree": { - "version": "10.1.0", + "version": "10.2.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -911,7 +921,7 @@ } }, "../../src/node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -1178,14 +1188,6 @@ "node": ">=0.12.0" } }, - "../../src/node_modules/is-path-inside": { - "version": "3.0.3", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "../../src/node_modules/isexe": { "version": "2.0.0", "dev": true, diff --git a/sdk/assemblyscript/examples/http/package-lock.json b/sdk/assemblyscript/examples/http/package-lock.json index ad330c58..cbed094b 100644 --- a/sdk/assemblyscript/examples/http/package-lock.json +++ b/sdk/assemblyscript/examples/http/package-lock.json @@ -29,19 +29,18 @@ "license": "Apache-2.0", "dependencies": { "@assemblyscript/wasi-shim": "^0.1.0", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21", "semver": "^7.6.3", "xid-ts": "^1.1.4" }, "devDependencies": { - "@eslint/js": "^9.11.1", + "@eslint/js": "^9.12.0", "@types/eslint__js": "^8.42.3", "@types/node": "^20.16.10", "as-test": "^0.3.4", "assemblyscript": "^0.27.30", "assemblyscript-prettier": "^3.0.1", - "eslint": "^9.11.1", + "eslint": "^9.12.0", "prettier": "^3.3.3", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0", @@ -122,7 +121,7 @@ } }, "../../src/node_modules/@eslint/js": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "engines": { @@ -148,6 +147,26 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "../../src/node_modules/@humanfs/core": { + "version": "0.19.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "../../src/node_modules/@humanfs/node": { + "version": "0.16.5", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, "../../src/node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "dev": true, @@ -161,7 +180,7 @@ } }, "../../src/node_modules/@humanwhocodes/retry": { - "version": "0.3.0", + "version": "0.3.1", "dev": true, "license": "Apache-2.0", "engines": { @@ -172,13 +191,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "../../src/node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "../../src/node_modules/@isaacs/cliui": { "version": "8.0.2", "dev": true, @@ -797,7 +809,7 @@ } }, "../../src/node_modules/eslint": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "dependencies": { @@ -806,11 +818,11 @@ "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.1", + "@eslint/js": "9.12.0", "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -818,9 +830,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -830,13 +842,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { @@ -858,7 +868,7 @@ } }, "../../src/node_modules/eslint-scope": { - "version": "8.0.2", + "version": "8.1.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -884,7 +894,7 @@ } }, "../../src/node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -895,13 +905,13 @@ } }, "../../src/node_modules/espree": { - "version": "10.1.0", + "version": "10.2.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -911,7 +921,7 @@ } }, "../../src/node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -1178,14 +1188,6 @@ "node": ">=0.12.0" } }, - "../../src/node_modules/is-path-inside": { - "version": "3.0.3", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "../../src/node_modules/isexe": { "version": "2.0.0", "dev": true, diff --git a/sdk/assemblyscript/examples/postgresql/package-lock.json b/sdk/assemblyscript/examples/postgresql/package-lock.json index 2b830451..e82bed92 100644 --- a/sdk/assemblyscript/examples/postgresql/package-lock.json +++ b/sdk/assemblyscript/examples/postgresql/package-lock.json @@ -29,19 +29,18 @@ "license": "Apache-2.0", "dependencies": { "@assemblyscript/wasi-shim": "^0.1.0", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21", "semver": "^7.6.3", "xid-ts": "^1.1.4" }, "devDependencies": { - "@eslint/js": "^9.11.1", + "@eslint/js": "^9.12.0", "@types/eslint__js": "^8.42.3", "@types/node": "^20.16.10", "as-test": "^0.3.4", "assemblyscript": "^0.27.30", "assemblyscript-prettier": "^3.0.1", - "eslint": "^9.11.1", + "eslint": "^9.12.0", "prettier": "^3.3.3", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0", @@ -122,7 +121,7 @@ } }, "../../src/node_modules/@eslint/js": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "engines": { @@ -148,6 +147,26 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "../../src/node_modules/@humanfs/core": { + "version": "0.19.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "../../src/node_modules/@humanfs/node": { + "version": "0.16.5", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, "../../src/node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "dev": true, @@ -161,7 +180,7 @@ } }, "../../src/node_modules/@humanwhocodes/retry": { - "version": "0.3.0", + "version": "0.3.1", "dev": true, "license": "Apache-2.0", "engines": { @@ -172,13 +191,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "../../src/node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "../../src/node_modules/@isaacs/cliui": { "version": "8.0.2", "dev": true, @@ -797,7 +809,7 @@ } }, "../../src/node_modules/eslint": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "dependencies": { @@ -806,11 +818,11 @@ "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.1", + "@eslint/js": "9.12.0", "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -818,9 +830,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -830,13 +842,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { @@ -858,7 +868,7 @@ } }, "../../src/node_modules/eslint-scope": { - "version": "8.0.2", + "version": "8.1.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -884,7 +894,7 @@ } }, "../../src/node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -895,13 +905,13 @@ } }, "../../src/node_modules/espree": { - "version": "10.1.0", + "version": "10.2.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -911,7 +921,7 @@ } }, "../../src/node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -1178,14 +1188,6 @@ "node": ">=0.12.0" } }, - "../../src/node_modules/is-path-inside": { - "version": "3.0.3", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "../../src/node_modules/isexe": { "version": "2.0.0", "dev": true, diff --git a/sdk/assemblyscript/examples/simple/package-lock.json b/sdk/assemblyscript/examples/simple/package-lock.json index aa39edf2..94e20471 100644 --- a/sdk/assemblyscript/examples/simple/package-lock.json +++ b/sdk/assemblyscript/examples/simple/package-lock.json @@ -28,19 +28,18 @@ "license": "Apache-2.0", "dependencies": { "@assemblyscript/wasi-shim": "^0.1.0", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21", "semver": "^7.6.3", "xid-ts": "^1.1.4" }, "devDependencies": { - "@eslint/js": "^9.11.1", + "@eslint/js": "^9.12.0", "@types/eslint__js": "^8.42.3", "@types/node": "^20.16.10", "as-test": "^0.3.4", "assemblyscript": "^0.27.30", "assemblyscript-prettier": "^3.0.1", - "eslint": "^9.11.1", + "eslint": "^9.12.0", "prettier": "^3.3.3", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0", @@ -121,7 +120,7 @@ } }, "../../src/node_modules/@eslint/js": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "engines": { @@ -147,6 +146,26 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "../../src/node_modules/@humanfs/core": { + "version": "0.19.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "../../src/node_modules/@humanfs/node": { + "version": "0.16.5", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, "../../src/node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "dev": true, @@ -160,7 +179,7 @@ } }, "../../src/node_modules/@humanwhocodes/retry": { - "version": "0.3.0", + "version": "0.3.1", "dev": true, "license": "Apache-2.0", "engines": { @@ -171,13 +190,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "../../src/node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "../../src/node_modules/@isaacs/cliui": { "version": "8.0.2", "dev": true, @@ -796,7 +808,7 @@ } }, "../../src/node_modules/eslint": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "dependencies": { @@ -805,11 +817,11 @@ "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.1", + "@eslint/js": "9.12.0", "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -817,9 +829,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -829,13 +841,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { @@ -857,7 +867,7 @@ } }, "../../src/node_modules/eslint-scope": { - "version": "8.0.2", + "version": "8.1.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -883,7 +893,7 @@ } }, "../../src/node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -894,13 +904,13 @@ } }, "../../src/node_modules/espree": { - "version": "10.1.0", + "version": "10.2.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -910,7 +920,7 @@ } }, "../../src/node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -1177,14 +1187,6 @@ "node": ">=0.12.0" } }, - "../../src/node_modules/is-path-inside": { - "version": "3.0.3", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "../../src/node_modules/isexe": { "version": "2.0.0", "dev": true, diff --git a/sdk/assemblyscript/examples/textgeneration/assembly/index.ts b/sdk/assemblyscript/examples/textgeneration/assembly/index.ts index fb0f17fb..4d1b96db 100644 --- a/sdk/assemblyscript/examples/textgeneration/assembly/index.ts +++ b/sdk/assemblyscript/examples/textgeneration/assembly/index.ts @@ -13,7 +13,7 @@ import { ResponseFormat, SystemMessage, UserMessage, -} from "@hypermode/models-as/models/openai/chat"; +} from "@hypermode/modus-sdk-as/models/openai/chat"; // In this example, we will generate text using the OpenAI Chat model. // See https://platform.openai.com/docs/api-reference/chat/create for more details @@ -78,8 +78,6 @@ ${sampleProductJson}`; // This function generates multiple products. export function generateProducts(category: string, quantity: i32): Product[] { - // const instruction = `Generate ${quantity} products for the category provided.`; - // Similar to the previous example above, we can tailor the instruction and prompt // to guide the model in generating the desired output. Note that understanding the behavior // of the model is important to get the desired results. In this case, we need the model diff --git a/sdk/assemblyscript/examples/textgeneration/package-lock.json b/sdk/assemblyscript/examples/textgeneration/package-lock.json index c447fc43..e49c8c48 100644 --- a/sdk/assemblyscript/examples/textgeneration/package-lock.json +++ b/sdk/assemblyscript/examples/textgeneration/package-lock.json @@ -7,7 +7,6 @@ "name": "text-generation-example", "license": "Apache-2.0", "dependencies": { - "@hypermode/models-as": "^0.2.4", "@hypermode/modus-sdk-as": "../../src", "json-as": "^0.9.21" }, @@ -30,19 +29,18 @@ "license": "Apache-2.0", "dependencies": { "@assemblyscript/wasi-shim": "^0.1.0", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21", "semver": "^7.6.3", "xid-ts": "^1.1.4" }, "devDependencies": { - "@eslint/js": "^9.11.1", + "@eslint/js": "^9.12.0", "@types/eslint__js": "^8.42.3", "@types/node": "^20.16.10", "as-test": "^0.3.4", "assemblyscript": "^0.27.30", "assemblyscript-prettier": "^3.0.1", - "eslint": "^9.11.1", + "eslint": "^9.12.0", "prettier": "^3.3.3", "typescript": "^5.6.2", "typescript-eslint": "^8.8.0", @@ -123,7 +121,7 @@ } }, "../../src/node_modules/@eslint/js": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "engines": { @@ -149,6 +147,26 @@ "node": "^18.18.0 || ^20.9.0 || >=21.1.0" } }, + "../../src/node_modules/@humanfs/core": { + "version": "0.19.0", + "dev": true, + "license": "Apache-2.0", + "engines": { + "node": ">=18.18.0" + } + }, + "../../src/node_modules/@humanfs/node": { + "version": "0.16.5", + "dev": true, + "license": "Apache-2.0", + "dependencies": { + "@humanfs/core": "^0.19.0", + "@humanwhocodes/retry": "^0.3.0" + }, + "engines": { + "node": ">=18.18.0" + } + }, "../../src/node_modules/@humanwhocodes/module-importer": { "version": "1.0.1", "dev": true, @@ -162,7 +180,7 @@ } }, "../../src/node_modules/@humanwhocodes/retry": { - "version": "0.3.0", + "version": "0.3.1", "dev": true, "license": "Apache-2.0", "engines": { @@ -173,13 +191,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "../../src/node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "../../src/node_modules/@isaacs/cliui": { "version": "8.0.2", "dev": true, @@ -798,7 +809,7 @@ } }, "../../src/node_modules/eslint": { - "version": "9.11.1", + "version": "9.12.0", "dev": true, "license": "MIT", "dependencies": { @@ -807,11 +818,11 @@ "@eslint/config-array": "^0.18.0", "@eslint/core": "^0.6.0", "@eslint/eslintrc": "^3.1.0", - "@eslint/js": "9.11.1", + "@eslint/js": "9.12.0", "@eslint/plugin-kit": "^0.2.0", + "@humanfs/node": "^0.16.5", "@humanwhocodes/module-importer": "^1.0.1", - "@humanwhocodes/retry": "^0.3.0", - "@nodelib/fs.walk": "^1.2.8", + "@humanwhocodes/retry": "^0.3.1", "@types/estree": "^1.0.6", "@types/json-schema": "^7.0.15", "ajv": "^6.12.4", @@ -819,9 +830,9 @@ "cross-spawn": "^7.0.2", "debug": "^4.3.2", "escape-string-regexp": "^4.0.0", - "eslint-scope": "^8.0.2", - "eslint-visitor-keys": "^4.0.0", - "espree": "^10.1.0", + "eslint-scope": "^8.1.0", + "eslint-visitor-keys": "^4.1.0", + "espree": "^10.2.0", "esquery": "^1.5.0", "esutils": "^2.0.2", "fast-deep-equal": "^3.1.3", @@ -831,13 +842,11 @@ "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0", - "is-path-inside": "^3.0.3", "json-stable-stringify-without-jsonify": "^1.0.1", "lodash.merge": "^4.6.2", "minimatch": "^3.1.2", "natural-compare": "^1.4.0", "optionator": "^0.9.3", - "strip-ansi": "^6.0.1", "text-table": "^0.2.0" }, "bin": { @@ -859,7 +868,7 @@ } }, "../../src/node_modules/eslint-scope": { - "version": "8.0.2", + "version": "8.1.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { @@ -885,7 +894,7 @@ } }, "../../src/node_modules/eslint/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -896,13 +905,13 @@ } }, "../../src/node_modules/espree": { - "version": "10.1.0", + "version": "10.2.0", "dev": true, "license": "BSD-2-Clause", "dependencies": { "acorn": "^8.12.0", "acorn-jsx": "^5.3.2", - "eslint-visitor-keys": "^4.0.0" + "eslint-visitor-keys": "^4.1.0" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -912,7 +921,7 @@ } }, "../../src/node_modules/espree/node_modules/eslint-visitor-keys": { - "version": "4.0.0", + "version": "4.1.0", "dev": true, "license": "Apache-2.0", "engines": { @@ -1179,14 +1188,6 @@ "node": ">=0.12.0" } }, - "../../src/node_modules/is-path-inside": { - "version": "3.0.3", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "../../src/node_modules/isexe": { "version": "2.0.0", "dev": true, @@ -2090,13 +2091,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@hypermode/models-as": { - "version": "0.2.4", - "license": "MIT", - "dependencies": { - "json-as": "^0.9.21" - } - }, "node_modules/@hypermode/modus-sdk-as": { "resolved": "../../src", "link": true diff --git a/sdk/assemblyscript/examples/textgeneration/package.json b/sdk/assemblyscript/examples/textgeneration/package.json index 185615fa..7d7dbf10 100644 --- a/sdk/assemblyscript/examples/textgeneration/package.json +++ b/sdk/assemblyscript/examples/textgeneration/package.json @@ -13,7 +13,6 @@ }, "dependencies": { "@hypermode/modus-sdk-as": "../../src", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21" }, "devDependencies": { diff --git a/sdk/assemblyscript/scripts/install-all.sh b/sdk/assemblyscript/scripts/install-all.sh new file mode 100755 index 00000000..3b482143 --- /dev/null +++ b/sdk/assemblyscript/scripts/install-all.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# Runs "npm install" on all projects. + +set -euo pipefail +trap "cd \"${PWD}\"" EXIT +cd "$(dirname "$0")" +cd .. + +cd src +npm install + +cd ../examples +for example in *; do + if [ -d "${example}" ]; then + cd "${example}" + npm install + cd .. + fi +done diff --git a/sdk/assemblyscript/src/assembly/models.ts b/sdk/assemblyscript/src/assembly/models.ts index 20095373..6f3f1723 100644 --- a/sdk/assemblyscript/src/assembly/models.ts +++ b/sdk/assemblyscript/src/assembly/models.ts @@ -7,8 +7,10 @@ * SPDX-License-Identifier: Apache-2.0 */ +import { JSON } from "json-as"; import * as utils from "./utils"; -import { Model, ModelFactory, ModelInfo } from "@hypermode/models-as"; + +type ModelInvoker = (modelName: string, inputJson: string) => string | null; // @ts-expect-error: decorator @external("hypermode", "lookupModel") @@ -45,5 +47,51 @@ class ModusModelFactory implements ModelFactory { } } +export class ModelInfo { + constructor( + public readonly name: string, + public readonly fullName: string = name, + ) {} +} + +export interface ModelFactory { + getModel(modelName: string): T; +} + +export abstract class Model { + static invoker: ModelInvoker | null = null; + protected constructor(public info: ModelInfo) {} + + debug: boolean = false; + + /** + * Invokes the model with the given input. + * @param input The input object to pass to the model. + * @returns The output object from the model. + */ + invoke(input: TInput): TOutput { + if (!Model.invoker) { + throw new Error("Model invoker is not set."); + } + + const modelName = this.info.name; + const inputJson = JSON.stringify(input); + if (this.debug) { + console.debug(`Invoking ${modelName} model with input: ${inputJson}`); + } + + const outputJson = Model.invoker(modelName, inputJson); + if (!outputJson) { + throw new Error(`Failed to invoke ${modelName} model.`); + } + + if (this.debug) { + console.debug(`Received output: ${outputJson}`); + } + + return JSON.parse(outputJson); + } +} + const factory = new ModusModelFactory(); export default factory; diff --git a/sdk/assemblyscript/src/assembly/models/anthropic/messages.ts b/sdk/assemblyscript/src/assembly/models/anthropic/messages.ts new file mode 100644 index 00000000..b0dc4f66 --- /dev/null +++ b/sdk/assemblyscript/src/assembly/models/anthropic/messages.ts @@ -0,0 +1,385 @@ +import { Model } from "../../models"; +import { JSON } from "json-as"; + +/** + * Provides input and output types that conform to the Anthropic Messages API. + * + * Reference: https://docs.anthropic.com/en/api/messages + */ +export class AnthropicMessagesModel extends Model< + AnthropicMessagesInput, + AnthropicMessagesOutput +> { + /** + * Creates an input object for the Anthropic Messages API. + * + * @param messages: An array of messages to send to the model. + * Note that if you want to include a system prompt, you can use the top-level system parameter — + * there is no "system" role for input messages in the Messages API. + * @returns An input object that can be passed to the `invoke` method. + */ + createInput(messages: Message[]): AnthropicMessagesInput { + const model = this.info.fullName; + return { model, messages }; + } +} + +/** + * A message object that can be sent to the model. + */ +@json +export class Message { + /** + * Creates a new message object. + * + * @param role The role of the author of this message. + * @param content The contents of the message. + */ + constructor(role: string, content: string) { + this._role = role; + this.content = content; + } + + + @alias("role") + protected _role: string; + + /** + * The role of the author of this message. + */ + get role(): string { + return this._role; + } + + /** + * The contents of the message. + * For now it can only be a string, even though Anthropic supports more complex types. + */ + content: string; // TODO: support more complex types +} + +/** + * A user message. + */ +@json +export class UserMessage extends Message { + /** + * Creates a new user message object. + * + * @param content The contents of the message. + */ + constructor(content: string) { + super("user", content); + } +} + +/** + * An assistant message. + */ +@json +export class AssistantMessage extends Message { + /** + * Creates a new assistant message object. + * + * @param content The contents of the message. + */ + constructor(content: string) { + super("assistant", content); + } +} + +/** + * The input object for the Anthropic Messages API. + */ +@json +export class AnthropicMessagesInput { + /** + * The model that will complete your prompt. + * Must be the exact string expected by the model provider. + * For example, "claude-3-5-sonnet-20240620". + * + * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional + * details and options. + * + * @remarks + * This field is automatically set by the `createInput` method when creating this object. + * It does not need to be set manually. + */ + model!: string; + + /** + * Input messages. + * + * We do not currently support image content blocks, which are available starting with + * Claude 3 models. This will be added in a future release. + * + * Note that if you want to include a + * [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use + * the top-level `system` parameter — there is no `"system"` role for input + * messages in the Messages API. + */ + messages!: Message[]; + + /** + * The maximum number of tokens to generate before stopping. + * + * Different models have different maximum values for this parameter. See + * [models](https://docs.anthropic.com/en/docs/models-overview) for details. + * + * @default 4096 + */ + @alias("max_tokens") + maxTokens: i32 = 4096; + + /** + * A `Metadata` object describing the request. + */ + @omitnull() + metadata: Metadata | null = null; + + /** + * Custom text sequences that will cause the model to stop generating. + */ + @alias("stop_sequences") + @omitnull() + stopSequences: string[] | null = null; + + /** + * Streaming is not currently supported. + * + * @default false + */ + @alias("stream") + @omitif("this._stream == false") + private _stream: boolean = false; + + /** + * System prompt. + * + * A system prompt is a way of providing context and instructions to Claude, such + * as specifying a particular goal or role. See [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts). + */ + @omitnull() + system: string | null = null; + + /** + * A number between `0.0` and `1.0` that controls the randomness injected into the response. + * + * It is recommended to use `temperature` closer to `0.0` + * for analytical / multiple choice, and closer to `1.0` for creative tasks. + * + * Note that even with `temperature` of `0.0`, the results will not be fully + * deterministic. + * + * @default 1.0 + */ + @omitif("this.temperature == 1.0") + temperature: f64 = 1.0; + + /** + * How the model should use the provided tools. + * + * Use either `ToolChoiceAuto`, `ToolChoiceAny`, or `ToolChoiceTool(name: string)`. + */ + @alias("tool_choice") + @omitnull() + toolChoice: ToolChoice | null = null; + + /** + * Definitions of tools that the model may use. + * + * Tools can be used for workflows that include running client-side tools and + * functions, or more generally whenever you want the model to produce a particular + * JSON structure of output. + * + * See Anthropic's [guide](https://docs.anthropic.com/en/docs/tool-use) for more details. + */ + @omitnull() + tools: Tool[] | null = null; + + /** + * Only sample from the top K options for each subsequent token. + * + * Recommended for advanced use cases only. You usually only need to use + * `temperature`. + */ + @alias("top_k") + @omitif("this.topK == -1") + topK: i64 = -1; // The default value of top_k is not specified in the API docs + + /** + * Use nucleus sampling. + * + * You should either alter `temperature` or `top_p`, but not both. + * + * Recommended for advanced use cases only. You usually only need to use + * `temperature`. + */ + @alias("top_p") + @omitif("this.topP == 0.999") + topP: f64 = 0.999; +} + + +@json +export class Metadata { + /** + * An external identifier for the user who is associated with the request. + */ + @alias("user_id") + userId: string | null = null; +} + +/** + * A tool object that the model may call. + */ +@json +export class Tool { + /** + * Name of the tool. + */ + name!: string; + + /** + * [JSON schema](https://json-schema.org/) for this tool's input. + * + * This defines the shape of the `input` that your tool accepts and that the model + * will produce. + */ + @alias("input_schema") + inputSchema!: JSON.Raw; + + /** + * Optional, but strongly-recommended description of the tool. + */ + @omitnull() + description: string | null = null; +} + + +@json +export class ToolChoice { + constructor(type: string, name: string | null = null) { + this._type = type; + this._name = name; + } + + + @alias("type") + protected _type: string; + + /** + * The name of the tool to use. + */ + @alias("name") + @omitnull() + protected _name: string | null = null; +} + +/** + * The model will automatically decide whether to use tools. + */ +export const ToolChoiceAuto = new ToolChoice("auto"); + +/** + * The model will use any available tools. + */ +export const ToolChoiceAny = new ToolChoice("any"); + +/** + * The model will use the specified tool. + */ +export const ToolChoiceTool = (name: string): ToolChoice => + new ToolChoice("tool", name); + +/** + * The output object for the Anthropic Messages API. + */ +@json +export class AnthropicMessagesOutput { + /** + * Unique object identifier. + */ + id!: string; + + /** + * Content generated by the model. + * + */ + content!: ContentBlock[]; + + /** + * The model that handled the request. + */ + model!: string; + + /** + * Conversational role of the generated message. + * + * This will always be `"assistant"`. + */ + role!: "assistant"; + + /** + * The reason that the model stopped. + */ + @alias("stop_reason") + stopReason!: string; + + /** + * Which custom stop sequence was generated, if any. + * + * This value will be a non-null string if one of your custom stop sequences was + * generated. + */ + @alias("stop_sequence") + stopSequence: string | null = null; + + /** + * Object type. This is always `"message"`. + */ + type!: "message"; + + /** + * Billing and rate-limit usage. + */ + usage!: Usage; +} + + +@json +export class ContentBlock { + type!: string; + + // Text block + @omitnull() + text: string | null = null; + + // Tool use block + @omitnull() + id: string | null = null; + + + @omitnull() + input: JSON.Raw | null = null; + + + @omitnull() + name: string | null = null; +} + + +@json +export class Usage { + /** + * The number of input tokens which were used. + */ + @alias("input_tokens") + inputTokens!: number; + + /** + * The number of output tokens which were used. + */ + @alias("output_tokens") + outputTokens!: number; +} diff --git a/sdk/assemblyscript/src/models/anthropic/messages.ts b/sdk/assemblyscript/src/models/anthropic/messages.ts new file mode 100644 index 00000000..922bd4e7 --- /dev/null +++ b/sdk/assemblyscript/src/models/anthropic/messages.ts @@ -0,0 +1,394 @@ +/* + * Copyright 2024 Hypermode, Inc. + * Licensed under the terms of the Apache License, Version 2.0 + * See the LICENSE file that accompanied this code for further details. + * + * SPDX-FileCopyrightText: 2024 Hypermode, Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Model } from "../../assembly/models"; +import { JSON } from "json-as"; + +/** + * Provides input and output types that conform to the Anthropic Messages API. + * + * Reference: https://docs.anthropic.com/en/api/messages + */ +export class AnthropicMessagesModel extends Model< + AnthropicMessagesInput, + AnthropicMessagesOutput +> { + /** + * Creates an input object for the Anthropic Messages API. + * + * @param messages: An array of messages to send to the model. + * Note that if you want to include a system prompt, you can use the top-level system parameter — + * there is no "system" role for input messages in the Messages API. + * @returns An input object that can be passed to the `invoke` method. + */ + createInput(messages: Message[]): AnthropicMessagesInput { + const model = this.info.fullName; + return { model, messages }; + } +} + +/** + * A message object that can be sent to the model. + */ +@json +export class Message { + /** + * Creates a new message object. + * + * @param role The role of the author of this message. + * @param content The contents of the message. + */ + constructor(role: string, content: string) { + this._role = role; + this.content = content; + } + + + @alias("role") + protected _role: string; + + /** + * The role of the author of this message. + */ + get role(): string { + return this._role; + } + + /** + * The contents of the message. + * For now it can only be a string, even though Anthropic supports more complex types. + */ + content: string; // TODO: support more complex types +} + +/** + * A user message. + */ +@json +export class UserMessage extends Message { + /** + * Creates a new user message object. + * + * @param content The contents of the message. + */ + constructor(content: string) { + super("user", content); + } +} + +/** + * An assistant message. + */ +@json +export class AssistantMessage extends Message { + /** + * Creates a new assistant message object. + * + * @param content The contents of the message. + */ + constructor(content: string) { + super("assistant", content); + } +} + +/** + * The input object for the Anthropic Messages API. + */ +@json +export class AnthropicMessagesInput { + /** + * The model that will complete your prompt. + * Must be the exact string expected by the model provider. + * For example, "claude-3-5-sonnet-20240620". + * + * See [models](https://docs.anthropic.com/en/docs/models-overview) for additional + * details and options. + * + * @remarks + * This field is automatically set by the `createInput` method when creating this object. + * It does not need to be set manually. + */ + model!: string; + + /** + * Input messages. + * + * We do not currently support image content blocks, which are available starting with + * Claude 3 models. This will be added in a future release. + * + * Note that if you want to include a + * [system prompt](https://docs.anthropic.com/en/docs/system-prompts), you can use + * the top-level `system` parameter — there is no `"system"` role for input + * messages in the Messages API. + */ + messages!: Message[]; + + /** + * The maximum number of tokens to generate before stopping. + * + * Different models have different maximum values for this parameter. See + * [models](https://docs.anthropic.com/en/docs/models-overview) for details. + * + * @default 4096 + */ + @alias("max_tokens") + maxTokens: i32 = 4096; + + /** + * A `Metadata` object describing the request. + */ + @omitnull() + metadata: Metadata | null = null; + + /** + * Custom text sequences that will cause the model to stop generating. + */ + @alias("stop_sequences") + @omitnull() + stopSequences: string[] | null = null; + + /** + * Streaming is not currently supported. + * + * @default false + */ + @alias("stream") + @omitif("this._stream == false") + private _stream: boolean = false; + + /** + * System prompt. + * + * A system prompt is a way of providing context and instructions to Claude, such + * as specifying a particular goal or role. See [guide to system prompts](https://docs.anthropic.com/en/docs/system-prompts). + */ + @omitnull() + system: string | null = null; + + /** + * A number between `0.0` and `1.0` that controls the randomness injected into the response. + * + * It is recommended to use `temperature` closer to `0.0` + * for analytical / multiple choice, and closer to `1.0` for creative tasks. + * + * Note that even with `temperature` of `0.0`, the results will not be fully + * deterministic. + * + * @default 1.0 + */ + @omitif("this.temperature == 1.0") + temperature: f64 = 1.0; + + /** + * How the model should use the provided tools. + * + * Use either `ToolChoiceAuto`, `ToolChoiceAny`, or `ToolChoiceTool(name: string)`. + */ + @alias("tool_choice") + @omitnull() + toolChoice: ToolChoice | null = null; + + /** + * Definitions of tools that the model may use. + * + * Tools can be used for workflows that include running client-side tools and + * functions, or more generally whenever you want the model to produce a particular + * JSON structure of output. + * + * See Anthropic's [guide](https://docs.anthropic.com/en/docs/tool-use) for more details. + */ + @omitnull() + tools: Tool[] | null = null; + + /** + * Only sample from the top K options for each subsequent token. + * + * Recommended for advanced use cases only. You usually only need to use + * `temperature`. + */ + @alias("top_k") + @omitif("this.topK == -1") + topK: i64 = -1; // The default value of top_k is not specified in the API docs + + /** + * Use nucleus sampling. + * + * You should either alter `temperature` or `top_p`, but not both. + * + * Recommended for advanced use cases only. You usually only need to use + * `temperature`. + */ + @alias("top_p") + @omitif("this.topP == 0.999") + topP: f64 = 0.999; +} + + +@json +export class Metadata { + /** + * An external identifier for the user who is associated with the request. + */ + @alias("user_id") + userId: string | null = null; +} + +/** + * A tool object that the model may call. + */ +@json +export class Tool { + /** + * Name of the tool. + */ + name!: string; + + /** + * [JSON schema](https://json-schema.org/) for this tool's input. + * + * This defines the shape of the `input` that your tool accepts and that the model + * will produce. + */ + @alias("input_schema") + inputSchema!: JSON.Raw; + + /** + * Optional, but strongly-recommended description of the tool. + */ + @omitnull() + description: string | null = null; +} + + +@json +export class ToolChoice { + constructor(type: string, name: string | null = null) { + this._type = type; + this._name = name; + } + + + @alias("type") + protected _type: string; + + /** + * The name of the tool to use. + */ + @alias("name") + @omitnull() + protected _name: string | null = null; +} + +/** + * The model will automatically decide whether to use tools. + */ +export const ToolChoiceAuto = new ToolChoice("auto"); + +/** + * The model will use any available tools. + */ +export const ToolChoiceAny = new ToolChoice("any"); + +/** + * The model will use the specified tool. + */ +export const ToolChoiceTool = (name: string): ToolChoice => + new ToolChoice("tool", name); + +/** + * The output object for the Anthropic Messages API. + */ +@json +export class AnthropicMessagesOutput { + /** + * Unique object identifier. + */ + id!: string; + + /** + * Content generated by the model. + * + */ + content!: ContentBlock[]; + + /** + * The model that handled the request. + */ + model!: string; + + /** + * Conversational role of the generated message. + * + * This will always be `"assistant"`. + */ + role!: "assistant"; + + /** + * The reason that the model stopped. + */ + @alias("stop_reason") + stopReason!: string; + + /** + * Which custom stop sequence was generated, if any. + * + * This value will be a non-null string if one of your custom stop sequences was + * generated. + */ + @alias("stop_sequence") + stopSequence: string | null = null; + + /** + * Object type. This is always `"message"`. + */ + type!: "message"; + + /** + * Billing and rate-limit usage. + */ + usage!: Usage; +} + + +@json +export class ContentBlock { + type!: string; + + // Text block + @omitnull() + text: string | null = null; + + // Tool use block + @omitnull() + id: string | null = null; + + + @omitnull() + input: JSON.Raw | null = null; + + + @omitnull() + name: string | null = null; +} + + +@json +export class Usage { + /** + * The number of input tokens which were used. + */ + @alias("input_tokens") + inputTokens!: number; + + /** + * The number of output tokens which were used. + */ + @alias("output_tokens") + outputTokens!: number; +} diff --git a/sdk/assemblyscript/src/models/experimental/classification.ts b/sdk/assemblyscript/src/models/experimental/classification.ts new file mode 100644 index 00000000..8127ef02 --- /dev/null +++ b/sdk/assemblyscript/src/models/experimental/classification.ts @@ -0,0 +1,91 @@ +/* + * Copyright 2024 Hypermode, Inc. + * Licensed under the terms of the Apache License, Version 2.0 + * See the LICENSE file that accompanied this code for further details. + * + * SPDX-FileCopyrightText: 2024 Hypermode, Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Model } from "../../assembly/models"; + +/** + * A model that returns classification results for a list of text strings. + * + * @remarks + * This model interface is experimental and may change in the future. + * It is primarily intended for use with with classification models hosted on Hypermode. + */ +export class ClassificationModel extends Model< + ClassificationInput, + ClassificationOutput +> { + /** + * Creates an input object for the classification model. + * + * @param instances - A list of one or more text strings to classify. + * @returns An input object that can be passed to the `invoke` method. + */ + createInput(instances: string[]): ClassificationInput { + return { instances }; + } +} + +/** + * An input object for the classification model. + */ +@json +export class ClassificationInput { + /** + * A list of one or more text strings of text to classify. + */ + instances!: string[]; +} + +/** + * An output object for the classification model. + */ +@json +export class ClassificationOutput { + /** + * A list of prediction results that correspond to each input text string. + */ + predictions!: ClassifierResult[]; +} + +/** + * A classification result for a single text string. + */ +@json +export class ClassifierResult { + /** + * The classification label with the highest confidence. + */ + label!: string; + + /** + * The confidence score for the classification label. + */ + confidence!: f32; + + /** + * The list of all classification labels with their corresponding probabilities. + */ + probabilities!: ClassifierLabel[]; +} + +/** + * A classification label with its corresponding probability. + */ +@json +export class ClassifierLabel { + /** + * The classification label. + */ + label!: string; + + /** + * The probability value. + */ + probability!: f32; +} diff --git a/sdk/assemblyscript/src/models/experimental/embeddings.ts b/sdk/assemblyscript/src/models/experimental/embeddings.ts new file mode 100644 index 00000000..500be1e0 --- /dev/null +++ b/sdk/assemblyscript/src/models/experimental/embeddings.ts @@ -0,0 +1,51 @@ +/* + * Copyright 2024 Hypermode, Inc. + * Licensed under the terms of the Apache License, Version 2.0 + * See the LICENSE file that accompanied this code for further details. + * + * SPDX-FileCopyrightText: 2024 Hypermode, Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Model } from "../../assembly/models"; + +/** + * A model that returns embeddings for a list of text strings. + * + * @remarks + * This model interface is experimental and may change in the future. + * It is primarily intended for use with with embedding models hosted on Hypermode. + */ +export class EmbeddingsModel extends Model { + /** + * Creates an input object for the embeddings model. + * + * @param instances - A list of one or more text strings to create vector embeddings for. + * @returns An input object that can be passed to the `invoke` method. + */ + createInput(instances: string[]): EmbeddingsInput { + return { instances }; + } +} + +/** + * An input object for the embeddings model. + */ +@json +export class EmbeddingsInput { + /** + * A list of one or more text strings to create vector embeddings for. + */ + instances!: string[]; +} + +/** + * An output object for the embeddings model. + */ +@json +export class EmbeddingsOutput { + /** + * A list of vector embeddings that correspond to each input text string. + */ + predictions!: f32[][]; +} diff --git a/sdk/assemblyscript/src/models/gemini/generate.ts b/sdk/assemblyscript/src/models/gemini/generate.ts new file mode 100644 index 00000000..0731e6c5 --- /dev/null +++ b/sdk/assemblyscript/src/models/gemini/generate.ts @@ -0,0 +1,571 @@ +/* + * Copyright 2024 Hypermode, Inc. + * Licensed under the terms of the Apache License, Version 2.0 + * See the LICENSE file that accompanied this code for further details. + * + * SPDX-FileCopyrightText: 2024 Hypermode, Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Model } from "../../assembly/models"; +import { JSON } from "json-as"; + +/** + * Provides input and output types that conform to the Gemini Generate Content API. + * + * Reference: https://ai.google.dev/api/generate-content + */ +export class GeminiGenerateModel extends Model< + GeminiGenerateInput, + GeminiGenerateOutput +> { + /** + * Creates an input object for the Gemini Generate Content API. + * + * @param contents The content of the current conversation with the model. + * @returns An input object that can be passed to the `invoke` method. + */ + createInput(contents: PromptContent[]): GeminiGenerateInput { + // for Gemini, the model is part of the URL, not the request body + return { contents }; + } +} + +/** + * Content type for prompts. + */ +@json +export class PromptContent { + /** + * Creates a new content object. + * + * @param role The role of the author of this content. + * @param parts The multi-part content message. + */ + constructor(role: string, parts: Part[]) { + this._role = role; + this.parts = parts; + } + + + @alias("role") + protected _role: string; + + /** + * The role of the author of this content. + */ + get role(): string { + return this._role; + } + + /** + * The multi-part content message. + * For now it can only be a text, even though Gemini supports more complex types. + */ + parts: Part[]; +} + + +@json +export class Part { + text!: string; +} + +/** + * A user content. + */ +@json +export class UserContent extends PromptContent { + /** + * Creates a new user content object. + * + * @param parts The multi-part content message. + */ + constructor(parts: Part[]) { + super("user", parts); + } +} + +/** + * A user text content. + */ +@json +export class UserTextContent extends UserContent { + /** + * Creates a new user text content object. + * + * @param content The contents of the message. + */ + constructor(content: string) { + super([{ text: content }]); + } +} + +/** + * A system text content. To be used with {@link GeminiGenerateInput.systemInstruction} + */ +@json +export class SystemTextContent extends PromptContent { + /** + * Creates a new system text content object. + * + * @param content The contents of the message. + */ + constructor(content: string) { + super("system", [{ text: content }]); + } +} + +/** + * A model content. + */ +@json +export class ModelContent extends PromptContent { + /** + * Creates a new model content object. + * + * @param parts The multi-part content message. + */ + constructor(parts: Part[]) { + super("model", parts); + } +} + +/** + * A model text content. + */ +@json +export class ModelTextContent extends ModelContent { + /** + * Creates a new model text content object. + * + * @param content The contents of the message. + */ + constructor(content: string) { + super([{ text: content }]); + } +} + +/** + * The input object for the Gemini Generate Content API. + */ +@json +export class GeminiGenerateInput { + /** + * The content of the current conversation with the model. + */ + contents!: PromptContent[]; + + /** + * Developer set system instruction. Currently, text only. + */ + @omitnull() + systemInstruction: PromptContent | null = null; + + /** + * Configuration options for model generation and outputs. + */ + generationConfig: GenerationConfig | null = null; + + /** + * A list of unique SafetySetting instances for blocking unsafe content. + */ + @omitnull() + safetySettings: SafetySetting[] | null = null; + + /** + * The name of the cached content used as context to serve the prediction. + */ + @omitnull() + cachedContent: string | null = null; + + // TODO: support `tools` and `toolConfig` fields +} + +/** + * The Gemini config options. + */ +@json +export class GenerationConfig { + /** + * Number of generated responses to return. + * Currently, this value can only be set to 1. + * + * @default 1 + */ + candidateCount: i32 = 1; + + /** + * The set of character sequences (up to 5) that will stop output generation. + */ + @omitnull() + stopSequences: string[] | null = null; + + /** + * The maximum number of tokens to include in a candidate. + * + * @remarks + * Different model variants may have different maximum token limits. + * See the `outputTokenLimit` of the model variant for the exact value. + */ + @omitif("this.maxOutputTokens == -1") + maxOutputTokens: i32 = -1; + + /** + * Controls the randomness of the output. + * + * Values can range from [0.0, `maxTemperature`], inclusive. + * + * @remarks + * Different models may have different `maxTemperature` and + * different defaults as well. See the `temperature` and + * `maxTemperature` of the model variant for the exact values. + */ + @omitif("this.temperature == -1.0") + temperature: f64 = -1.0; + + /** + * The maximum cumulative probability of tokens to consider when sampling. + * + * @remarks + * Different model variants may have different defaults. + * See the `topP` of the model variant for the exact value. + */ + @omitif("this.topP == -1.0") + topP: f64 = -1.0; + + /** + * The maximum number of tokens to consider when sampling. + * + * @remarks + * Different model variants may have different defaults. + * See the `topK` of the model variant for the exact value. + */ + @omitif("this.topK == -1") + topK: i32 = -1; + + /** + * Output response mimetype of the generated candidate text. + * Supported mimetype: + * `text/plain`: (default) Text output. + * `application/json`: JSON response in the candidates. + */ + @omitif("this.responseMimeType == 'text/plain'") + responseMimeType: string = "text/plain"; + + /** + * Output response schema of the generated candidate text. + * Note: This only applies when the specified `responseMIMEType` supports a schema; currently + * this is limited to `application/json`. + */ + @omitnull() + responseSchema: JSON.Raw | null = null; +} + +/** + * Safety setting, affecting the safety-blocking behavior. + */ +@json +export class SafetySetting { + category!: HarmCategory; + threshold!: HarmBlockThreshold; +} + +/** + * Harm categories that would cause prompts or candidates to be blocked. + */ +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace HarmCategory { + export const UNSPECIFIED = "HARM_CATEGORY_UNSPECIFIED"; + export const HATE_SPEECH = "HARM_CATEGORY_HATE_SPEECH"; + export const SEXUALLY_EXPLICIT = "HARM_CATEGORY_SEXUALLY_EXPLICIT"; + export const HARASSMENT = "HARM_CATEGORY_HARASSMENT"; + export const DANGEROUS_CONTENT = "HARM_CATEGORY_DANGEROUS_CONTENT"; +} +export type HarmCategory = string; + +/** + * Threshold above which a prompt or candidate will be blocked. + */ +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace HarmBlockThreshold { + /** + * Threshold is unspecified. + */ + export const HARM_BLOCK_THRESHOLD_UNSPECIFIED = + "HARM_BLOCK_THRESHOLD_UNSPECIFIED"; + + /** + * Content with NEGLIGIBLE will be allowed. + */ + export const BLOCK_LOW_AND_ABOVE = "BLOCK_LOW_AND_ABOVE"; + + /** + * Content with NEGLIGIBLE and LOW will be allowed. + */ + export const BLOCK_MEDIUM_AND_ABOVE = "BLOCK_MEDIUM_AND_ABOVE"; + + /** + * Content with NEGLIGIBLE, LOW, and MEDIUM will be allowed. + */ + export const BLOCK_ONLY_HIGH = "BLOCK_ONLY_HIGH"; + + /** + * All content will be allowed. + */ + export const BLOCK_NONE = "BLOCK_NONE"; +} +export type HarmBlockThreshold = string; + +/** + * The output object for the Gemini Generate Content API. + */ +@json +export class GeminiGenerateOutput { + /** + * Candidate responses from the model. + */ + candidates!: Candidate[]; + + /** + * Returns the prompt's feedback related to the content filters. + */ + @omitnull() + promptFeedback: PromptFeedback | null = null; + + /** + * Metadata on the generation requests' token usage. + */ + usageMetadata!: UsageMetadata; +} + +/** + * + */ +@json +export class Candidate { + /** + * Index of the candidate in the list of candidates. + */ + index!: i8; + + /** + * Generated content returned from the model. + */ + @omitnull() + content: ResponseContent | null = null; + + /** + * The reason why the model stopped generating tokens. + */ + @omitnull() + finishReason: FinishReason | null = null; + + /** + * List of ratings for the safety of a response candidate. + */ + @omitnull() + safetyRatings: SafetyRating[] | null = null; + + /** + * Citation information for model-generated candidate. + */ + @omitnull() + citationMetadata: CitationMetadata | null = null; +} + +/** + * Content type for response candidates. + */ +@json +export class ResponseContent { + role!: string; + + /** + * The multi-part content message. + * For now it can only be a text, even though Gemini supports more complex types. + */ + parts!: Part[]; +} + +/** + * Reason that a candidate finished. + */ +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace FinishReason { + /** + * Default value. This value is unused. + */ + export const FINISH_REASON_UNSPECIFIED = "FINISH_REASON_UNSPECIFIED"; + + /** + * Natural stop point of the model or provided stop sequence. + */ + export const STOP = "STOP"; + + /** + * The maximum number of tokens as specified in the request was reached. + */ + export const MAX_TOKENS = "MAX_TOKENS"; + + /** + * The candidate content was flagged for safety reasons. + */ + export const SAFETY = "SAFETY"; + + /** + * The candidate content was flagged for recitation reasons. + */ + export const RECITATION = "RECITATION"; + + /** + * The candidate content was flagged for using an unsupported language. + */ + export const LANGUAGE = "LANGUAGE"; + + /** + * Unknown reason. + */ + export const OTHER = "OTHER"; +} +export type FinishReason = string; + +/** + * Safety setting, affecting the safety-blocking behavior. + */ +@json +export class SafetyRating { + category!: HarmCategory; + probability!: HarmProbability; +} + +/** + * Probability that a prompt or candidate matches a harm category. + */ +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace HarmProbability { + /** + * Probability is unspecified. + */ + export const HARM_PROBABILITY_UNSPECIFIED = "HARM_PROBABILITY_UNSPECIFIED"; + + /** + * Content has a negligible chance of being unsafe. + */ + export const NEGLIGIBLE = "NEGLIGIBLE"; + + /** + * Content has a low chance of being unsafe. + */ + export const LOW = "LOW"; + + /** + * Content has a medium chance of being unsafe. + */ + export const MEDIUM = "MEDIUM"; + + /** + * Content has a high chance of being unsafe. + */ + export const HIGH = "HIGH"; +} +export type HarmProbability = string; + +/** + * Citation metadata that may be found on a {@link Candidate}. + */ +@json +export class CitationMetadata { + citationSources!: CitationSource[]; +} + +/** + * A single citation source. + */ +@json +export class CitationSource { + /** + * Start of segment of the response that is attributed to this source. + */ + @omitnull() + startIndex!: i64; + + /** + * End of the attributed segment, exclusive. + */ + @omitnull() + endIndex!: i64; + + /** + * URI that is attributed as a source for a portion of the text. + */ + @omitnull() + uri: string | null = null; + + /** + * License for the GitHub project that is attributed as a source for segment. + */ + license: string | null = null; +} + +/** + * If the prompt was blocked, this will be populated with `blockReason` and + * the relevant `safetyRatings`. + * @public + */ +@json +export class PromptFeedback { + blockReason!: BlockReason; + safetyRatings!: SafetyRating[]; +} + +/** + * Reason that a prompt was blocked. + */ +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace BlockReason { + /** + * A blocked reason was not specified. + */ + export const BLOCKED_REASON_UNSPECIFIED = "BLOCKED_REASON_UNSPECIFIED"; + + /** + * Content was blocked by safety settings. + */ + export const SAFETY = "SAFETY"; + + /** + * Content was blocked, but the reason is uncategorized. + */ + export const OTHER = "OTHER"; +} +export type BlockReason = string; + +/** + * Metadata on the generation request's token usage. + */ +@json +export class UsageMetadata { + /** + * Number of tokens in the prompt. + */ + promptTokenCount!: i32; + + /** + * Total number of tokens across the generated candidates. + * + * @remarks + * This value will be zero if the prompt was blocked due to safety reasons. + */ + candidatesTokenCount: i32 = 0; // TODO: make this an `i32 | null` when supported + + /** + * Total token count for the generation request (prompt + candidates). + */ + totalTokenCount!: i32; + + /** + * Total token count in the cached part of the prompt, i.e. in the cached content. + */ + cachedContentTokenCount: i32 = 0; // TODO: make this an `i32 | null` when supported +} diff --git a/sdk/assemblyscript/src/models/meta/llama.ts b/sdk/assemblyscript/src/models/meta/llama.ts new file mode 100644 index 00000000..91c3cddc --- /dev/null +++ b/sdk/assemblyscript/src/models/meta/llama.ts @@ -0,0 +1,97 @@ +/* + * Copyright 2024 Hypermode, Inc. + * Licensed under the terms of the Apache License, Version 2.0 + * See the LICENSE file that accompanied this code for further details. + * + * SPDX-FileCopyrightText: 2024 Hypermode, Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Model } from "../../assembly/models"; + +export class TextGenerationModel extends Model< + TextGenerationInput, + TextGenerationOutput +> { + /** + * Creates a new input object for the model. + * @param prompt The prompt text to pass to the model. + * @returns A new input object. + * @remarks Optional properties may be set on the returned input object to + * control the behavior of the model. + */ + createInput(prompt: string): TextGenerationInput { + return { prompt }; + } +} + + +@json +export class TextGenerationInput { + /** + * The prompt text to pass to the model. + * May contain special tokens to control the behavior of the model. + * See https://llama.meta.com/docs/model-cards-and-prompt-formats/meta-llama-2/ + */ + prompt!: string; + + /** + * The temperature of the generated text, which controls the randomness of the output. + * Higher values may lead to mode creative but less coherent outputs, + * while lower values may lead to more conservative but more coherent outputs. + * + * Default: 0.6 + */ + @omitif("this.temperature == 0.6") + temperature: f64 = 0.6; + + /** + * The maximum probability threshold for generating tokens. + * Use a lower value to ignore less probable options. + * + * Default: 0.9 + */ + @omitif("this.topP == 0.9") + @alias("top_p") + topP: f64 = 0.9; + + /** + * The maximum number of tokens in the generated text. + * + * Default: 512 + */ + @omitif("this.maxGenLen == 512") + @alias("max_gen_len") + maxGenLen: i32 = 512; +} + + +@json +export class TextGenerationOutput { + /** + * The generated text. + */ + generation!: string; + + /** + * The number of tokens in the prompt text. + */ + @alias("prompt_token_count") + promptTokenCount!: i32; + + /** + * The number of tokens in the generated text. + */ + @alias("generation_token_count") + generationTokenCount!: i32; + + /** + * The reason why the response stopped generating text. + * Possible values are: + * - `"stop"` - The model has finished generating text. + * - `"length"` - The response has been truncated due to reaching the maximum + * token length specified by `maxGenLen` in the input. + */ + @alias("stop_reason") + stopReason!: string; +} diff --git a/sdk/assemblyscript/src/models/openai/chat.ts b/sdk/assemblyscript/src/models/openai/chat.ts new file mode 100644 index 00000000..97805d61 --- /dev/null +++ b/sdk/assemblyscript/src/models/openai/chat.ts @@ -0,0 +1,746 @@ +/* + * Copyright 2024 Hypermode, Inc. + * Licensed under the terms of the Apache License, Version 2.0 + * See the LICENSE file that accompanied this code for further details. + * + * SPDX-FileCopyrightText: 2024 Hypermode, Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Model } from "../../assembly/models"; +import { JSON } from "json-as"; + +/** + * Provides input and output types that conform to the OpenAI Chat API. + * + * Reference: https://platform.openai.com/docs/api-reference/chat + */ +export class OpenAIChatModel extends Model { + /** + * Creates an input object for the OpenAI Chat API. + * + * @param messages: An array of messages to send to the chat model. + * @returns An input object that can be passed to the `invoke` method. + */ + createInput(messages: Message[]): OpenAIChatInput { + const model = this.info.fullName; + return { model, messages }; + } +} + +/** + * The input object for the OpenAI Chat API. + */ +@json +export class OpenAIChatInput { + /** + * The name of the model to use for the chat. + * Must be the exact string expected by the model provider. + * For example, "gpt-3.5-turbo". + * + * @remarks + * This field is automatically set by the `createInput` method when creating this object. + * It does not need to be set manually. + */ + model!: string; + + /** + * An array of messages to send to the chat model. + */ + messages!: Message[]; + + /** + * Number between `-2.0` and `2.0`. + * + * Positive values penalize new tokens based on their existing frequency in the text so far, + * decreasing the model's likelihood to repeat the same line verbatim. + * + * @default 0.0 + */ + @alias("frequency_penalty") + @omitif("this.frequencyPenalty == 0.0") + frequencyPenalty: f64 = 0.0; + + /** + * Modifies the likelihood of specified tokens appearing in the completion. + * + * Accepts an object that maps tokens (specified by their token ID in the tokenizer) to an associated bias value from -100 to 100. + * Mathematically, the bias is added to the logits generated by the model prior to sampling. The exact effect will vary per model, + * but values between -1 and 1 should decrease or increase likelihood of selection; values like -100 or 100 should result in a ban + * or exclusive selection of the relevant token. + */ + @alias("logit_bias") + @omitnull() + logitBias: Map | null = null; + + /** + * Whether to return log probabilities of the output tokens or not, + * + * If true, returns the log probabilities of each output token returned in the content of message. + * + * @default false + */ + @omitif("this.logprobs == false") + logprobs: bool = false; + + /** + * An integer between 0 and 20 specifying the number of most likely tokens to return at each token position, + * each with an associated log probability. `logprobs` must be set to `true` if this parameter is used. + */ + @alias("top_logprobs") + @omitif("this.logprobs == false") + topLogprobs: i32 = 0; + + /** + * The maximum number of tokens to generate in the chat completion. + * + * @default 4096 + */ + @alias("max_tokens") + @omitif("this.maxTokens == 4096") + maxTokens: i32 = 4096; // TODO: make this an `i32 | null` when supported + + /** + * The number of completions to generate for each prompt. + */ + @omitif("this.n == 1") + n: i32 = 1; + + /** + * + * Number between `-2.0` and `2.0`. + * + * Positive values penalize new tokens based on whether they appear in the text so far, + * increasing the model's likelihood to talk about new topics. + * + * @default 0.0 + */ + @alias("presence_penalty") + @omitif("this.presencePenalty == 0.0") + presencePenalty: f64 = 0.0; + + /** + * Specifies the format for the response. + * + * If set to `ResponseFormat.Json`, the response will be a JSON object. + * + * If set to `ResponseFormat.JsonSchema`, the response will be a JSON object + * that conforms to the provided JSON schema. + * + * @default ResponseFormat.Text + */ + @alias("response_format") + @omitif("this.responseFormat.type == 'text'") + responseFormat: ResponseFormat = ResponseFormat.Text; + + /** + * If specified, the model will make a best effort to sample deterministically, such that + * repeated requests with the same seed and parameters should return the same result. + * Determinism is not guaranteed, and you should use the `systemFingerprint` response + * parameter to monitor changes in the backend. + */ + @omitif("this.seed == -1") + seed: i32 = -1; // TODO: make this an `i32 | null` when supported + + /** + * Specifies the latency tier to use for processing the request. + */ + @alias("service_tier") + @omitnull() + serviceTier: ServiceTier | null = null; + + /** + * Up to 4 sequences where the API will stop generating further tokens. + */ + @omitnull() + stop: string[] | null = null; + + // stream: bool = false; + + // @omitif("this.stream == false") + // @alias("stream_options") + // streamOptions: StreamOptions | null = null; + + /** + * A number between `0.0` and `2.0` that controls the sampling temperature. + * + * Higher values like `0.8` will make the output more random, while lower values like `0.2` will make + * it more focused and deterministic. + * + * We generally recommend altering this or `topP` but not both. + * + * @default 1.0 + */ + @omitif("this.temperature == 1.0") + temperature: f64 = 1.0; + + /** + * An alternative to sampling with temperature, called nucleus sampling, where the model + * considers the results of the tokens with `topP` probability mass. + * + * For example, `0.1` means only the tokens comprising the top 10% probability mass are considered. + * + * We generally recommend altering this or `temperature` but not both. + */ + @alias("top_p") + @omitif("this.topP == 1.0") + topP: f64 = 1.0; + + /** + * A list of tools the model may call. Currently, only functions are supported as a tool. + * Use this to provide a list of functions the model may generate JSON inputs for. + * A max of 128 functions are supported. + */ + @omitnull() + tools: Tool[] | null = null; + + /** + * Controls which (if any) tool is called by the model. + * - `"none"` means the model will not call any tool and instead generates a message. + * - `"auto"` means the model can pick between generating a message or calling one or more tools. + * - `"required"` means the model must call one or more tools. + * - Specifying a particular tool via `{"type": "function", "function": {"name": "my_function"}}` forces the model to call that tool. + * + * `none` is the default when no tools are present. `auto` is the default if tools are present. + */ + @alias("tool_choice") + @omitnull() + toolChoice: string | null = null; // TODO: Make this work with a custom tool object + + /** + * Whether to enable parallel function calling during tool use. + * + * @default true + */ + @alias("parallel_tool_calls") + @omitif("this.parallelToolCalls == true || !this.tools || this.tools!.length == 0") + parallelToolCalls: bool = true; + + /** + * The user ID to associate with the request. + * If not specified, the request will be anonymous. + * See https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids + */ + @omitnull() + user: string | null = null; +} + +/** + * The OpenAI service tier used to process the request. + */ +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace ServiceTier { + /** + * The OpenAI system will utilize scale tier credits until they are exhausted. + */ + export const Auto = "auto"; + + /** + * The request will be processed using the default OpenAI service tier with a lower + * uptime SLA and no latency guarantee. + */ + export const Default = "default"; +} +export type ServiceTier = string; + +/** + * The output object for the OpenAI Chat API. + */ +@json +export class OpenAIChatOutput { + /** + * A unique identifier for the chat completion. + */ + id!: string; + + /** + * The name of the output object type returned by the API. + * Always `"chat.completion"`. + */ + object!: string; + + /** + * A list of chat completion choices. Can be more than one if `n` is greater than 1 in the input options. + */ + choices!: Choice[]; + + /** + * The Unix timestamp (in seconds) of when the chat completion was created. + */ + created!: i32; + + /** + * The model used for the chat completion. + * In most cases, this will match the requested `model` field in the input. + */ + model!: string; + + /** + * The service tier used for processing the request. + * + * This field is only included if the `serviceTier` parameter is specified in the request. + */ + @alias("service_tier") + serviceTier: string | null = null; + + /** + * This fingerprint represents the OpenAI backend configuration that the model runs with. + * + * Can be used in conjunction with the seed request parameter to understand when backend changes + * have been made that might impact determinism. + */ + @alias("system_fingerprint") + systemFingerprint!: string; + + /** + * The usage statistics for the request. + */ + usage!: Usage; +} + +type JsonSchemaFunction = (jsonSchema: string) => ResponseFormat; + +/** + * An object specifying the format that the model must output. + */ +@json +export class ResponseFormat { + /** + * The type of response format. Must be one of `"text"` or `"json_object"`. + */ + readonly type!: string; + + /** + * The JSON schema to use for the response format. + */ + @omitnull() + @alias("json_schema") + readonly jsonSchema: JSON.Raw | null = null; + + /** + * Instructs the model to output the response as a JSON object. + * + * @remarks + * You must also instruct the model to produce JSON yourself via a system or user message. + * + * Additionally, if you need an array you must ask for an object that wraps the array, + * because the model will not reliably produce arrays directly (ie., there is no `json_array` option). + */ + static Json: ResponseFormat = { type: "json_object", jsonSchema: null }; + + /** + * Enables Structured Outputs which guarantees the model will match your supplied JSON schema. + * + * See https://platform.openai.com/docs/guides/structured-outputs + */ + static JsonSchema: JsonSchemaFunction = ( + jsonSchema: string, + ): ResponseFormat => { + return { + type: "json_schema", + jsonSchema: jsonSchema, + }; + }; + + /** + * Instructs the model to output the response as a plain text string. + * + * @remarks + * This is the default response format. + */ + static Text: ResponseFormat = { type: "text", jsonSchema: null }; +} + +// @json +// export class StreamOptions { + +// @omitif("this.includeUsage == false") +// @alias("include_usage") +// includeUsage: bool = false; +// } + +/** + * A tool object that the model may call. + */ +@json +export class Tool { + /** + * The type of the tool. Currently, only `"function"` is supported. + * + * @default "function" + */ + type: string = "function"; + + /** + * The definition of the function. + */ + function!: FunctionDefinition; +} + +/** + * The definition of a function that can be called by the model. + */ +@json +export class FunctionDefinition { + /** + * The name of the function to be called. + * + * Must be a-z, A-Z, 0-9, or contain underscores and dashes, with a maximum length of 64. + */ + name!: string; + + /** + * An optional description of what the function does, used by the model to choose when and how to call the function. + */ + @omitnull() + description: string | null = null; + + /** + * Whether to enable strict schema adherence when generating the function call. + * If set to true, the model will follow the exact schema defined in the parameters field. + * + * See https://platform.openai.com/docs/guides/function-calling + * + * @remarks + * In order to guarantee strict schema adherence, disable parallel function calls + * by setting {@link OpenAIChatInput.parallelToolCalls}=false. + * + * See https://platform.openai.com/docs/guides/function-calling/parallel-function-calling-and-structured-outputs + * + * @default false + */ + @omitif("this.strict == false") + strict: bool = false; + + /** + * The parameters the functions accepts, described as a JSON Schema object. + * + * See https://platform.openai.com/docs/guides/function-calling + */ + @omitnull() + parameters: JSON.Raw | null = null; +} + +/** + * A tool call object that the model may generate. + */ +@json +export class ToolCall { + /** + * The ID of the tool call. + */ + id!: string; + + /** + * The type of the tool. Currently, only `"function"` is supported. + * + * @default "function" + */ + type: string = "function"; + + /** + * The function that the model called. + */ + function!: FunctionCall; +} + +/** + * A function call object that the model may generate. + */ +@json +export class FunctionCall { + /** + * The name of the function to call. + */ + name!: string; + + /** + * The arguments to call the function with, as generated by the model in JSON format. + * + * @remarks + * Note that the model does not always generate valid JSON, and may hallucinate parameters not + * defined by your function schema. Validate the arguments in your code before calling your function. + */ + arguments!: string; +} + +/** + * The usage statistics for the request. + */ +@json +export class Usage { + /** + * The number of completion tokens used in the response. + */ + @alias("completion_tokens") + completionTokens!: i32; + + /** + * The number of prompt tokens used in the request. + */ + @alias("prompt_tokens") + promptTokens!: i32; + + /** + * The total number of tokens used in the request and response. + */ + @alias("total_tokens") + totalTokens!: i32; +} + +/** + * A completion choice object returned in the response. + */ +@json +export class Choice { + /** + * The reason the model stopped generating tokens. + * + * Possible values are: + * - `"stop"` if the model hit a natural stop point or a provided stop sequence + * - `"length"` if the maximum number of tokens specified in the request was reached + * - `"content_filter"` if content was omitted due to a flag from our content filters + * - `"tool_calls"` if the model called a tool + */ + @alias("finish_reason") + finishReason!: string; + + /** + * The index of the choice in the list of choices. + */ + index!: i32; + + /** + * A chat completion message generated by the model. + */ + message!: CompletionMessage; + + /** + * Log probability information for the choice. + */ + logprobs!: Logprobs | null; +} + +/** + * Log probability information for a choice. + */ +@json +export class Logprobs { + /** + * A list of message content tokens with log probability information. + */ + content: LogprobsContent[] | null = null; +} + +/** + * Log probability information for a message content token. + */ +@json +export class LogprobsContent { + /** + * The token. + */ + token!: string; + + /** + * The log probability of this token, if it is within the top 20 most likely tokens. + * Otherwise, the value `-9999.0` is used to signify that the token is very unlikely. + */ + logprob!: f64; + + /** + * A list of integers representing the UTF-8 bytes representation of the token. + * + * Useful in instances where characters are represented by multiple tokens and their byte + * representations must be combined to generate the correct text representation. + * Can be null if there is no bytes representation for the token. + */ + bytes!: u8[] | null; // TODO: verify this works + + /** + * List of the most likely tokens and their log probability, at this token position. + * In rare cases, there may be fewer than the number of requested `topLogprobs` returned. + */ + @alias("top_logprobs") + topLogprobs!: TopLogprobsContent[]; // TODO: verify this works +} + +/** + * Log probability information for the most likely tokens at a given position. + */ +@json +export class TopLogprobsContent { + /** + * The token. + */ + token!: string; + + /** + * The log probability of this token, if it is within the top 20 most likely tokens. + * Otherwise, the value `-9999.0` is used to signify that the token is very unlikely. + */ + logprob!: f64; + + /** + * A list of integers representing the UTF-8 bytes representation of the token. + * Useful in instances where characters are represented by multiple tokens and their byte + * representations must be combined to generate the correct text representation. + * Can be null if there is no bytes representation for the token. + */ + bytes!: u8[] | null; // TODO: verify this works +} + +/** + * A message object that can be sent to the chat model. + */ +@json +abstract class Message { + /** + * Creates a new message object. + * + * @param role The role of the author of this message. + * @param content The contents of the message. + */ + constructor(role: string, content: string) { + this._role = role; + this.content = content; + } + + + @alias("role") + protected _role: string; + + /** + * The role of the author of this message. + */ + get role(): string { + return this._role; + } + + /** + * The contents of the message. + */ + content: string; +} + +/** + * A system message. + */ +@json +export class SystemMessage extends Message { + /** + * Creates a new system message object. + * + * @param content The contents of the message. + */ + constructor(content: string) { + super("system", content); + } + + /** + * An optional name for the participant. + * Provides the model information to differentiate between participants of the same role. + */ + @omitnull() + name: string | null = null; +} + +/** + * A user message. + */ +@json +export class UserMessage extends Message { + /** + * Creates a new user message object. + * + * @param content The contents of the message. + */ + constructor(content: string) { + super("user", content); + } + + /** + * An optional name for the participant. + * Provides the model information to differentiate between participants of the same role. + */ + @omitnull() + name: string | null = null; +} + +/** + * An assistant message. + */ +@json +export class AssistantMessage extends Message { + /** + * Creates a new assistant message object. + * + * @param content The contents of the message. + */ + constructor(content: string) { + super("assistant", content); + } + + /** + * An optional name for the participant. + * Provides the model information to differentiate between participants of the same role. + */ + @omitnull() + name: string | null = null; + + /** + * The tool calls generated by the model, such as function calls. + */ + @alias("tool_calls") + @omitif("this.toolCalls.length == 0") + toolCalls: ToolCall[] = []; +} + +/** + * A tool message. + */ +@json +export class ToolMessage extends Message { + /** + * Creates a new tool message object. + * + * @param content The contents of the message. + */ + constructor(content: string, toolCallId: string) { + super("tool", content); + this.toolCallId = toolCallId; + } + + /** + * Tool call that this message is responding to. + */ + @alias("tool_call_id") + toolCallId!: string; +} + +/** + * A chat completion message generated by the model. + */ +@json +export class CompletionMessage extends Message { + /** + * Creates a new completion message object. + * + * @param role The role of the author of this message. + * @param content The contents of the message. + */ + constructor(role: string, content: string) { + super(role, content); + } + + /** + * The refusal message generated by the model. + */ + refusal: string | null = null; + + /** + * The tool calls generated by the model, such as function calls. + */ + @alias("tool_calls") + toolCalls: ToolCall[] = []; +} diff --git a/sdk/assemblyscript/src/models/openai/embeddings.ts b/sdk/assemblyscript/src/models/openai/embeddings.ts new file mode 100644 index 00000000..21e2ae84 --- /dev/null +++ b/sdk/assemblyscript/src/models/openai/embeddings.ts @@ -0,0 +1,207 @@ +/* + * Copyright 2024 Hypermode, Inc. + * Licensed under the terms of the Apache License, Version 2.0 + * See the LICENSE file that accompanied this code for further details. + * + * SPDX-FileCopyrightText: 2024 Hypermode, Inc. + * SPDX-License-Identifier: Apache-2.0 + */ + +import { Model } from "../../assembly/models"; + +/** + * Provides input and output types that conform to the OpenAI Embeddings API. + * + * Reference: https://platform.openai.com/docs/api-reference/embeddings + */ +export class OpenAIEmbeddingsModel extends Model< + OpenAIEmbeddingsInput, + OpenAIEmbeddingsOutput +> { + /** + * Creates an input object for the OpenAI Embeddings API. + * + * @param content The input content to vectorize. Can be any of: + * - A string representing the text to vectorize. + * - An array of strings representing multiple texts to vectorize. + * - An array of integers representing pre-tokenized text to vectorize. + * - An array of arrays of integers representing multiple pre-tokenized texts to vectorize. + * + * @returns An input object that can be passed to the `invoke` method. + * + * @remarks + * The input content must not exceed the maximum token limit of the model. + */ + createInput(content: T): OpenAIEmbeddingsInput { + const model = this.info.fullName; + + switch (idof()) { + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + case idof(): + return >{ model, input: content }; + } + + throw new Error("Unsupported input content type."); + } +} + +/** + * The input object for the OpenAI Embeddings API. + */ +@json +export class OpenAIEmbeddingsInput { + /** + * The name of the model to use for the embeddings. + * Must be the exact string expected by the model provider. + * For example, "text-embedding-3-small". + * + * @remarks + * This field is automatically set by the `createInput` method when creating this object. + * It does not need to be set manually. + */ + model!: string; + + /** + * The encoding format for the output embeddings. + * + * @default EncodingFormat.Float + * + * @remarks + * Currently only `EncodingFormat.Float` is supported. + */ + @alias("encoding_format") + @omitif("this.encodingFormat == 'float'") + encodingFormat: string = EncodingFormat.Float; + + /** + * The maximum number of dimensions for the output embeddings. + * If not specified, the model's default number of dimensions will be used. + */ + @omitif("this.dimensions == -1") + dimensions: i32 = -1; // TODO: make this an `i32 | null` when supported + + /** + * The user ID to associate with the request. + * If not specified, the request will be anonymous. + * See https://platform.openai.com/docs/guides/safety-best-practices/end-user-ids + */ + @omitnull() + user: string | null = null; +} + +/** + * The input object for the OpenAI Embeddings API. + */ +@json +export class TypedEmbeddingsInput extends OpenAIEmbeddingsInput { + /** + * The input content to vectorize. + */ + input!: T; +} + +/** + * The output object for the OpenAI Embeddings API. + */ +@json +export class OpenAIEmbeddingsOutput { + /** + * The name of the output object type returned by the API. + * Always `"list"`. + */ + object!: string; + + /** + * The name of the model used to generate the embeddings. + * In most cases, this will match the requested `model` field in the input. + */ + model!: string; + + /** + * The usage statistics for the request. + */ + usage!: Usage; + + /** + * The output vector embeddings data. + */ + data!: Embedding[]; +} + +/** + * The encoding format for the output embeddings. + */ +// eslint-disable-next-line @typescript-eslint/no-namespace +export namespace EncodingFormat { + /** + * The output embeddings are encoded as an array of floating-point numbers. + */ + export const Float = "float"; + + /** + * The output embeddings are encoded as a base64-encoded string, + * containing an binary representation of an array of floating-point numbers. + * + * @remarks + * This format is currently not supported through this interface. + */ + export const Base64 = "base64"; +} +export type EncodingFormat = string; + +/** + * The output vector embeddings data. + */ +@json +export class Embedding { + /** + * The name of the output object type returned by the API. + * Always `"embedding"`. + */ + object!: string; + + /** + * The index of the input text that corresponds to this embedding. + * Used when requesting embeddings for multiple texts. + */ + index!: i32; + + /** + * The vector embedding of the input text. + */ + embedding!: f32[]; // TODO: support `f32[] | string` based on input encoding format +} + +/** + * The usage statistics for the request. + */ +@json +export class Usage { + /** + * The number of prompt tokens used in the request. + */ + @alias("prompt_tokens") + promptTokens!: i32; + + /** + * The total number of tokens used in the request. + */ + @alias("total_tokens") + totalTokens!: i32; +} diff --git a/sdk/assemblyscript/src/models/tsconfig.json b/sdk/assemblyscript/src/models/tsconfig.json new file mode 100644 index 00000000..798b474e --- /dev/null +++ b/sdk/assemblyscript/src/models/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "assemblyscript/std/assembly.json", + "include": ["./**/*.ts"] +} diff --git a/sdk/assemblyscript/src/package-lock.json b/sdk/assemblyscript/src/package-lock.json index 81e13e27..13cbc242 100644 --- a/sdk/assemblyscript/src/package-lock.json +++ b/sdk/assemblyscript/src/package-lock.json @@ -10,7 +10,6 @@ "license": "Apache-2.0", "dependencies": { "@assemblyscript/wasi-shim": "^0.1.0", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21", "semver": "^7.6.3", "xid-ts": "^1.1.4" @@ -187,14 +186,6 @@ "url": "https://github.com/sponsors/nzakas" } }, - "node_modules/@hypermode/models-as": { - "version": "0.2.4", - "resolved": "https://registry.npmjs.org/@hypermode/models-as/-/models-as-0.2.4.tgz", - "integrity": "sha512-OgfGzAUlhfbv46PTeOxoLalsiwJ/V6Cg0xyBsV+zcdPW4uKNk9No8tqNF8rjXm37cwCjgtE3JZzuSnn3EyI4OA==", - "dependencies": { - "json-as": "^0.9.21" - } - }, "node_modules/@isaacs/cliui": { "version": "8.0.2", "resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz", diff --git a/sdk/assemblyscript/src/package.json b/sdk/assemblyscript/src/package.json index eadb97da..6397f742 100644 --- a/sdk/assemblyscript/src/package.json +++ b/sdk/assemblyscript/src/package.json @@ -16,7 +16,6 @@ }, "dependencies": { "@assemblyscript/wasi-shim": "^0.1.0", - "@hypermode/models-as": "^0.2.4", "json-as": "^0.9.21", "semver": "^7.6.3", "xid-ts": "^1.1.4" @@ -45,6 +44,8 @@ "index.ts", "assembly/**/*.ts", "!assembly/**/__tests__", + "models/**/*.ts", + "!models/**/__tests__", "bin/build-plugin.js", "plugin.asconfig.json", "transform/lib/*.js",