From 89d12da47a8795cd22812a62c048abb1750b767e Mon Sep 17 00:00:00 2001 From: root Date: Mon, 9 Dec 2024 15:09:28 +0000 Subject: [PATCH] YOLO modified: uncloseai.js --- uncloseai.js | 52 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/uncloseai.js b/uncloseai.js index f0466e2..6fea554 100644 --- a/uncloseai.js +++ b/uncloseai.js @@ -81,8 +81,8 @@ function extractWebpageContent() { // Function to read text using TTS async function speakText(text, voice = 'alloy', rate = 0.9) { try { - // Preprocess the text using Hermes to get spoken tokens - const spokenText = await processContentWithHermes(text); + // Preprocess the text using the new function to get spoken tokens + const spokenText = await extractSpokenTokens(text); const response = await fetch(TTS_API_URL, { method: 'POST', @@ -112,7 +112,7 @@ async function speakText(text, voice = 'alloy', rate = 0.9) { } } -// New function to process content using Hermes +// process page content using Hermes async function processContentWithHermes(content) { const payload = { model: MODEL, @@ -155,7 +155,7 @@ Ready? Breath and then return a stream of tokens to be used in a TTS system. max_tokens: 13000 }; - console.log("Sending payload to Hermes:", JSON.stringify(payload, null, 2)); + console.log("Sending payload to Hermes for spoken tokens:", JSON.stringify(payload, null, 2)); try { const response = await fetch(API_URL, { @@ -181,6 +181,50 @@ Ready? Breath and then return a stream of tokens to be used in a TTS system. } } +// New function to extract spoken tokens without altering content +async function extractSpokenTokens(content) { + const payload = { + model: MODEL, + messages: [ + { + role: "system", + content: `Extract the spoken tokens from the content without altering or summarizing it. Ensure that the spoken tokens match the content displayed on the screen. Skip any embedded advertisements.` + }, + { + role: "user", + content: content + } + ], + temperature: 0, + max_tokens: 13000 + }; + + console.log("Sending payload to Hermes for spoken tokens:", JSON.stringify(payload, null, 2)); + + try { + const response = await fetch(API_URL, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${API_KEY}` + }, + body: JSON.stringify(payload) + }); + + if (!response.ok) { + const errorText = await response.text(); + console.error(`HTTP error! status: ${response.status}`, errorText); + throw new Error(`HTTP error! status: ${response.status}`); + } + + const data = await response.json(); + return data.choices[0].message.content; + } catch (error) { + console.error('Error in extractSpokenTokens:', error); + throw error; + } +} + // Function to generate a title for TTS async function generateTitleForTTS(text) { const response = await fetch(API_URL, {