Skip to content

armgit / my-yt

Public Imported from GitHub
0

A clean and minimal youtube frontend, without all the ads and whistles

JavaScript

fix: callback when summarizing without error

Christian Feica4fbf6b43d8
diff --git a/lib/subtitles-summary.js b/lib/subtitles-summary.js
index 88445ff..aa3c9e7 100644
--- a/lib/subtitles-summary.js
+++ b/lib/subtitles-summary.js
@@ -12,7 +12,7 @@ export async function summarizeVideo (id, repo, llmSettings = {}, callback = ()
repo.setVideoTranscript(id, cleanedTranscript)
cleanedTranscript = cleanedTranscript.replace('\n', ' ')
fs.writeFileSync(`./data/videos/${id}.en.txt`, cleanedTranscript)
- callback(null, 'prompting llm') // eslint-disable-line
+ callback('prompting llm') // eslint-disable-line
const userPrompt = `
Extract the key points from the following video transcript:
@@ -23,12 +23,12 @@ ${cleanedTranscript}`.trim()
Begin by summarizing it into a single paragraph, followed by a longer summary that expands on the key points.
Do not describe or mention the video itself. Simply summarize the points it makes. Focus on the overall or underlying takeaway, cause, reason.`
const summary = await llm.summarize(systemPrompt, userPrompt, llmSettings)
- callback(null, 'received summary') // eslint-disable-line
+ callback('received summary') // eslint-disable-line
repo.setVideoSummary(id, summary)
resolve({ summary, transcript: cleanedTranscript })
} catch (error) {
console.error(`Error summarizing video ${id}: ${error.message}`)
- callback(error, `Error summarizing video ${id}: ${error.message}`)
+ callback(`Error summarizing video ${id}: ${error.message}`) // eslint-disable-line
reject(error)
}
}))
diff --git a/server/router/api.js b/server/router/api.js
index 19d1eff..d7291c5 100644
--- a/server/router/api.js
+++ b/server/router/api.js
@@ -137,12 +137,8 @@ async function summarizeVideoHandler (req, res, repo, connections = [], state =
state.summarizing = state.summarizing || {}
state.summarizing[id] = { lines: [] }
- summarizeVideo(id, repo, llmSettings, (err, line) => {
- if (err) {
- broadcastSSE(JSON.stringify({ type: 'download-log-line', line: `Error summarizing video ${id}: ${err.message}` }), connections)
- } else {
- broadcastSSE(JSON.stringify({ type: 'download-log-line', line }), connections)
- }
+ summarizeVideo(id, repo, llmSettings, (line) => {
+ broadcastSSE(JSON.stringify({ type: 'download-log-line', line }), connections)
})
.then(({ summary, transcript }) =>
broadcastSSE(JSON.stringify({ type: 'summary', summary, transcript, videoId: id }), connections))