From a8075f52f7c8359a73e19c06a9826a0971cd781c Mon Sep 17 00:00:00 2001 From: Antonio Ciolino Date: Tue, 27 Jun 2023 14:43:16 -0400 Subject: [PATCH 1/4] Enable saving history value per workspace --- .../Modals/MangeWorkspace/Settings/index.jsx | 34 +++++++++++++++++++ server/models/workspace.js | 12 +++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/Modals/MangeWorkspace/Settings/index.jsx b/frontend/src/components/Modals/MangeWorkspace/Settings/index.jsx index c35df763417..d57e0da6b61 100644 --- a/frontend/src/components/Modals/MangeWorkspace/Settings/index.jsx +++ b/frontend/src/components/Modals/MangeWorkspace/Settings/index.jsx @@ -140,6 +140,40 @@ export default function WorkspaceSettings({ workspace }) { onChange={() => setHasChanges(true)} /> + +
+
+ +

+ Chat history: how far back in teh current discussion will + chat pull responses. +
+ Default 20. Anything more than 45 is likely to cause significant failures + as well as higher costs. +
+ Recommended: 20 +

+
+ e.target.blur()} + defaultValue={workspace?.openAiHistory ?? 20} + className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-stone-600 dark:border-stone-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500" + placeholder="20" + required={true} + autoComplete="off" + onChange={() => setHasChanges(true)} + /> +
{error && ( diff --git a/server/models/workspace.js b/server/models/workspace.js index 09c3712cebd..44d62579b6e 100644 --- a/server/models/workspace.js +++ b/server/models/workspace.js @@ -10,6 +10,7 @@ const Workspace = { "slug", "vectorTag", "openAiTemp", + "openAiHistory", "lastUpdatedAt", ], colsInit: ` @@ -19,6 +20,7 @@ const Workspace = { vectorTag TEXT DEFAULT NULL, createdAt TEXT DEFAULT CURRENT_TIMESTAMP, openAiTemp REAL DEFAULT NULL, + openAiHistory INTEGER DEFAULT 20, lastUpdatedAt TEXT DEFAULT CURRENT_TIMESTAMP `, migrateTable: async function () { @@ -42,6 +44,11 @@ const Workspace = { END`, doif: true, }, + { + colName: "openAiHistory", + execCmd: `ALTER TABLE ${this.tablename} ADD COLUMN openAiHistory INTEGER DEFAULT 20`, + doif: false, + }, ]; }, db: async function (tracing = true) { @@ -104,9 +111,10 @@ const Workspace = { this.writable.includes(key) ); const values = Object.values(data); + console.log(validKeys); if (validKeys.length === 0 || validKeys.length !== values.length) return { workspace: { id }, message: "No valid fields to update!" }; - + const template = `UPDATE ${this.tablename} SET ${validKeys.map((key) => { return `${key}=?`; })} WHERE id = ?`; @@ -120,7 +128,7 @@ const Workspace = { return { success: false, message: error.message }; }); - db.close(); + db.close(); if (!success) { return { workspace: null, message }; } From c9ae7ffc26248f01c1e093402539c408ed345b58 Mon Sep 17 00:00:00 2001 From: Antonio Ciolino Date: Tue, 27 Jun 2023 14:43:16 -0400 Subject: [PATCH 2/4] added history --- server/utils/chats/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/utils/chats/index.js b/server/utils/chats/index.js index 7b2cc484750..31364a42b8d 100644 --- a/server/utils/chats/index.js +++ b/server/utils/chats/index.js @@ -104,7 +104,9 @@ async function chatWithWorkspace(workspace, message, chatMode = "chat") { error: null, }; } else { - const rawHistory = await WorkspaceChats.forWorkspace(workspace.id, 20); + var chat_memory = workspace?.openAiHistory; + // console.debug(chat_memory); + const rawHistory = await WorkspaceChats.forWorkspace(workspace.id, chat_memory); const chatHistory = convertToPromptHistory(rawHistory); const { response, From 693ad8aecbc45b0aa4e5a9f794b8758c717e4e2e Mon Sep 17 00:00:00 2001 From: Antonio Ciolino Date: Tue, 27 Jun 2023 16:01:00 -0400 Subject: [PATCH 3/4] added history --- server/models/workspace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/models/workspace.js b/server/models/workspace.js index 44d62579b6e..7d7bdc1ad10 100644 --- a/server/models/workspace.js +++ b/server/models/workspace.js @@ -111,7 +111,7 @@ const Workspace = { this.writable.includes(key) ); const values = Object.values(data); - console.log(validKeys); + // console.log(validKeys); if (validKeys.length === 0 || validKeys.length !== values.length) return { workspace: { id }, message: "No valid fields to update!" }; From 8b4af25619b889c03ef3284828b26dcb35bfa916 Mon Sep 17 00:00:00 2001 From: Antonio Ciolino Date: Wed, 28 Jun 2023 15:30:01 -0400 Subject: [PATCH 4/4] Changes re: the PR for message limits from history --- .../Modals/MangeWorkspace/Settings/index.jsx | 12 ++++++------ server/models/workspace.js | 1 - server/utils/chats/index.js | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/Modals/MangeWorkspace/Settings/index.jsx b/frontend/src/components/Modals/MangeWorkspace/Settings/index.jsx index d57e0da6b61..77d131625f3 100644 --- a/frontend/src/components/Modals/MangeWorkspace/Settings/index.jsx +++ b/frontend/src/components/Modals/MangeWorkspace/Settings/index.jsx @@ -150,11 +150,11 @@ export default function WorkspaceSettings({ workspace }) { Chat History

- Chat history: how far back in teh current discussion will - chat pull responses. + Chat history: The number of previous chats that + will be included in the response's short-term memory.
- Default 20. Anything more than 45 is likely to cause significant failures - as well as higher costs. + Recommend 20. Anything more than 45 is likely to lead to + continuous chat failures depending on message size.
Recommended: 20

@@ -162,8 +162,8 @@ export default function WorkspaceSettings({ workspace }) { e.target.blur()} defaultValue={workspace?.openAiHistory ?? 20} diff --git a/server/models/workspace.js b/server/models/workspace.js index 7d7bdc1ad10..8abd7b7c665 100644 --- a/server/models/workspace.js +++ b/server/models/workspace.js @@ -111,7 +111,6 @@ const Workspace = { this.writable.includes(key) ); const values = Object.values(data); - // console.log(validKeys); if (validKeys.length === 0 || validKeys.length !== values.length) return { workspace: { id }, message: "No valid fields to update!" }; diff --git a/server/utils/chats/index.js b/server/utils/chats/index.js index 31364a42b8d..58381cb5660 100644 --- a/server/utils/chats/index.js +++ b/server/utils/chats/index.js @@ -104,9 +104,9 @@ async function chatWithWorkspace(workspace, message, chatMode = "chat") { error: null, }; } else { - var chat_memory = workspace?.openAiHistory; - // console.debug(chat_memory); - const rawHistory = await WorkspaceChats.forWorkspace(workspace.id, chat_memory); + var messageLimit = workspace?.openAiHistory; + + const rawHistory = await WorkspaceChats.forWorkspace(workspace.id, messageLimit); const chatHistory = convertToPromptHistory(rawHistory); const { response,