mirror of
https://github.com/wassname/chatGPTBox.git
synced 2026-07-01 18:37:43 +08:00
change youtube/index.mjs to not confuse chatgpt or run out of tokens (#205 @iamsirsammy)
* change youtube/index.mjs to not confuse chatgpt or run out of tokens * Update index.mjs
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { cropText } from '../../../utils'
|
||||
import { config } from '../index.mjs'
|
||||
|
||||
function replaceHtmlEntities(htmlString) { // This function was written by ChatGPT and modified by me (iamsirsammy)
|
||||
const doc = new DOMParser().parseFromString(htmlString.replace("&", "&"), 'text/html');
|
||||
return doc.documentElement.innerText;
|
||||
}
|
||||
|
||||
export default {
|
||||
init: async (hostname, userConfig, getInput, mountComponent) => {
|
||||
try {
|
||||
@@ -41,12 +46,14 @@ export default {
|
||||
let subtitleContent = ''
|
||||
while (subtitleData.indexOf('">') !== -1) {
|
||||
subtitleData = subtitleData.substring(subtitleData.indexOf('">') + 2)
|
||||
subtitleContent += subtitleData.substring(0, subtitleData.indexOf('<')) + ','
|
||||
subtitleContent += subtitleData.substring(0, subtitleData.indexOf('<')) + ' '
|
||||
}
|
||||
|
||||
subtitleContent = replaceHtmlEntities(subtitleContent)
|
||||
|
||||
return cropText(
|
||||
`Provide a brief summary of the video using concise language and incorporating the video title.` +
|
||||
`The video title is:"${title}".The subtitle content is as follows:\n${subtitleContent}`,
|
||||
`Provide a brief summary of the following video using concise language, still including all the important details, and incorporating the video title.` +
|
||||
`The video title is "${title}". The subtitle content is as follows:\n${subtitleContent}`,
|
||||
)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
|
||||
Reference in New Issue
Block a user