Skip to content

Commit

Permalink
update prompt and handle custom group edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
nickoferrall committed Dec 17, 2024
1 parent b98b2d7 commit 8617536
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions packages/server/utils/OpenAIServerManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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) {
Expand Down

0 comments on commit 8617536

Please sign in to comment.