Skip to content

Commit

Permalink
feat: use better subtitle
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyLv committed Mar 2, 2023
1 parent 6cd52a0 commit 66514ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pages/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ export const Home: NextPage = () => {
<h3 className="m-8 mx-auto max-w-3xl border-t border-gray-600 pt-8 text-center text-2xl font-bold sm:text-4xl">
<a
href={curVideo}
className="hover:text-pink-600"
className="hover:text-pink-600 hover:underline"
target="_blank"
rel="noreferrer"
>
Expand Down
13 changes: 8 additions & 5 deletions pages/api/summarize.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { find } from "lodash";
import { NextResponse } from "next/server";
import { Redis } from "@upstash/redis";
import type { NextFetchEvent, NextRequest } from "next/server";
Expand Down Expand Up @@ -35,13 +36,14 @@ export default async function handler(
const res = await response.json();
// @ts-ignore
const title = res.data?.title;
const subtitleUrl = res.data?.subtitle?.list?.[0]?.subtitle_url;
apiKey && console.log("========use user key========");
console.log("bvid", bvId);
console.log("subtitle_url", subtitleUrl);
if (!subtitleUrl) {
const subtitleList = res.data?.subtitle?.list;
if (subtitleList && subtitleList.length < 1) {
return new Response("No subtitle in the video", { status: 501 });
}
const betterSubtitle = find(subtitleList, { lan: "zh-CN" }) || subtitleList?.[0]
const subtitleUrl = betterSubtitle?.subtitle_url;
console.log("bvid", bvId);
console.log("subtitle_url", subtitleUrl);

const subtitleResponse = await fetch(subtitleUrl);
const subtitles = await subtitleResponse.json();
Expand All @@ -57,6 +59,7 @@ export default async function handler(
const text = getChunckedTranscripts(transcripts, transcripts);
const prompt = getSummaryPrompt(title, text);

apiKey && console.log("========use user key========");
const payload = {
model: "gpt-3.5-turbo",
messages: [{ role: "user" as const, content: prompt }],
Expand Down

0 comments on commit 66514ef

Please sign in to comment.