🐞 fix: 修复哔哩哔哩总结的部分问题

This commit is contained in:
zhiyu1998 2023-03-24 09:01:26 +08:00
parent 1000d21e2f
commit 261184086d
2 changed files with 11 additions and 2 deletions

View File

@ -353,7 +353,13 @@ export class tools extends plugin {
// 如果有ck 并且 有openai的key // 如果有ck 并且 有openai的key
if (this.biliSessData && this.openaiApiKey) { if (this.biliSessData && this.openaiApiKey) {
const prompt = await getBiliGptInputText(title, aid, cid); let prompt;
try {
prompt = await getBiliGptInputText(title, aid, cid);
} catch (err) {
logger.error("总结失败,可能是没有弹幕或者网络问题!");
return true;
}
const response = await this.chatGptClient.sendMessage(prompt); const response = await this.chatGptClient.sendMessage(prompt);
// 暂时不设计上下文 // 暂时不设计上下文
e.reply(response.response); e.reply(response.response);

View File

@ -28,7 +28,10 @@ export async function getBiliGptInputText(title, aid, cid, shouldShowTimestamp =
commonConfig, commonConfig,
); );
const subtitles = (await resp.json()).data.subtitle.subtitles; const subtitles = (await resp.json()).data.subtitle.subtitles;
const res = await fetch(`http:${subtitles[0].subtitle_url}`); const res = await fetch(`http:${subtitles[0]?.subtitle_url}`);
if (_.isUndefined(res)) {
throw new Error("");
}
const subtitlesData = (await res.json()).body; const subtitlesData = (await res.json()).body;
const subtitleTimestamp = reduceBilibiliSubtitleTimestamp(subtitlesData, shouldShowTimestamp); const subtitleTimestamp = reduceBilibiliSubtitleTimestamp(subtitlesData, shouldShowTimestamp);
const inputText = getSmallSizeTranscripts(subtitleTimestamp, subtitleTimestamp); const inputText = getSmallSizeTranscripts(subtitleTimestamp, subtitleTimestamp);