Workspace prompt changes (#949)

* track workspace prompt change

* refactor

* modify arg order

---------

Co-authored-by: timothycarambat <rambat1010@gmail.com>
This commit is contained in:
Sean Hatfield 2024-03-21 15:25:42 -07:00 committed by GitHub
parent 373c833aad
commit 35a155d3ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 1 deletions

View File

@ -87,7 +87,7 @@ function workspaceEndpoints(app) {
response.sendStatus(400).end();
return;
}
await Workspace.trackChange(currWorkspace, data, user);
const { workspace, message } = await Workspace.update(
currWorkspace.id,
data

View File

@ -6,6 +6,8 @@ const { ROLES } = require("../utils/middleware/multiUserProtected");
const { v4: uuidv4 } = require("uuid");
const Workspace = {
defaultPrompt:
"Given the following conversation, relevant context, and a follow up question, reply with an answer to the current question the user is asking. Return only your response to the question given the above information following the users instructions as needed.",
writable: [
// Used for generic updates so we can validate keys in request body
"name",
@ -213,6 +215,34 @@ const Workspace = {
return { success: false, error: error.message };
}
},
trackChange: async function (prevData, newData, user) {
try {
const { Telemetry } = require("./telemetry");
const { EventLogs } = require("./eventLogs");
if (
!newData?.openAiPrompt ||
newData?.openAiPrompt === this.defaultPrompt ||
newData?.openAiPrompt === prevData?.openAiPrompt
)
return;
await Telemetry.sendTelemetry("workspace_prompt_changed");
await EventLogs.logEvent(
"workspace_prompt_changed",
{
workspaceName: prevData?.name,
prevSystemPrompt: prevData?.openAiPrompt || this.defaultPrompt,
newSystemPrompt: newData?.openAiPrompt,
},
user?.id
);
return;
} catch (error) {
console.error("Error tracking workspace change:", error.message);
return;
}
},
};
module.exports = { Workspace };