Skip to content

Commit

Permalink
fix: simplified the result with [format]
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 12, 2023
1 parent a6b7fcc commit f343c59
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 26 deletions.
5 changes: 1 addition & 4 deletions components/SummaryResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ export function SummaryResult({
shouldShowTimestamp?: boolean;
}) {
const { toast } = useToast();
const { summaryArray, formattedSummary } = formatSummary(
summary,
shouldShowTimestamp
);
const { summaryArray, formattedSummary } = formatSummary(summary);
const summaryNote =
formattedSummary +
"\n\n #BibiGPT自动总结 b.jimmylv.cn @吕立青_JimmyLv \nBV1fX4y1Q7Ux";
Expand Down
15 changes: 7 additions & 8 deletions lib/openai/prompt.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { limitTranscriptByteLength } from "~/lib/openai/getSmallSizeTranscripts";
import { CommonSubtitleItem } from "~/lib/types";

interface PromptConfig {
language?: string;
Expand Down Expand Up @@ -56,7 +55,8 @@ export function getUserSubtitlePrompt(title: string, transcript: any) {
.replace(/\n+/g, " ")
.trim();
const language = `zh-CN`;
const prompt = `Your output should use the following template:\n### Summary\n### Highlights\n- [Emoji] Bulletpoint\n\nYour task is to summarise the text I have given you in up to seven concise bullet points, starting with a short highlight. Choose an appropriate emoji for each bullet point. Use the text above: {{Title}} {{Transcript}}.\n\n\nReply in ${language} Language.`;
const sentenceCount = `7`;
const prompt = `Your output should use the following template:\n### Summary\n### Highlights\n- [Emoji] Bulletpoint\n\nYour task is to summarise the text I have given you in up to ${sentenceCount} concise bullet points, starting with a short highlight. Choose an appropriate emoji for each bullet point. Use the text above: {{Title}} {{Transcript}}.\n\nReply in ${language} Language.`;

return `Title: "${videoTitle}"\nTranscript: "${videoTranscript}"\n\nInstructions: ${prompt}`;
}
Expand All @@ -66,13 +66,12 @@ export function getUserSubtitleWithTimestampPrompt(
transcript: any
) {
const videoTitle = title?.replace(/\n+/g, " ").trim();
console.log("========transcript========", transcript);
const videoTranscript = transcript.map((i: CommonSubtitleItem) => ({
start_time: i.index,
text: i.text,
}));
const videoTranscript = limitTranscriptByteLength(transcript)
.replace(/\n+/g, " ")
.trim();
const language = "Chinese";
const promptWithTimestamp = `Act as the author and provide exactly 5 bullet points all in ${language} language for the text transcript given in the format [{\"start_time\": <start_time>, \"text\": <text>}] \n and make the output only in the format of a json array [{\"start_time\": <start_time> , \"bullet_point\": <bullet_point>} ]\n Make sure that:\n - The output is not more than 5 bullet points\n - each bullet_point is at least 15 words and all bullet points are sorted by \"start_time\"\n - each bullet_point doesn't start with \"- \" or a number or a bullet point symbol\n - Wrap json keys with double quotes and don't put single quotes or double quotes inside the values. \n - The output json is not wrapped in any other json structure like { \"data\": <output json >}.`;
const sentenceCount = "7";
const promptWithTimestamp = `Act as the author and provide exactly 5 bullet points all in ${language} language for the text transcript given in the format [seconds] - [text] \nMake sure that:\n - Please start by summarizing the whole video in one short sentence\n - Then, please summarize with not more than ${sentenceCount} bullet points\n - each bullet_point is at least 15 words\n - each bullet_point start with \"- \" or a number or a bullet point symbol\n - each bullet_point should has the start timestamp, e.g. seconds - [Emoji] [bullet_point]\n - there may be typos in the subtitles, please correct them`;
const videoTranscripts = limitTranscriptByteLength(
JSON.stringify(videoTranscript)
);
Expand Down
2 changes: 1 addition & 1 deletion lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export enum VideoService {
export type CommonSubtitleItem = {
text: string;
index: number;
start_time?: number | string;
s?: number | string;
};
1 change: 1 addition & 0 deletions pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const Home: NextPage<{
};

function handleShowTimestamp(checked: boolean) {
resetSummary();
setShouldShowTimestamp(checked);
analytics
.track(`ShowTimestamp Clicked`, {
Expand Down
5 changes: 2 additions & 3 deletions pages/api/sumup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ export default async function handler(
// shouldShowTimestamp: subtitlesArray ? shouldShowTimestamp : false,
// });
// const examplePrompt = getExamplePrompt();
const userPrompt =
subtitlesArray && shouldShowTimestamp
? getUserSubtitleWithTimestampPrompt(title, subtitlesArray)
const userPrompt = shouldShowTimestamp
? getUserSubtitleWithTimestampPrompt(title, inputText)
: getUserSubtitlePrompt(title, inputText);
if (isDev) {
// console.log("final system prompt: ", systemPrompt);
Expand Down
14 changes: 5 additions & 9 deletions utils/formatSummary.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import { extractSentenceWithTimestamp } from "~/utils/extractSentenceWithTimestamp";
import { extractTimestamp } from "~/utils/extractTimestamp";

export function formatSummary(summary: string, shouldShowTimestamp?: boolean) {
export function formatSummary(summary: string) {
/*
if (shouldShowTimestamp) {
try {
const parsedBulletPoints = JSON.parse(summary);
const summaryArray = parsedBulletPoints.map(
({
start_time,
bullet_point,
}: {
start_time: number;
bullet_point: string;
}) => {
const startTime = start_time === 0 ? "0.0" : start_time;
({ s, bullet_point }: { s: number; bullet_point: string }) => {
const startTime = s === 0 ? "0.0" : s;
return startTime + " " + bullet_point;
}
);
Expand All @@ -26,6 +21,7 @@ export function formatSummary(summary: string, shouldShowTimestamp?: boolean) {
return {};
}
}
*/

const summaryArray = ("\n" + summary).split("\n- ");
const formattedSummary = summaryArray
Expand Down
2 changes: 1 addition & 1 deletion utils/reduceSubtitleTimestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function reduceSubtitleTimestamp<T>(
// 5.88 -> 5.9
// text: current.start.toFixed() + ": ",
index: groupIndex,
start_time: getStart(current),
s: getStart(current),
text: shouldShowTimestamp ? getStart(current) + " - " : ""
};
}
Expand Down

1 comment on commit f343c59

@vercel
Copy link

@vercel vercel bot commented on f343c59 Mar 12, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.