From 861753688ad2f938d80cbf93c0e0bc7ee32aedbe Mon Sep 17 00:00:00 2001 From: Nick O'Ferrall Date: Tue, 17 Dec 2024 17:16:48 +0000 Subject: [PATCH] update prompt and handle custom group edge case --- .../addReflectionToGroup.ts | 20 +++++++++++++++---- packages/server/utils/OpenAIServerManager.ts | 8 +++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/server/graphql/mutations/helpers/updateReflectionLocation/addReflectionToGroup.ts b/packages/server/graphql/mutations/helpers/updateReflectionLocation/addReflectionToGroup.ts index 672e287ccd2..222679d1677 100644 --- a/packages/server/graphql/mutations/helpers/updateReflectionLocation/addReflectionToGroup.ts +++ b/packages/server/graphql/mutations/helpers/updateReflectionLocation/addReflectionToGroup.ts @@ -15,9 +15,10 @@ const addReflectionToGroup = async ( const reflection = await dataLoader.get('retroReflections').load(reflectionId) if (!reflection) throw new Error('Reflection not found') const {reflectionGroupId: oldReflectionGroupId, meetingId: reflectionMeetingId} = reflection - const reflectionGroup = await dataLoader - .get('retroReflectionGroups') - .loadNonNull(reflectionGroupId) + const [reflectionGroup, oldReflectionGroup] = await Promise.all([ + dataLoader.get('retroReflectionGroups').loadNonNull(reflectionGroupId), + dataLoader.get('retroReflectionGroups').loadNonNull(oldReflectionGroupId) + ]) dataLoader.get('retroReflectionGroups').clear(reflectionGroupId) dataLoader.get('retroReflectionGroups').clear(oldReflectionGroupId) @@ -56,7 +57,18 @@ const addReflectionToGroup = async ( .get('retroReflectionsByGroupId') .load(oldReflectionGroupId) - if (smartTitle) { + const oldGroupHasSingleReflectionCustomTitle = + oldReflectionGroup.title !== oldReflectionGroup.smartTitle && oldReflections.length === 0 + const newGroupHasSmartTitle = reflectionGroup.title === reflectionGroup.smartTitle + + if (oldGroupHasSingleReflectionCustomTitle && newGroupHasSmartTitle) { + // Edge case of dragging a single card with a custom group name on a group with smart name + await pg + .updateTable('RetroReflectionGroup') + .set({title: oldReflectionGroup.title, smartTitle: smartTitle ?? ''}) + .where('id', '=', reflectionGroupId) + .execute() + } else if (smartTitle) { // smartTitle exists when autogrouping or resetting groups await updateSmartGroupTitle(reflectionGroupId, smartTitle) reflectionGroup.smartTitle = smartTitle diff --git a/packages/server/utils/OpenAIServerManager.ts b/packages/server/utils/OpenAIServerManager.ts index 8b880bae1dd..29a7b315cad 100644 --- a/packages/server/utils/OpenAIServerManager.ts +++ b/packages/server/utils/OpenAIServerManager.ts @@ -420,11 +420,11 @@ class OpenAIServerManager { async generateGroupTitle(reflections: {plaintextContent: string}[]) { if (!this.openAIApi) return null - const prompt = `Given these related retrospective comments, generate a short (2-4 words) theme or title that captures their essence. The title should be clear and actionable: + const prompt = `Generate a short (2-4 words) theme or title that captures the essence of these related retrospective comments. The title should be clear and actionable. ${reflections.map((r) => r.plaintextContent).join('\n')} -Return only the title, nothing else. Do not include quote marks around the title.` +Important: Respond with ONLY the title itself. Do not include any prefixes like "Title:" or any quote marks. Do not provide any additional explanation.` try { const response = await this.openAIApi.chat.completions.create({ @@ -442,7 +442,9 @@ Return only the title, nothing else. Do not include quote marks around the title presence_penalty: 0 }) const title = - (response.choices[0]?.message?.content?.trim() as string)?.replaceAll(/['"]/g, '') ?? null + (response.choices[0]?.message?.content?.trim() as string) + ?.replace(/^[Tt]itle:*\s*/gi, '') // Remove "Title:" prefix + ?.replaceAll(/['"]/g, '') ?? null return title } catch (e) {