diff --git a/frontend/src/components/Modals/MangeWorkspace/Settings/index.jsx b/frontend/src/components/Modals/MangeWorkspace/Settings/index.jsx
index c35df763..77d13162 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
+
+
+ Chat history: The number of previous chats that
+ will be included in the response's short-term memory.
+
+ Recommend 20. Anything more than 45 is likely to lead to
+ continuous chat failures depending on message size.
+
+ 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 09c3712c..8abd7b7c 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) {
@@ -106,7 +113,7 @@ const Workspace = {
const values = Object.values(data);
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 +127,7 @@ const Workspace = {
return { success: false, message: error.message };
});
- db.close();
+ db.close();
if (!success) {
return { workspace: null, message };
}
diff --git a/server/utils/chats/index.js b/server/utils/chats/index.js
index 7b2cc484..58381cb5 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 messageLimit = workspace?.openAiHistory;
+
+ const rawHistory = await WorkspaceChats.forWorkspace(workspace.id, messageLimit);
const chatHistory = convertToPromptHistory(rawHistory);
const {
response,