From 35a155d3ac94009755b829d68ed685957d0a5ca9 Mon Sep 17 00:00:00 2001 From: Sean Hatfield Date: Thu, 21 Mar 2024 15:25:42 -0700 Subject: [PATCH] Workspace prompt changes (#949) * track workspace prompt change * refactor * modify arg order --------- Co-authored-by: timothycarambat --- server/endpoints/workspaces.js | 2 +- server/models/workspace.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/server/endpoints/workspaces.js b/server/endpoints/workspaces.js index 2fe63e58..d3715cd8 100644 --- a/server/endpoints/workspaces.js +++ b/server/endpoints/workspaces.js @@ -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 diff --git a/server/models/workspace.js b/server/models/workspace.js index 48952c63..7056468d 100644 --- a/server/models/workspace.js +++ b/server/models/workspace.js @@ -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 };