randomly select at most 25 candidates and time each step
This commit is contained in:
@ -136,11 +136,17 @@ const getPreferencesList = async (userId: string): Promise<LibraryItem[]> => {
|
|||||||
return dedupedPreferences
|
return dedupedPreferences
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const randomSelectCandidates = (candidates: LibraryItem[]): LibraryItem[] => {
|
||||||
|
// randomly choose at most 25 candidates
|
||||||
|
return candidates.sort(() => 0.5 - Math.random()).slice(0, 25)
|
||||||
|
}
|
||||||
|
|
||||||
// Makes multiple DB queries and combines the results
|
// Makes multiple DB queries and combines the results
|
||||||
const getCandidatesList = async (
|
const getCandidatesList = async (
|
||||||
userId: string,
|
userId: string,
|
||||||
selectedLibraryItemIds?: string[]
|
selectedLibraryItemIds?: string[]
|
||||||
): Promise<LibraryItem[]> => {
|
): Promise<LibraryItem[]> => {
|
||||||
|
console.time('getCandidatesList')
|
||||||
// use the queries from the digest definitions to lookup preferences
|
// use the queries from the digest definitions to lookup preferences
|
||||||
// There should be a list of multiple queries we use. For now we can
|
// There should be a list of multiple queries we use. For now we can
|
||||||
// hardcode these queries:
|
// hardcode these queries:
|
||||||
@ -199,11 +205,15 @@ const getCandidatesList = async (
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const selectedCandidates = randomSelectCandidates(dedupedCandidates)
|
||||||
|
|
||||||
// store the ids in cache
|
// store the ids in cache
|
||||||
const candidateIds = dedupedCandidates.map((item) => item.id).join(',')
|
const candidateIds = selectedCandidates.map((item) => item.id).join(',')
|
||||||
await redisDataSource.redisClient?.set(key, candidateIds)
|
await redisDataSource.redisClient?.set(key, candidateIds)
|
||||||
|
|
||||||
return dedupedCandidates
|
console.timeEnd('getCandidatesList')
|
||||||
|
|
||||||
|
return selectedCandidates
|
||||||
}
|
}
|
||||||
|
|
||||||
// Takes a list of library items, and uses a prompt to generate
|
// Takes a list of library items, and uses a prompt to generate
|
||||||
@ -345,6 +355,7 @@ const chooseRankedSelections = (rankedCandidates: RankedItem[]) => {
|
|||||||
const summarizeItems = async (
|
const summarizeItems = async (
|
||||||
rankedCandidates: RankedItem[]
|
rankedCandidates: RankedItem[]
|
||||||
): Promise<RankedItem[]> => {
|
): Promise<RankedItem[]> => {
|
||||||
|
console.time('summarizeItems')
|
||||||
const llm = new OpenAI({
|
const llm = new OpenAI({
|
||||||
modelName: 'gpt-4-0125-preview',
|
modelName: 'gpt-4-0125-preview',
|
||||||
configuration: {
|
configuration: {
|
||||||
@ -370,6 +381,8 @@ const summarizeItems = async (
|
|||||||
(summary, index) => (rankedCandidates[index].summary = summary)
|
(summary, index) => (rankedCandidates[index].summary = summary)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
console.timeEnd('summarizeItems')
|
||||||
|
|
||||||
return rankedCandidates
|
return rankedCandidates
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,6 +391,7 @@ const generateSpeechFiles = (
|
|||||||
rankedItems: RankedItem[],
|
rankedItems: RankedItem[],
|
||||||
options: SSMLOptions
|
options: SSMLOptions
|
||||||
): SpeechFile[] => {
|
): SpeechFile[] => {
|
||||||
|
console.time('generateSpeechFiles')
|
||||||
// convert the summaries from markdown to HTML
|
// convert the summaries from markdown to HTML
|
||||||
const converter = new showdown.Converter({
|
const converter = new showdown.Converter({
|
||||||
backslashEscapesHTMLTags: true,
|
backslashEscapesHTMLTags: true,
|
||||||
@ -396,6 +410,8 @@ const generateSpeechFiles = (
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.timeEnd('generateSpeechFiles')
|
||||||
|
|
||||||
return speechFiles
|
return speechFiles
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,6 +450,8 @@ const generateByline = (summaries: RankedItem[]): string =>
|
|||||||
|
|
||||||
export const createDigest = async (jobData: CreateDigestData) => {
|
export const createDigest = async (jobData: CreateDigestData) => {
|
||||||
try {
|
try {
|
||||||
|
console.time('createDigestJob')
|
||||||
|
|
||||||
digestDefinition = await fetchDigestDefinition()
|
digestDefinition = await fetchDigestDefinition()
|
||||||
|
|
||||||
const candidates = await getCandidatesList(
|
const candidates = await getCandidatesList(
|
||||||
@ -511,5 +529,7 @@ export const createDigest = async (jobData: CreateDigestData) => {
|
|||||||
|
|
||||||
await sendMulticastPushNotifications(jobData.userId, message, 'reminder')
|
await sendMulticastPushNotifications(jobData.userId, message, 'reminder')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.timeEnd('createDigestJob')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user