-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve reflection group titles (#10546)
- Loading branch information
1 parent
2741491
commit cfde723
Showing
8 changed files
with
185 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/server/graphql/mutations/helpers/generateAIGroupTitle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {SubscriptionChannel} from 'parabol-client/types/constEnums' | ||
import OpenAIServerManager from '../../../utils/OpenAIServerManager' | ||
import publish from '../../../utils/publish' | ||
import standardError from '../../../utils/standardError' | ||
import {DataLoaderWorker} from '../../graphql' | ||
import updateSmartGroupTitle from './updateReflectionLocation/updateSmartGroupTitle' | ||
|
||
interface Reflection { | ||
entities: any[] | ||
plaintextContent: string | ||
} | ||
|
||
const generateAIGroupTitle = async ( | ||
reflections: Reflection[], | ||
reflectionGroupId: string, | ||
meetingId: string, | ||
dataLoader: DataLoaderWorker | ||
) => { | ||
const manager = new OpenAIServerManager() | ||
const aiTitle = await manager.generateGroupTitle(reflections) | ||
const newTitle = aiTitle ?? reflections[0]?.plaintextContent ?? '' | ||
if (!newTitle) standardError(new Error('Failed to generate AI title')) | ||
await updateSmartGroupTitle(reflectionGroupId, newTitle) | ||
dataLoader.get('retroReflectionGroups').clear(reflectionGroupId) | ||
publish( | ||
SubscriptionChannel.MEETING, | ||
meetingId, | ||
'UpdateReflectionGroupTitlePayload', | ||
{ | ||
meetingId, | ||
reflectionGroupId, | ||
title: aiTitle | ||
}, | ||
{operationId: dataLoader.share()} | ||
) | ||
} | ||
|
||
export default generateAIGroupTitle |
42 changes: 42 additions & 0 deletions
42
packages/server/graphql/mutations/helpers/updateGroupTitle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import getGroupSmartTitle from '../../../../client/utils/smartGroup/getGroupSmartTitle' | ||
import getKysely from '../../../postgres/getKysely' | ||
import {DataLoaderWorker} from '../../graphql' | ||
import {RetroReflection} from '../../public/resolverTypes' | ||
import canAccessAI from './canAccessAI' | ||
import generateAIGroupTitle from './generateAIGroupTitle' | ||
import updateSmartGroupTitle from './updateReflectionLocation/updateSmartGroupTitle' | ||
|
||
type Input = { | ||
reflections: RetroReflection[] | ||
reflectionGroupId: string | ||
meetingId: string | ||
teamId: string | ||
dataLoader: DataLoaderWorker | ||
} | ||
|
||
const updateGroupTitle = async (input: Input) => { | ||
const {reflections, reflectionGroupId, meetingId, teamId, dataLoader} = input | ||
if (reflections.length === 1) { | ||
// For single reflection, use its content as the title | ||
const newTitle = reflections[0].plaintextContent | ||
await updateSmartGroupTitle(reflectionGroupId, newTitle) | ||
return | ||
} | ||
const team = await dataLoader.get('teams').loadNonNull(teamId) | ||
const hasAIAccess = await canAccessAI(team, 'retrospective', dataLoader) | ||
if (!hasAIAccess) { | ||
const smartTitle = getGroupSmartTitle(reflections) | ||
await updateSmartGroupTitle(reflectionGroupId, smartTitle) | ||
} else { | ||
const pg = getKysely() | ||
await pg | ||
.updateTable('RetroReflectionGroup') | ||
.set({title: '', smartTitle: ''}) | ||
.where('id', '=', reflectionGroupId) | ||
.execute() | ||
// Generate title and don't await or the reflection will hang when it's dropped | ||
generateAIGroupTitle(reflections, reflectionGroupId, meetingId, dataLoader) | ||
} | ||
} | ||
|
||
export default updateGroupTitle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters