这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions frontend/src/components/Modals/MangeWorkspace/Settings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,40 @@ export default function WorkspaceSettings({ workspace }) {
onChange={() => setHasChanges(true)}
/>
</div>

<div>
<div className="flex flex-col gap-y-1 mb-4">
<label
htmlFor="name"
className="block text-sm font-medium text-gray-900 dark:text-white"
>
Chat History
</label>
<p className="text-xs text-gray-600 dark:text-stone-400">
Chat history: The number of previous chats that
will be included in the response's short-term memory.
<br />
Recommend 20. Anything more than 45 is likely to lead to
continuous chat failures depending on message size.
<br />
Recommended: 20
</p>
</div>
<input
name="openAiHistory"
type="number"
min={1}
max={45}
step={1}
onWheel={(e) => 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)}
/>
</div>
</div>

{error && (
Expand Down
11 changes: 9 additions & 2 deletions server/models/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const Workspace = {
"slug",
"vectorTag",
"openAiTemp",
"openAiHistory",
"lastUpdatedAt",
],
colsInit: `
Expand All @@ -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 () {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 = ?`;
Expand All @@ -120,7 +127,7 @@ const Workspace = {
return { success: false, message: error.message };
});

db.close();
db.close();
if (!success) {
return { workspace: null, message };
}
Expand Down
4 changes: 3 additions & 1 deletion server/utils/chats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down