diff --git a/package-lock.json b/package-lock.json index c684d84..9c1c327 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "llmatic", - "version": "0.4.202", + "version": "0.4.203", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "llmatic", - "version": "0.4.202", + "version": "0.4.203", "license": "MIT", "dependencies": { "@fastify/static": "^7.0.0", @@ -44,9 +44,9 @@ "earl": "^1.1.0", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", - "eslint-config-xo": "^0.43.1", - "eslint-config-xo-typescript": "^1.0.1", - "eslint-plugin-unicorn": "^50.0.1", + "eslint-config-xo": "^0.44.0", + "eslint-config-xo-typescript": "^2.0.0", + "eslint-plugin-unicorn": "^51.0.1", "http-status-codes": "^2.3.0", "jsonpath-plus": "^8.0.0", "nodemon": "^3.0.3", @@ -3644,45 +3644,45 @@ } }, "node_modules/eslint-config-xo": { - "version": "0.43.1", - "resolved": "https://registry.npmjs.org/eslint-config-xo/-/eslint-config-xo-0.43.1.tgz", - "integrity": "sha512-azv1L2PysRA0NkZOgbndUpN+581L7wPqkgJOgxxw3hxwXAbJgD6Hqb/SjHRiACifXt/AvxCzE/jIKFAlI7XjvQ==", + "version": "0.44.0", + "resolved": "https://registry.npmjs.org/eslint-config-xo/-/eslint-config-xo-0.44.0.tgz", + "integrity": "sha512-YG4gdaor0mJJi8UBeRJqDPO42MedTWYMaUyucF5bhm2pi/HS98JIxfFQmTLuyj6hGpQlAazNfyVnn7JuDn+Sew==", "dev": true, "dependencies": { "confusing-browser-globals": "1.0.11" }, "engines": { - "node": ">=12" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" }, "peerDependencies": { - "eslint": ">=8.27.0" + "eslint": ">=8.56.0" } }, "node_modules/eslint-config-xo-typescript": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/eslint-config-xo-typescript/-/eslint-config-xo-typescript-1.0.1.tgz", - "integrity": "sha512-vPQssnRSUgBFOEfB/KY12CXwltwFSn4RSCfa+w7gjBC2PFQ7Yfgmyei+1XUZ3K+8LRGef2NMJUcxts7PldhDjg==", + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-xo-typescript/-/eslint-config-xo-typescript-2.0.0.tgz", + "integrity": "sha512-Z6LxmerEsGzLH4niSgfD/ZfqnCkOWZmE1XPnbU9gyYRQbHFZUkjstvi2prvGF9ToXkTDBiBZWvAWwNw9F2lFHg==", "dev": true, "engines": { - "node": ">=16" + "node": ">=18" }, "funding": { "url": "https://github.com/sponsors/sindresorhus" }, "peerDependencies": { - "@typescript-eslint/eslint-plugin": ">=6.0.0", - "@typescript-eslint/parser": ">=6.0.0", - "eslint": ">=8.0.0", - "typescript": ">=4.7" + "@typescript-eslint/eslint-plugin": ">=6.21.0", + "@typescript-eslint/parser": ">=6.21.0", + "eslint": ">=8.56.0", + "typescript": ">=5.0.0" } }, "node_modules/eslint-plugin-unicorn": { - "version": "50.0.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-50.0.1.tgz", - "integrity": "sha512-KxenCZxqSYW0GWHH18okDlOQcpezcitm5aOSz6EnobyJ6BIByiPDviQRjJIUAjG/tMN11958MxaQ+qCoU6lfDA==", + "version": "51.0.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-unicorn/-/eslint-plugin-unicorn-51.0.1.tgz", + "integrity": "sha512-MuR/+9VuB0fydoI0nIn2RDA5WISRn4AsJyNSaNKLVwie9/ONvQhxOBbkfSICBPnzKrB77Fh6CZZXjgTt/4Latw==", "dev": true, "dependencies": { "@babel/helper-validator-identifier": "^7.22.20", diff --git a/package.json b/package.json index 57a7bee..efb191a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "llmatic", - "version": "0.4.202", + "version": "0.4.203", "description": "Use self-hosted LLMs with an OpenAI compatible API", "exports": { "./llm-adapter": { @@ -86,9 +86,9 @@ "earl": "^1.1.0", "eslint": "^8.56.0", "eslint-config-prettier": "^9.1.0", - "eslint-config-xo": "^0.43.1", - "eslint-config-xo-typescript": "^1.0.1", - "eslint-plugin-unicorn": "^50.0.1", + "eslint-config-xo": "^0.44.0", + "eslint-config-xo-typescript": "^2.0.0", + "eslint-plugin-unicorn": "^51.0.1", "http-status-codes": "^2.3.0", "jsonpath-plus": "^8.0.0", "nodemon": "^3.0.3", diff --git a/src/handlers/create-chat-completion.handler.ts b/src/handlers/create-chat-completion.handler.ts index 94f0f7a..d1a9b85 100644 --- a/src/handlers/create-chat-completion.handler.ts +++ b/src/handlers/create-chat-completion.handler.ts @@ -82,12 +82,10 @@ export default class CreateChatCompletionHandler implements OperationHandler { return; } - if (choices[index] == null) { - choices[index] = { + choices[index] ??= { index, message: { role: Role.Assistant, content: "" }, }; - } choices[index].finish_reason = finishReason; @@ -95,9 +93,7 @@ export default class CreateChatCompletionHandler implements OperationHandler { choices[index].message!.role = delta.role; } - if (choiceTokens[index] == null) { - choiceTokens[index] = []; - } + choiceTokens[index] ??= []; if (delta.content) { choiceTokens[index].push(delta.content); diff --git a/src/handlers/create-completion.handler.ts b/src/handlers/create-completion.handler.ts index e722f7d..0f2b21c 100644 --- a/src/handlers/create-completion.handler.ts +++ b/src/handlers/create-completion.handler.ts @@ -111,16 +111,12 @@ export default class CreateCompletionHandler implements OperationHandler { return; } - if (choices[index] == null) { - choices[index] = { + choices[index] ??= { index, }; - } choices[index].finish_reason = finishReason; - if (choiceTokens[index] == null) { - choiceTokens[index] = []; - } + choiceTokens[index] ??= []; choiceTokens[index].push(text); },