Skip to content

Commit

Permalink
fix: improve the timestamp by group
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 8, 2023
1 parent 587e48e commit aa3fb66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion lib/openai/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function getSummaryPrompt(title: string, transcript: any, promptConfig: P
console.log('prompt ', promptConfig);
const { language = '中文', shouldShowTimestamp } = promptConfig
const betterPrompt = `我希望你是一名专业的视频内容编辑,帮我用${language}总结视频的内容精华。请你将视频字幕文本进行总结,然后以无序列表的方式返回,不要超过5条。记得不要重复句子,确保所有的句子都足够精简,清晰完整,祝你好运!`
const promptWithTimestamp = `我希望你是一名专业的视频内容编辑,帮我用${language}总结视频的内容精华。请先用一句简短的话总结视频梗概。然后再请你将视频字幕文本进行总结,在每句话的最前面加上时间戳(类似 10:24),每句话开头只需要一个开始时间。请你以无序列表的方式返回,请注意不要超过5条哦,确保所有的句子都足够精简,清晰完整,祝你好运!`;
const timestamp = '' //`(类似 10:24)`;
const promptWithTimestamp = `我希望你是一名专业的视频内容编辑,帮我用${language}总结视频的内容精华。请先用一句简短的话总结视频梗概。然后再请你将视频字幕文本进行总结,在每句话的最前面加上时间戳${timestamp},每句话开头只需要一个开始时间。请你以无序列表的方式返回,请注意不要超过5条哦,确保所有的句子都足够精简,清晰完整,祝你好运!`;

return `标题: "${title
?.replace(/\n+/g, " ")
Expand Down
10 changes: 5 additions & 5 deletions utils/reduceSubtitleTimestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export function reduceSubtitleTimestamp<T>(
getText: (i: T) => string
): Array<CommonSubtitleItem> {
// 把字幕数组总共分成 20 组
const TOTAL_GROUP_COUNT = 20;
// 如果字幕不够多,就每三组合并一下
const MINIMUM_COUNT_ONE_GROUP = 3;
const TOTAL_GROUP_COUNT = 30;
// 如果字幕不够多,就每5句话合并一下
const MINIMUM_COUNT_ONE_GROUP = 5;
const eachGroupCount =
subtitles.length > TOTAL_GROUP_COUNT
? subtitles.length / TOTAL_GROUP_COUNT
Expand All @@ -40,14 +40,14 @@ export function reduceSubtitleTimestamp<T>(
return subtitles.reduce(
(accumulator: CommonSubtitleItem[], current: T, index: number) => {
// 计算当前元素在哪一组
const groupIndex: number = Math.floor(index / eachGroupCount);
const groupIndex: number = Math.floor(index / MINIMUM_COUNT_ONE_GROUP);

// 如果是当前组的第一个元素,初始化这一组的字符串
if (!accumulator[groupIndex]) {
accumulator[groupIndex] = {
// 5.88 -> 5.9
// text: current.start.toFixed() + ": ",
text: getStart(current) + ": ",
text: getStart(current) + " - ",
index: groupIndex,
};
}
Expand Down

1 comment on commit aa3fb66

@vercel
Copy link

@vercel vercel bot commented on aa3fb66 Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please # to comment.