Skip to content

Commit

Permalink
feat: update suggest group titles (#10568)
Browse files Browse the repository at this point in the history
  • Loading branch information
nickoferrall authored Dec 18, 2024
1 parent 2da5af3 commit 81043ad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,11 @@ const ReflectionGroupTitleEditor = (props: Props) => {
const {id: reflectionGroupId, title} = reflectionGroup
const dirtyRef = useRef(false)
const initialTitleRef = useRef(title)
const isLoading = title === ''

const isLoading = title === '' && !dirtyRef.current

const onChange = (e: React.ChangeEvent<HTMLInputElement>) => {
dirtyRef.current = true
const title = e.target.value
commitLocalUpdate(atmosphere, (store) => {
const reflectionGroup = store.get(reflectionGroupId)
Expand Down
1 change: 1 addition & 0 deletions packages/client/mutations/AutogroupMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ graphql`
reflectionGroups {
id
title
smartTitle
reflections {
id
plaintextContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dndNoise from 'parabol-client/utils/dndNoise'
import getKysely from '../../../../postgres/getKysely'
import updateGroupTitle from '../updateGroupTitle'
import {GQLContext} from './../../../graphql'
import updateSmartGroupTitle from './updateSmartGroupTitle'

const addReflectionToGroup = async (
reflectionId: string,
Expand Down Expand Up @@ -67,6 +68,11 @@ const addReflectionToGroup = async (
.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
reflectionGroup.title = smartTitle
} else {
const meeting = await dataLoader.get('newMeetings').loadNonNull(meetingId)
await updateGroupTitle({
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 81043ad

Please sign in to comment.