Skip to content

Commit

Permalink
Workspace prompt changes (#949)
Browse files Browse the repository at this point in the history
* track workspace prompt change

* refactor

* modify arg order

---------

Co-authored-by: timothycarambat <[email protected]>
  • Loading branch information
shatfield4 and timothycarambat authored Mar 21, 2024
1 parent 373c833 commit 35a155d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/endpoints/workspaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions server/models/workspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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 };

0 comments on commit 35a155d

Please sign in to comment.