Skip to content

Commit

Permalink
chore: Reduce language detection threshold for MeetingTemplates (#9855)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dschoordsch authored Jun 18, 2024
1 parent 4604716 commit 03bd7dd
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 21 deletions.
41 changes: 41 additions & 0 deletions packages/embedder/__tests__/inferLanguage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import {inferLanguage} from '../inferLanguage'

test('should infer the language of a string', () => {
expect(
inferLanguage(
`
Weighted Shortest Job First
planning poker, sprint poker, estimation
Story Points
Fibonacci
1, 2, 3, 5, 8, 13, 21, 34, ?, Pass
Story Value
Fibonacci
1, 2, 3, 5, 8, 13, 21, 34, ?, Pass
`,
10
)
).toBe('en')
/* ideally this would be detected as 'en', but it isn't
expect(
inferLanguage(
`
*New Template #1
New prompt
`,
10
)
).toBe('en')
*/
expect(
inferLanguage(
`
Was lief gut?
Höhepunkte
`,
10
)
).not.toBe('en')
})
47 changes: 26 additions & 21 deletions packages/embedder/indexing/meetingTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import PokerTemplate from '../../server/database/types/PokerTemplate'
import ReflectTemplate from '../../server/database/types/ReflectTemplate'
import {inferLanguage} from '../inferLanguage'

const MIN_TEXT_LENGTH = 10

const createTextFromRetrospectiveMeetingTemplate = async (
template: ReflectTemplate,
dataLoader: DataLoaderInstance
Expand All @@ -14,15 +16,21 @@ const createTextFromRetrospectiveMeetingTemplate = async (
return `${question}\n${description}`
})
.join('\n')
return `${template.name}\nRetrospective\n${promptText}`
const body = `${template.name}\nRetrospective\n${promptText}`
const language = inferLanguage(`${template.name}\n${promptText}`, MIN_TEXT_LENGTH)
return {body, language}
}

const createTextFromTeamPromptMeetingTemplate = async (template: MeetingTemplate) => {
return `${template.name}\nteam prompt, daily standup, status update`
const body = `${template.name}\nteam prompt, daily standup, status update`
const language = inferLanguage(template.name, MIN_TEXT_LENGTH)
return {body, language}
}

const createTextFromActionMeetingTemplate = async (template: MeetingTemplate) => {
return `${template.name}\ncheck-in, action, task, todo, follow-up`
const body = `${template.name}\ncheck-in, action, task, todo, follow-up`
const language = inferLanguage(template.name, MIN_TEXT_LENGTH)
return {body, language}
}

const createTextFromPokerMeetingTemplate = async (
Expand All @@ -39,29 +47,26 @@ const createTextFromPokerMeetingTemplate = async (
})
)
).join('\n')
return `${template.name}\nplanning poker, sprint poker, estimation\n${dimensionsText}`
const body = `${template.name}\nplanning poker, sprint poker, estimation\n${dimensionsText}`
const language = inferLanguage(`${template.name}\n${dimensionsText}`, MIN_TEXT_LENGTH)
return {body, language}
}

export const createTextFromMeetingTemplate = async (
templateId: string,
dataLoader: DataLoaderInstance
) => {
const template = await dataLoader.get('meetingTemplates').load(templateId)
const body = await (() => {
switch (template?.type) {
case 'retrospective':
return createTextFromRetrospectiveMeetingTemplate(template, dataLoader)
case 'teamPrompt':
return createTextFromTeamPromptMeetingTemplate(template)
case 'action':
return createTextFromActionMeetingTemplate(template)
case 'poker':
return createTextFromPokerMeetingTemplate(template, dataLoader)
default:
return ''
}
})()

const language = inferLanguage(body)
return {body, language}
switch (template?.type) {
case 'retrospective':
return createTextFromRetrospectiveMeetingTemplate(template, dataLoader)
case 'teamPrompt':
return createTextFromTeamPromptMeetingTemplate(template)
case 'action':
return createTextFromActionMeetingTemplate(template)
case 'poker':
return createTextFromPokerMeetingTemplate(template, dataLoader)
default:
return {body: '', language: undefined}
}
}
21 changes: 21 additions & 0 deletions packages/embedder/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const tsJestPresets = require('ts-jest/presets')

module.exports = {
testEnvironment: 'node',
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
diagnostics: false
}
]
},
modulePaths: ['<rootDir>/packages/'],
moduleNameMapper: {
'server/(.*)': ['<rootDir>/$1'],
'parabol-client/(.*)': ['<rootDir>/../client/$1'],
'~/(.*)': ['<rootDir>/../client/$1']
},
testRegex: '/__tests__/.*.test\\.ts?$',
clearMocks: true
}
5 changes: 5 additions & 0 deletions packages/embedder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"lint:check": "eslint . --ext .ts,.tsx",
"prettier": "prettier --config ../../.prettierrc --write \"**/*.{ts,tsx}\"",
"prettier:check": "prettier --config ../../.prettierrc --check \"**/*.{ts,tsx}\"",
"test": "jest --verbose",
"typecheck": "yarn tsc --noEmit -p tsconfig.json"
},
"bugs": {
Expand All @@ -26,8 +27,12 @@
"@types/franc": "^5.0.3",
"@types/node": "^16.11.62",
"babel-plugin-inline-import": "^3.0.0",
"jest": "^29.5.0",
"jest-extended": "^3.2.4",
"jest-junit": "^16.0.0",
"openapi-fetch": "^0.9.3",
"sucrase": "^3.32.0",
"ts-jest": "^29.1.0",
"ts-node-dev": "^1.0.0-pre.44",
"typescript": "^5.3.3"
},
Expand Down

0 comments on commit 03bd7dd

Please sign in to comment.