From f67049911ed9f3b54864e2e1fb62cefa9ec20ab9 Mon Sep 17 00:00:00 2001 From: Adhityan K V Date: Wed, 30 Oct 2024 21:49:32 +0100 Subject: [PATCH 1/2] chore: base model does not create conversation history when the parameter is not passed --- .../src/interfaces/base-model.ts | 46 ++-- package-lock.json | 235 +++++++++--------- package.json | 8 +- 3 files changed, 150 insertions(+), 139 deletions(-) diff --git a/core/embedjs-interfaces/src/interfaces/base-model.ts b/core/embedjs-interfaces/src/interfaces/base-model.ts index df1ab3b..961ac6b 100644 --- a/core/embedjs-interfaces/src/interfaces/base-model.ts +++ b/core/embedjs-interfaces/src/interfaces/base-model.ts @@ -2,7 +2,7 @@ import { HumanMessage, AIMessage, SystemMessage } from '@langchain/core/messages import createDebugMessages from 'debug'; import { v4 as uuidv4 } from 'uuid'; -import { Chunk, QueryResponse, Message, SourceDetail, ModelResponse } from '../types.js'; +import { Chunk, QueryResponse, Message, SourceDetail, ModelResponse, Conversation } from '../types.js'; import { BaseCache } from './base-cache.js'; export abstract class BaseModel { @@ -78,23 +78,32 @@ export abstract class BaseModel { system: string, userQuery: string, supportingContext: Chunk[], - conversationId = 'default', + conversationId?: string, ): Promise { - if (!(await BaseModel.cache.hasConversation(conversationId))) { - this.baseDebug(`Conversation with id '${conversationId}' is new`); - await BaseModel.cache.addConversation(conversationId); - } + let conversation: Conversation; - const conversation = await BaseModel.cache.getConversation(conversationId); - this.baseDebug(`${conversation.entries.length} history entries found for conversationId '${conversationId}'`); + if (conversationId) { + if (!(await BaseModel.cache.hasConversation(conversationId))) { + this.baseDebug(`Conversation with id '${conversationId}' is new`); + await BaseModel.cache.addConversation(conversationId); + } - // Add user query to history - await BaseModel.cache.addEntryToConversation(conversationId, { - id: uuidv4(), - timestamp: new Date(), - actor: 'HUMAN', - content: userQuery, - }); + conversation = await BaseModel.cache.getConversation(conversationId); + this.baseDebug( + `${conversation.entries.length} history entries found for conversationId '${conversationId}'`, + ); + + // Add user query to history + await BaseModel.cache.addEntryToConversation(conversationId, { + id: uuidv4(), + timestamp: new Date(), + actor: 'HUMAN', + content: userQuery, + }); + } else { + this.baseDebug('Conversation history is disabled as no conversationId was provided'); + conversation = { conversationId: 'default', entries: [] }; + } const messages = await this.prepare(system, userQuery, supportingContext, conversation.entries.slice(0, -1)); const uniqueSources = this.extractUniqueSources(supportingContext); @@ -112,8 +121,11 @@ export abstract class BaseModel { sources: uniqueSources, }; - // Add AI response to history - await BaseModel.cache.addEntryToConversation(conversationId, newEntry); + if (conversationId) { + // Add AI response to history + await BaseModel.cache.addEntryToConversation(conversationId, newEntry); + } + return { ...newEntry, tokenUse: { diff --git a/package-lock.json b/package-lock.json index f45252c..4169d9b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,9 +27,9 @@ "@swc-node/register": "~1.10.9", "@swc/core": "~1.7.40", "@swc/helpers": "~0.5.13", - "@types/node": "22.8.1", - "@typescript-eslint/eslint-plugin": "^8.11.0", - "@typescript-eslint/parser": "^8.11.0", + "@types/node": "22.8.4", + "@typescript-eslint/eslint-plugin": "^8.12.2", + "@typescript-eslint/parser": "^8.12.2", "arg": "^5.0.2", "esbuild": "^0.19.12", "eslint": "~9.13.0", @@ -40,7 +40,7 @@ "simple-git": "^3.27.0", "tslib": "^2.8.0", "typescript": "5.6.3", - "typescript-eslint": "^8.11.0" + "typescript-eslint": "^8.12.2" }, "engines": { "node": ">= 18.0.0" @@ -48,12 +48,12 @@ }, "core/embedjs": { "name": "@llm-tools/embedjs", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/textsplitters": "^0.1.0", - "@llm-tools/embedjs-interfaces": "0.1.11", - "@llm-tools/embedjs-utils": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", + "@llm-tools/embedjs-utils": "0.1.13", "debug": "^4.3.7", "langchain": "^0.3.4", "md5": "^2.3.0", @@ -68,7 +68,7 @@ }, "core/embedjs-interfaces": { "name": "@llm-tools/embedjs-interfaces", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/core": "^0.3.15", @@ -85,10 +85,10 @@ }, "core/embedjs-utils": { "name": "@llm-tools/embedjs-utils", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { - "@llm-tools/embedjs-interfaces": "0.1.11" + "@llm-tools/embedjs-interfaces": "0.1.13" } }, "core/embedjs/node_modules/js-yaml": { @@ -219,41 +219,41 @@ }, "databases/embedjs-astra": { "name": "@llm-tools/embedjs-astradb", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@datastax/astra-db-ts": "^1.5.0", - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "debug": "^4.3.7" } }, "databases/embedjs-cosmos": { "name": "@llm-tools/embedjs-cosmos", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@azure/cosmos": "^4.1.1", - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "debug": "^4.3.7" } }, "databases/embedjs-hnswlib": { "name": "@llm-tools/embedjs-hnswlib", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "debug": "^4.3.7", "hnswlib-node": "^3.0.0" } }, "databases/embedjs-lancedb": { "name": "@llm-tools/embedjs-lancedb", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@lancedb/lancedb": "^0.11.0", - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "compute-cosine-similarity": "^1.1.0" } }, @@ -370,29 +370,29 @@ }, "databases/embedjs-lmdb": { "name": "@llm-tools/embedjs-lmdb", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "lmdb": "^3.1.3" } }, "databases/embedjs-mongodb": { "name": "@llm-tools/embedjs-mongodb", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "debug": "^4.3.7", "mongodb": "^6.10.0" } }, "databases/embedjs-pinecone": { "name": "@llm-tools/embedjs-pinecone", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "@pinecone-database/pinecone": "^4.0.0", "debug": "^4.3.7" } @@ -411,10 +411,10 @@ }, "databases/embedjs-qdrant": { "name": "@llm-tools/embedjs-qdrant", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "@qdrant/js-client-rest": "^1.12.0", "debug": "^4.3.7", "uuid": "^10.0.0" @@ -422,19 +422,19 @@ }, "databases/embedjs-redis": { "name": "@llm-tools/embedjs-redis", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "ioredis": "^5.4.1" } }, "databases/embedjs-weaviate": { "name": "@llm-tools/embedjs-weaviate", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "compute-cosine-similarity": "^1.1.0", "debug": "^4.3.7", "weaviate-ts-client": "^2.2.0" @@ -442,11 +442,11 @@ }, "loaders/embedjs-loader-confluence": { "name": "@llm-tools/embedjs-loader-confluence", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { - "@llm-tools/embedjs-interfaces": "0.1.11", - "@llm-tools/embedjs-loader-web": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", + "@llm-tools/embedjs-loader-web": "0.1.13", "confluence.js": "^1.7.4", "debug": "^4.3.7", "md5": "^2.3.0" @@ -454,11 +454,11 @@ }, "loaders/embedjs-loader-csv": { "name": "@llm-tools/embedjs-loader-csv", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { - "@llm-tools/embedjs-interfaces": "0.1.11", - "@llm-tools/embedjs-utils": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", + "@llm-tools/embedjs-utils": "0.1.13", "axios": "^1.7.7", "csv-parse": "^5.5.6", "debug": "^4.3.7", @@ -467,35 +467,35 @@ }, "loaders/embedjs-loader-msoffice": { "name": "@llm-tools/embedjs-loader-msoffice", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/textsplitters": "^0.1.0", - "@llm-tools/embedjs-interfaces": "0.1.11", - "@llm-tools/embedjs-utils": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", + "@llm-tools/embedjs-utils": "0.1.13", "md5": "^2.3.0", "office-text-extractor": "^3.0.3" } }, "loaders/embedjs-loader-pdf": { "name": "@llm-tools/embedjs-loader-pdf", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/textsplitters": "^0.1.0", - "@llm-tools/embedjs-interfaces": "0.1.11", - "@llm-tools/embedjs-utils": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", + "@llm-tools/embedjs-utils": "0.1.13", "md5": "^2.3.0", "office-text-extractor": "^3.0.3" } }, "loaders/embedjs-loader-sitemap": { "name": "@llm-tools/embedjs-loader-sitemap", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { - "@llm-tools/embedjs-interfaces": "0.1.11", - "@llm-tools/embedjs-loader-web": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", + "@llm-tools/embedjs-loader-web": "0.1.13", "debug": "^4.3.7", "md5": "^2.3.0", "sitemapper": "^3.2.14" @@ -503,12 +503,12 @@ }, "loaders/embedjs-loader-web": { "name": "@llm-tools/embedjs-loader-web", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/textsplitters": "^0.1.0", - "@llm-tools/embedjs-interfaces": "0.1.11", - "@llm-tools/embedjs-utils": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", + "@llm-tools/embedjs-utils": "0.1.13", "axios": "^1.7.7", "debug": "^4.3.7", "html-to-text": "^9.0.5", @@ -520,12 +520,12 @@ }, "loaders/embedjs-loader-youtube": { "name": "@llm-tools/embedjs-loader-youtube", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/textsplitters": "^0.1.0", - "@llm-tools/embedjs-interfaces": "0.1.11", - "@llm-tools/embedjs-utils": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", + "@llm-tools/embedjs-utils": "0.1.13", "debug": "^4.3.7", "md5": "^2.3.0", "usetube": "^2.2.7", @@ -537,34 +537,34 @@ }, "models/embedjs-anthropic": { "name": "@llm-tools/embedjs-anthropic", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/anthropic": "^0.3.5", "@langchain/core": "^0.3.15", - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "debug": "^4.3.7" } }, "models/embedjs-cohere": { "name": "@llm-tools/embedjs-cohere", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/cohere": "^0.3.1", - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "cohere-ai": "^7.14.0" } }, "models/embedjs-huggingface": { "name": "@llm-tools/embedjs-huggingface", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@huggingface/inference": "^2.8.1", "@langchain/community": "^0.3.10", "@langchain/core": "^0.3.15", - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "debug": "^4.3.7" } }, @@ -1204,45 +1204,45 @@ }, "models/embedjs-mistral": { "name": "@llm-tools/embedjs-mistral", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/core": "^0.3.15", "@langchain/mistralai": "^0.1.1", - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "debug": "^4.3.7" } }, "models/embedjs-ollama": { "name": "@llm-tools/embedjs-ollama", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/core": "^0.3.15", "@langchain/ollama": "^0.1.0", - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "debug": "^4.3.7" } }, "models/embedjs-openai": { "name": "@llm-tools/embedjs-openai", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/core": "^0.3.15", "@langchain/openai": "^0.3.11", - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "debug": "^4.3.7" } }, "models/embedjs-vertexai": { "name": "@llm-tools/embedjs-vertexai", - "version": "0.1.11", + "version": "0.1.13", "license": "Apache-2.0", "dependencies": { "@langchain/core": "^0.3.15", "@langchain/google-vertexai": "^0.1.0", - "@llm-tools/embedjs-interfaces": "0.1.11", + "@llm-tools/embedjs-interfaces": "0.1.13", "debug": "^4.3.7" } }, @@ -8657,9 +8657,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.8.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.1.tgz", - "integrity": "sha512-k6Gi8Yyo8EtrNtkHXutUu2corfDf9su95VYVP10aGYMMROM6SAItZi0w1XszA6RtWTHSVp5OeFof37w0IEqCQg==", + "version": "22.8.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.8.4.tgz", + "integrity": "sha512-SpNNxkftTJOPk0oN+y2bIqurEXHTA2AOZ3EJDDKeJ5VzkvvORSvmQXGQarcOzWV1ac7DCaPBEdMDxBsM+d8jWw==", "license": "MIT", "dependencies": { "undici-types": "~6.19.8" @@ -8756,17 +8756,17 @@ "license": "MIT" }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.11.0.tgz", - "integrity": "sha512-KhGn2LjW1PJT2A/GfDpiyOfS4a8xHQv2myUagTM5+zsormOmBlYsnQ6pobJ8XxJmh6hnHwa2Mbe3fPrDJoDhbA==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.12.2.tgz", + "integrity": "sha512-gQxbxM8mcxBwaEmWdtLCIGLfixBMHhQjBqR8sVWNTPpcj45WlYL2IObS/DNMLH1DBP0n8qz+aiiLTGfopPEebw==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/regexpp": "^4.10.0", - "@typescript-eslint/scope-manager": "8.11.0", - "@typescript-eslint/type-utils": "8.11.0", - "@typescript-eslint/utils": "8.11.0", - "@typescript-eslint/visitor-keys": "8.11.0", + "@typescript-eslint/scope-manager": "8.12.2", + "@typescript-eslint/type-utils": "8.12.2", + "@typescript-eslint/utils": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2", "graphemer": "^1.4.0", "ignore": "^5.3.1", "natural-compare": "^1.4.0", @@ -8790,16 +8790,16 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.11.0.tgz", - "integrity": "sha512-lmt73NeHdy1Q/2ul295Qy3uninSqi6wQI18XwSpm8w0ZbQXUpjCAWP1Vlv/obudoBiIjJVjlztjQ+d/Md98Yxg==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-8.12.2.tgz", + "integrity": "sha512-MrvlXNfGPLH3Z+r7Tk+Z5moZAc0dzdVjTgUgwsdGweH7lydysQsnSww3nAmsq8blFuRD5VRlAr9YdEFw3e6PBw==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/scope-manager": "8.11.0", - "@typescript-eslint/types": "8.11.0", - "@typescript-eslint/typescript-estree": "8.11.0", - "@typescript-eslint/visitor-keys": "8.11.0", + "@typescript-eslint/scope-manager": "8.12.2", + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/typescript-estree": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2", "debug": "^4.3.4" }, "engines": { @@ -8819,14 +8819,14 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.11.0.tgz", - "integrity": "sha512-Uholz7tWhXmA4r6epo+vaeV7yjdKy5QFCERMjs1kMVsLRKIrSdM6o21W2He9ftp5PP6aWOVpD5zvrvuHZC0bMQ==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-8.12.2.tgz", + "integrity": "sha512-gPLpLtrj9aMHOvxJkSbDBmbRuYdtiEbnvO25bCMza3DhMjTQw0u7Y1M+YR5JPbMsXXnSPuCf5hfq0nEkQDL/JQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.11.0", - "@typescript-eslint/visitor-keys": "8.11.0" + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -8837,14 +8837,14 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.11.0.tgz", - "integrity": "sha512-ItiMfJS6pQU0NIKAaybBKkuVzo6IdnAhPFZA/2Mba/uBjuPQPet/8+zh5GtLHwmuFRShZx+8lhIs7/QeDHflOg==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-8.12.2.tgz", + "integrity": "sha512-bwuU4TAogPI+1q/IJSKuD4shBLc/d2vGcRT588q+jzayQyjVK2X6v/fbR4InY2U2sgf8MEvVCqEWUzYzgBNcGQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/typescript-estree": "8.11.0", - "@typescript-eslint/utils": "8.11.0", + "@typescript-eslint/typescript-estree": "8.12.2", + "@typescript-eslint/utils": "8.12.2", "debug": "^4.3.4", "ts-api-utils": "^1.3.0" }, @@ -8862,9 +8862,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.11.0.tgz", - "integrity": "sha512-tn6sNMHf6EBAYMvmPUaKaVeYvhUsrE6x+bXQTxjQRp360h1giATU0WvgeEys1spbvb5R+VpNOZ+XJmjD8wOUHw==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-8.12.2.tgz", + "integrity": "sha512-VwDwMF1SZ7wPBUZwmMdnDJ6sIFk4K4s+ALKLP6aIQsISkPv8jhiw65sAK6SuWODN/ix+m+HgbYDkH+zLjrzvOA==", "dev": true, "license": "MIT", "engines": { @@ -8876,14 +8876,14 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.11.0.tgz", - "integrity": "sha512-yHC3s1z1RCHoCz5t06gf7jH24rr3vns08XXhfEqzYpd6Hll3z/3g23JRi0jM8A47UFKNc3u/y5KIMx8Ynbjohg==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-8.12.2.tgz", + "integrity": "sha512-mME5MDwGe30Pq9zKPvyduyU86PH7aixwqYR2grTglAdB+AN8xXQ1vFGpYaUSJ5o5P/5znsSBeNcs5g5/2aQwow==", "dev": true, "license": "BSD-2-Clause", "dependencies": { - "@typescript-eslint/types": "8.11.0", - "@typescript-eslint/visitor-keys": "8.11.0", + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/visitor-keys": "8.12.2", "debug": "^4.3.4", "fast-glob": "^3.3.2", "is-glob": "^4.0.3", @@ -8938,16 +8938,16 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.11.0.tgz", - "integrity": "sha512-CYiX6WZcbXNJV7UNB4PLDIBtSdRmRI/nb0FMyqHPTQD1rMjA0foPLaPUV39C/MxkTd/QKSeX+Gb34PPsDVC35g==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-8.12.2.tgz", + "integrity": "sha512-UTTuDIX3fkfAz6iSVa5rTuSfWIYZ6ATtEocQ/umkRSyC9O919lbZ8dcH7mysshrCdrAM03skJOEYaBugxN+M6A==", "dev": true, "license": "MIT", "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", - "@typescript-eslint/scope-manager": "8.11.0", - "@typescript-eslint/types": "8.11.0", - "@typescript-eslint/typescript-estree": "8.11.0" + "@typescript-eslint/scope-manager": "8.12.2", + "@typescript-eslint/types": "8.12.2", + "@typescript-eslint/typescript-estree": "8.12.2" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" @@ -8961,13 +8961,13 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.11.0.tgz", - "integrity": "sha512-EaewX6lxSjRJnc+99+dqzTeoDZUfyrA52d2/HRrkI830kgovWsmIiTfmr0NZorzqic7ga+1bS60lRBUgR3n/Bw==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-8.12.2.tgz", + "integrity": "sha512-PChz8UaKQAVNHghsHcPyx1OMHoFRUEA7rJSK/mDhdq85bk+PLsUHUBqTQTFt18VJZbmxBovM65fezlheQRsSDA==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/types": "8.11.0", + "@typescript-eslint/types": "8.12.2", "eslint-visitor-keys": "^3.4.3" }, "engines": { @@ -12083,7 +12083,7 @@ "version": "5.3.2", "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz", "integrity": "sha512-hsBTNUqQTDwkWtcdYI2i06Y/nUBEsNEDJKjWdigLvegy8kDuJAS8uRlpkkcQpyEXL0Z/pjDy5HBmMjRCJ2gq+g==", - "dev": true, + "devOptional": true, "license": "MIT", "engines": { "node": ">= 4" @@ -16227,7 +16227,6 @@ "version": "5.6.3", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz", "integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==", - "dev": true, "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", @@ -16238,15 +16237,15 @@ } }, "node_modules/typescript-eslint": { - "version": "8.11.0", - "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.11.0.tgz", - "integrity": "sha512-cBRGnW3FSlxaYwU8KfAewxFK5uzeOAp0l2KebIlPDOT5olVi65KDG/yjBooPBG0kGW/HLkoz1c/iuBFehcS3IA==", + "version": "8.12.2", + "resolved": "https://registry.npmjs.org/typescript-eslint/-/typescript-eslint-8.12.2.tgz", + "integrity": "sha512-UbuVUWSrHVR03q9CWx+JDHeO6B/Hr9p4U5lRH++5tq/EbFq1faYZe50ZSBePptgfIKLEti0aPQ3hFgnPVcd8ZQ==", "dev": true, "license": "MIT", "dependencies": { - "@typescript-eslint/eslint-plugin": "8.11.0", - "@typescript-eslint/parser": "8.11.0", - "@typescript-eslint/utils": "8.11.0" + "@typescript-eslint/eslint-plugin": "8.12.2", + "@typescript-eslint/parser": "8.12.2", + "@typescript-eslint/utils": "8.12.2" }, "engines": { "node": "^18.18.0 || ^20.9.0 || >=21.1.0" diff --git a/package.json b/package.json index f953207..1d1f502 100644 --- a/package.json +++ b/package.json @@ -30,9 +30,9 @@ "@swc-node/register": "~1.10.9", "@swc/core": "~1.7.40", "@swc/helpers": "~0.5.13", - "@types/node": "22.8.1", - "@typescript-eslint/eslint-plugin": "^8.11.0", - "@typescript-eslint/parser": "^8.11.0", + "@types/node": "22.8.4", + "@typescript-eslint/eslint-plugin": "^8.12.2", + "@typescript-eslint/parser": "^8.12.2", "arg": "^5.0.2", "esbuild": "^0.19.12", "eslint": "~9.13.0", @@ -43,7 +43,7 @@ "simple-git": "^3.27.0", "tslib": "^2.8.0", "typescript": "5.6.3", - "typescript-eslint": "^8.11.0" + "typescript-eslint": "^8.12.2" }, "workspaces": [ "core/*", From e0c6c02e412eca13344007184a829dc6319d32fc Mon Sep 17 00:00:00 2001 From: Adhityan K V Date: Wed, 30 Oct 2024 21:54:48 +0100 Subject: [PATCH 2/2] chore: added param storeConversationsToDefaultThread --- core/embedjs/src/core/rag-application-builder.ts | 15 +++++++++++++++ core/embedjs/src/core/rag-application.ts | 9 ++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/embedjs/src/core/rag-application-builder.ts b/core/embedjs/src/core/rag-application-builder.ts index 30e398e..999c0e6 100644 --- a/core/embedjs/src/core/rag-application-builder.ts +++ b/core/embedjs/src/core/rag-application-builder.ts @@ -12,6 +12,7 @@ export class RAGApplicationBuilder { private searchResultCount: number; private embeddingModel: BaseEmbeddings; private embeddingRelevanceCutOff: number; + private storeConversationsToDefaultThread: boolean; constructor() { this.loaders = []; @@ -24,6 +25,7 @@ export class RAGApplicationBuilder { Do not use words like context or training data when responding. You can say you do not have all the information but do not indicate that you are not a reliable source.`; + this.storeConversationsToDefaultThread = true; this.embeddingRelevanceCutOff = 0; this.cache = new MemoryCache(); } @@ -101,6 +103,15 @@ export class RAGApplicationBuilder { return this; } + /** + * The setParamStoreConversationsToDefaultThread configures whether the conversation hisotry for queries made + * without a conversationId passed should be stored in the default thread. This is set to True by default. + */ + setParamStoreConversationsToDefaultThread(storeConversationsToDefaultThread: boolean) { + this.storeConversationsToDefaultThread = storeConversationsToDefaultThread; + return this; + } + getLoaders() { return this.loaders; } @@ -136,4 +147,8 @@ export class RAGApplicationBuilder { getModel() { return this.model; } + + getParamStoreConversationsToDefaultThread() { + return this.storeConversationsToDefaultThread; + } } diff --git a/core/embedjs/src/core/rag-application.ts b/core/embedjs/src/core/rag-application.ts index c305d52..cb861c8 100644 --- a/core/embedjs/src/core/rag-application.ts +++ b/core/embedjs/src/core/rag-application.ts @@ -19,6 +19,7 @@ import { cleanString, getUnique } from '@llm-tools/embedjs-utils'; export class RAGApplication { private readonly debug = createDebugMessages('embedjs:core'); + private readonly storeConversationsToDefaultThread: boolean; private readonly embeddingRelevanceCutOff: number; private readonly searchResultCount: number; private readonly systemMessage: string; @@ -30,6 +31,7 @@ export class RAGApplication { constructor(llmBuilder: RAGApplicationBuilder) { if (!llmBuilder.getEmbeddingModel()) throw new Error('Embedding model must be set!'); + this.storeConversationsToDefaultThread = llmBuilder.getParamStoreConversationsToDefaultThread(); this.cache = llmBuilder.getCache(); BaseLoader.setCache(this.cache); BaseModel.setCache(this.cache); @@ -382,11 +384,16 @@ export class RAGApplication { let context = options?.customContext; if (!context) context = await this.search(userQuery); + let conversationId = options?.conversationId; + if (!conversationId && this.storeConversationsToDefaultThread) { + conversationId = 'default'; + } + const sources = [...new Set(context.map((chunk) => chunk.metadata.source))]; this.debug( `Query resulted in ${context.length} chunks after filteration; chunks from ${sources.length} unique sources.`, ); - return this.model.query(this.systemMessage, userQuery, context, options?.conversationId); + return this.model.query(this.systemMessage, userQuery, context, conversationId); } }