From ac772f0ae5a92a97386099f3a33c359023d75eee Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Fri, 14 Jun 2024 16:04:57 -0700 Subject: [PATCH 1/5] fix usage warning --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index b414208..6acdad7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -16,7 +16,7 @@ export interface ModelFactory { export abstract class Model { protected constructor( public readonly info: ModelInfo, - private invoker: ModelInvoker, + protected invoker: ModelInvoker, ) {} debug: boolean = false; From 4e38aaef995e3335c2437ec6835384eb08be7436 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Mon, 17 Jun 2024 15:24:54 -0700 Subject: [PATCH 2/5] bump deps --- src/package-lock.json | 104 +++++++++++++++++++++--------------------- src/package.json | 8 ++-- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/package-lock.json b/src/package-lock.json index 3a398b6..272e3c2 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -9,12 +9,12 @@ "version": "0.1.1", "license": "MIT", "dependencies": { - "json-as": "^0.8.6" + "json-as": "^0.9.4" }, "devDependencies": { - "@types/node": "^20.14.2", - "@typescript-eslint/eslint-plugin": "^7.13.0", - "@typescript-eslint/parser": "^7.13.0", + "@types/node": "^20.14.4", + "@typescript-eslint/eslint-plugin": "^7.13.1", + "@typescript-eslint/parser": "^7.13.1", "assemblyscript": "^0.27.27", "assemblyscript-prettier": "^3.0.1", "eslint": "^8.57.0", @@ -208,9 +208,9 @@ } }, "node_modules/@types/node": { - "version": "20.14.2", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.2.tgz", - "integrity": "sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q==", + "version": "20.14.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.4.tgz", + "integrity": "sha512-1ChboN+57suCT2t/f8lwtPY/k3qTpuD/qnqQuYoBg6OQOcPyaw7PiZVdGpaZYAvhDDtqrt0oAaM8+oSu1xsUGw==", "dev": true, "license": "MIT", "dependencies": { @@ -218,17 +218,17 @@ } }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "7.13.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.13.0.tgz", - "integrity": "sha512-FX1X6AF0w8MdVFLSdqwqN/me2hyhuQg4ykN6ZpVhh1ij/80pTvDKclX1sZB9iqex8SjQfVhwMKs3JtnnMLzG9w==", + "version": "7.13.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-7.13.1.tgz", + "integrity": "sha512-kZqi+WZQaZfPKnsflLJQCz6Ze9FFSMfXrrIOcyargekQxG37ES7DJNpJUE9Q/X5n3yTIP/WPutVNzgknQ7biLg==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "7.13.0", - "@typescript-eslint/type-utils": "7.13.0", - "@typescript-eslint/utils": "7.13.0", - "@typescript-eslint/visitor-keys": "7.13.0", + "@typescript-eslint/scope-manager": "7.13.1", + "@typescript-eslint/type-utils": "7.13.1", + "@typescript-eslint/utils": "7.13.1", + "@typescript-eslint/visitor-keys": "7.13.1", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -252,16 +252,16 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "7.13.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.13.0.tgz", - "integrity": "sha512-EjMfl69KOS9awXXe83iRN7oIEXy9yYdqWfqdrFAYAAr6syP8eLEFI7ZE4939antx2mNgPRW/o1ybm2SFYkbTVA==", + "version": "7.13.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-7.13.1.tgz", + "integrity": "sha512-1ELDPlnLvDQ5ybTSrMhRTFDfOQEOXNM+eP+3HT/Yq7ruWpciQw+Avi73pdEbA4SooCawEWo3dtYbF68gN7Ed1A==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/scope-manager": "7.13.0", - "@typescript-eslint/types": "7.13.0", - "@typescript-eslint/typescript-estree": "7.13.0", - "@typescript-eslint/visitor-keys": "7.13.0", + "@typescript-eslint/scope-manager": "7.13.1", + "@typescript-eslint/types": "7.13.1", + "@typescript-eslint/typescript-estree": "7.13.1", + "@typescript-eslint/visitor-keys": "7.13.1", "debug": "^4.3.4" }, "engines": { @@ -281,14 +281,14 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "7.13.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.13.0.tgz", - "integrity": "sha512-ZrMCe1R6a01T94ilV13egvcnvVJ1pxShkE0+NDjDzH4nvG1wXpwsVI5bZCvE7AEDH1mXEx5tJSVR68bLgG7Dng==", + "version": "7.13.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-7.13.1.tgz", + "integrity": "sha512-adbXNVEs6GmbzaCpymHQ0MB6E4TqoiVbC0iqG3uijR8ZYfpAXMGttouQzF4Oat3P2GxDVIrg7bMI/P65LiQZdg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "7.13.0", - "@typescript-eslint/visitor-keys": "7.13.0" + "@typescript-eslint/types": "7.13.1", + "@typescript-eslint/visitor-keys": "7.13.1" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -299,14 +299,14 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "7.13.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.13.0.tgz", - "integrity": "sha512-xMEtMzxq9eRkZy48XuxlBFzpVMDurUAfDu5Rz16GouAtXm0TaAoTFzqWUFPPuQYXI/CDaH/Bgx/fk/84t/Bc9A==", + "version": "7.13.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-7.13.1.tgz", + "integrity": "sha512-aWDbLu1s9bmgPGXSzNCxELu+0+HQOapV/y+60gPXafR8e2g1Bifxzevaa+4L2ytCWm+CHqpELq4CSoN9ELiwCg==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/typescript-estree": "7.13.0", - "@typescript-eslint/utils": "7.13.0", + "@typescript-eslint/typescript-estree": "7.13.1", + "@typescript-eslint/utils": "7.13.1", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -327,9 +327,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "7.13.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.13.0.tgz", - "integrity": "sha512-QWuwm9wcGMAuTsxP+qz6LBBd3Uq8I5Nv8xb0mk54jmNoCyDspnMvVsOxI6IsMmway5d1S9Su2+sCKv1st2l6eA==", + "version": "7.13.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-7.13.1.tgz", + "integrity": "sha512-7K7HMcSQIAND6RBL4kDl24sG/xKM13cA85dc7JnmQXw2cBDngg7c19B++JzvJHRG3zG36n9j1i451GBzRuHchw==", "dev": true, "license": "MIT", "engines": { @@ -341,14 +341,14 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "7.13.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.13.0.tgz", - "integrity": "sha512-cAvBvUoobaoIcoqox1YatXOnSl3gx92rCZoMRPzMNisDiM12siGilSM4+dJAekuuHTibI2hVC2fYK79iSFvWjw==", + "version": "7.13.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-7.13.1.tgz", + "integrity": "sha512-uxNr51CMV7npU1BxZzYjoVz9iyjckBduFBP0S5sLlh1tXYzHzgZ3BR9SVsNed+LmwKrmnqN3Kdl5t7eZ5TS1Yw==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/types": "7.13.0", - "@typescript-eslint/visitor-keys": "7.13.0", + "@typescript-eslint/types": "7.13.1", + "@typescript-eslint/visitor-keys": "7.13.1", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -370,16 +370,16 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "7.13.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.13.0.tgz", - "integrity": "sha512-jceD8RgdKORVnB4Y6BqasfIkFhl4pajB1wVxrF4akxD2QPM8GNYjgGwEzYS+437ewlqqrg7Dw+6dhdpjMpeBFQ==", + "version": "7.13.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-7.13.1.tgz", + "integrity": "sha512-h5MzFBD5a/Gh/fvNdp9pTfqJAbuQC4sCN2WzuXme71lqFJsZtLbjxfSk4r3p02WIArOF9N94pdsLiGutpDbrXQ==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "7.13.0", - "@typescript-eslint/types": "7.13.0", - "@typescript-eslint/typescript-estree": "7.13.0" + "@typescript-eslint/scope-manager": "7.13.1", + "@typescript-eslint/types": "7.13.1", + "@typescript-eslint/typescript-estree": "7.13.1" }, "engines": { "node": "^18.18.0 || >=20.0.0" @@ -393,13 +393,13 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "7.13.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.13.0.tgz", - "integrity": "sha512-nxn+dozQx+MK61nn/JP+M4eCkHDSxSLDpgE3WcQo0+fkjEolnaB5jswvIKC4K56By8MMgIho7f1PVxERHEo8rw==", + "version": "7.13.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-7.13.1.tgz", + "integrity": "sha512-k/Bfne7lrP7hcb7m9zSsgcBmo+8eicqqfNAJ7uUY+jkTFpKeH2FSkWpFRtimBxgkyvqfu9jTPRbYOvud6isdXA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "7.13.0", + "@typescript-eslint/types": "7.13.1", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -1274,9 +1274,9 @@ } }, "node_modules/json-as": { - "version": "0.8.6", - "resolved": "https://registry.npmjs.org/json-as/-/json-as-0.8.6.tgz", - "integrity": "sha512-Rag2Mco5ZupujZ9Z2YBi5YW2D1p1tIFryAiPyiSfayp5VLfqloFcD1QOiaUFxMV37wvJRZzwOxgl6wWbyzkh3w==", + "version": "0.9.4", + "resolved": "https://registry.npmjs.org/json-as/-/json-as-0.9.4.tgz", + "integrity": "sha512-86PO80sYhAlwlO79ktQ9vc6CQU5cEWZ3qKu5hUVGv4SlZyX82rk2tZ2pO2LdTNNdqkrN1USqk1KI5Rb+lvI0FA==", "license": "MIT", "dependencies": { "as-container": "^0.8.0", diff --git a/src/package.json b/src/package.json index 07a6442..af5bfd4 100644 --- a/src/package.json +++ b/src/package.json @@ -14,12 +14,12 @@ "lint:fix": "eslint --ext .ts --fix ." }, "dependencies": { - "json-as": "^0.8.6" + "json-as": "^0.9.4" }, "devDependencies": { - "@types/node": "^20.14.2", - "@typescript-eslint/eslint-plugin": "^7.13.0", - "@typescript-eslint/parser": "^7.13.0", + "@types/node": "^20.14.4", + "@typescript-eslint/eslint-plugin": "^7.13.1", + "@typescript-eslint/parser": "^7.13.1", "assemblyscript": "^0.27.27", "assemblyscript-prettier": "^3.0.1", "eslint": "^8.57.0", From 009b560ac9bb8b0859bfa0550f05558b34aea55b Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Mon, 17 Jun 2024 18:08:48 -0700 Subject: [PATCH 3/5] remove true --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 6acdad7..a9f0233 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,6 +42,6 @@ export abstract class Model { console.debug(`Received output: ${outputJson}`); } - return JSON.parse(outputJson, true); + return JSON.parse(outputJson); } } From 8d2a2e8f840b5b10467f4d7cc79c348019e23731 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Mon, 17 Jun 2024 18:09:16 -0700 Subject: [PATCH 4/5] Omit default values --- src/models/meta/llama.ts | 3 ++ src/models/openai/chat.ts | 57 ++++++++++++++++++++++++++++----- src/models/openai/embeddings.ts | 14 ++++++-- 3 files changed, 63 insertions(+), 11 deletions(-) diff --git a/src/models/meta/llama.ts b/src/models/meta/llama.ts index 4853c85..6f252dc 100644 --- a/src/models/meta/llama.ts +++ b/src/models/meta/llama.ts @@ -30,6 +30,7 @@ class LlamaInput { * * Default: 0.6 */ + @omitif("this.temperature == 0.6") temperature: f64 = 0.6; /** @@ -38,6 +39,7 @@ class LlamaInput { * * Default: 0.9 */ + @omitif("this.topP == 0.9") @alias("top_p") topP: f64 = 0.9; @@ -46,6 +48,7 @@ class LlamaInput { * * Default: 512 */ + @omitif("this.maxGenLen == 512") @alias("max_gen_len") maxGenLen: i32 = 512; } diff --git a/src/models/openai/chat.ts b/src/models/openai/chat.ts index 5e528d2..57a1605 100644 --- a/src/models/openai/chat.ts +++ b/src/models/openai/chat.ts @@ -20,53 +20,80 @@ class ChatCompletionInput { @alias("frequency_penalty") + @omitif("this.frequencyPenalty == 0.0") frequencyPenalty: f64 = 0.0; @alias("logit_bias") + @omitnull() logitBias: Map | null = null; + + @omitif("this.logprobs == false") logprobs: bool = false; - // @alias("top_logprobs") - // topLogprobs: i32 = 0; // TODO: only send when logprobs is true + + @alias("top_logprobs") + @omitif("this.logprobs == false") + topLogprobs: i32 = 0; + @alias("max_tokens") - maxTokens: i32 = 4096; + @omitif("this.maxTokens == 4096") + maxTokens: i32 = 4096; // TODO: make this an `i32 | null` when supported + + @omitif("this.n == 1") n: i32 = 1; @alias("presence_penalty") + @omitif("this.presencePenalty == 0.0") presencePenalty: f64 = 0.0; @alias("response_format") + @omitif("this.responseFormat.type == 'text'") responseFormat: ResponseFormat = ResponseFormat.Text; - // seed: i32 | null = null; // TODO: we need a true Nullable type for this to work + + @omitif("this.seed == -1") + seed: i32 = -1; // TODO: make this an `i32 | null` when supported + + + @omitnull() stop: string[] | null = null; // stream: bool = false; + + // @omitif("this.stream == false") // @alias("stream_options") // streamOptions: StreamOptions | null = null; + @omitif("this.temperature == 1.0") temperature: f64 = 1.0; @alias("top_p") + @omitif("this.topP == 1.0") topP: f64 = 1.0; + + @omitnull() tools: Tool[] | null = null; @alias("tool_choice") + @omitnull() toolChoice: string | null = null; // TODO: verify this works - // @alias("parallel_tool_calls") - // parallelToolCalls: bool = true; // TODO: omit this when no tools - @alias("user") + @alias("parallel_tool_calls") + @omitif("this.parallelToolCalls == true || !this.tools || this.tools!.length == 0") + parallelToolCalls: bool = true; + + + @omitnull() user: string | null = null; } @@ -98,6 +125,7 @@ export class ResponseFormat { // @json // export class StreamOptions { +// @omitif("this.includeUsage == false") // @alias("include_usage") // includeUsage: bool = false; // } @@ -111,8 +139,14 @@ export class Tool { @json export class FunctionDefinition { - description: string | null = null; name!: string; + + + @omitnull() + description: string | null = null; + + + @omitnull() parameters: string | null = null; // TODO: verify this works } @@ -212,6 +246,8 @@ export class SystemMessage extends Message { super("system", content); } + + @omitnull() name: string | null = null; } @@ -222,6 +258,8 @@ export class UserMessage extends Message { super("user", content); } + + @omitnull() name: string | null = null; } @@ -232,10 +270,13 @@ export class AssistantMessage extends Message { super("assistant", content); } + + @omitnull() name: string | null = null; @alias("tool_calls") + @omitif("this.toolCalls.length == 0") toolCalls: ToolCall[] = []; } diff --git a/src/models/openai/embeddings.ts b/src/models/openai/embeddings.ts index 42b5334..3b3ca73 100644 --- a/src/models/openai/embeddings.ts +++ b/src/models/openai/embeddings.ts @@ -1,4 +1,3 @@ -// import { Box } from "as-container/assembly"; import { Model } from "../.."; // Reference: https://platform.openai.com/docs/api-reference/embeddings @@ -18,9 +17,18 @@ export default class EmbeddingsModel extends Model< class EmbeddingsInput { input!: string; // todo: support other types of input (arrays, etc.) model!: string; + + + @omitif("this.encodingFormat.type == 'float'") encodingFormat: EncodingFormat = EncodingFormat.Float; - // dimensions: Box | null = null; - user: string = ""; + + + @omitif("this.dimensions == -1") + dimensions: i32 = -1; // TODO: make this an `i32 | null` when supported + + + @omitnull() + user: string | null = null; } From ae62a381676d6966372b22a1948bc2de98b15fd1 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Mon, 17 Jun 2024 18:15:24 -0700 Subject: [PATCH 5/5] bump deps --- src/package-lock.json | 8 ++++---- src/package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/package-lock.json b/src/package-lock.json index 272e3c2..ef6867e 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -9,7 +9,7 @@ "version": "0.1.1", "license": "MIT", "dependencies": { - "json-as": "^0.9.4" + "json-as": "^0.9.6" }, "devDependencies": { "@types/node": "^20.14.4", @@ -1274,9 +1274,9 @@ } }, "node_modules/json-as": { - "version": "0.9.4", - "resolved": "https://registry.npmjs.org/json-as/-/json-as-0.9.4.tgz", - "integrity": "sha512-86PO80sYhAlwlO79ktQ9vc6CQU5cEWZ3qKu5hUVGv4SlZyX82rk2tZ2pO2LdTNNdqkrN1USqk1KI5Rb+lvI0FA==", + "version": "0.9.6", + "resolved": "https://registry.npmjs.org/json-as/-/json-as-0.9.6.tgz", + "integrity": "sha512-llNc2CTe9l6RcGazC3W05HggOevrACv4idd1uWmVPSQ6EnsKCduYFY2nBvUT79ghIV9z1LfZkYZ/NVufcqbFBg==", "license": "MIT", "dependencies": { "as-container": "^0.8.0", diff --git a/src/package.json b/src/package.json index af5bfd4..19cfa53 100644 --- a/src/package.json +++ b/src/package.json @@ -14,7 +14,7 @@ "lint:fix": "eslint --ext .ts --fix ." }, "dependencies": { - "json-as": "^0.9.4" + "json-as": "^0.9.6" }, "devDependencies": { "@types/node": "^20.14.4",