Skip to content

Commit

Permalink
Eliminated no-longer needed merging of API URLs w/ fail flags
Browse files Browse the repository at this point in the history
  • Loading branch information
adamlui committed Jan 26, 2025
1 parent 5b3702f commit f73c6d9
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 48 deletions.
19 changes: 7 additions & 12 deletions amazongpt/greasemonkey/amazongpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// @description Adds the magic of AI to Amazon shopping
// @author KudoAI
// @namespace https://kudoai.com
// @version 2025.1.26.8
// @version 2025.1.26.9
// @license MIT
// @icon https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon48.png?v=0fddfc7
// @icon64 https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon64.png?v=0fddfc7
Expand Down Expand Up @@ -2635,17 +2635,12 @@

const dataProcess = {

initFailFlags(api) { // escape/merge URLs w/ fail flags
const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api],
escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|'))
},
initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null },

stream(resp, { caller, callerAPI }) {
if (config.streamingDisabled || !config.proxyAPIenabled) return
log.caller = `get.${caller.name}() » dataProcess.stream()`
const failFlagsAndURLs = this.initFailFlags(callerAPI),
reader = resp.response.getReader()
const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI)
let textToShow = '', isDone = false
reader.read().then(chunk => handleChunk(chunk, callerAPI))
.catch(err => log.error('Error processing stream', err.message))
Expand Down Expand Up @@ -2683,7 +2678,7 @@

// Show accumulated reply chunks
try {
const failMatch = failFlagsAndURLs.exec(textToShow)
const failMatch = reFailFlags?.exec(textToShow)
if (failMatch) {
log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion()
Expand Down Expand Up @@ -2721,7 +2716,7 @@
if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled
|| caller.status == 'done') return
log.caller = `get.${caller.name}() » dataProcess.text()`
const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = ''
const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = ''
if (resp.status != 200) {
log.error('Response status', resp.status)
log.info('Response text', resp.response || resp.responseText)
Expand All @@ -2732,7 +2727,7 @@
: ['openAInotWorking', 'suggestProxy'] )
else api.tryNew(caller)
} else if (callerAPI == 'OpenAI' && resp.response) { // show response from OpenAI
const failMatch = failFlagsAndURLs.exec(resp.response)
const failMatch = reFailFlags?.exec(resp.response)
if (failMatch) { // suggest proxy
log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
appAlert('openAInotWorking', 'suggestProxy')
Expand Down Expand Up @@ -2769,7 +2764,7 @@
function handleProcessCompletion() {
if (caller.status != 'done') {
log.debug('Text to show', textToShow)
const failMatch = failFlagsAndURLs.exec(textToShow)
const failMatch = reFailFlags?.exec(textToShow)
if (!textToShow || failMatch) {
if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`)
api.tryNew(caller)
Expand Down
19 changes: 7 additions & 12 deletions bravegpt/greasemonkey/bravegpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
// @description:zu Yengeza izimpendulo ze-AI ku-Brave Search (inikwa amandla yi-GPT-4o!)
// @author KudoAI
// @namespace https://kudoai.com
// @version 2025.1.26.8
// @version 2025.1.26.9
// @license MIT
// @icon https://assets.bravegpt.com/images/icons/bravegpt/icon48.png?v=df624b0
// @icon64 https://assets.bravegpt.com/images/icons/bravegpt/icon64.png?v=df624b0
Expand Down Expand Up @@ -3385,17 +3385,12 @@

const dataProcess = {

initFailFlags(api) { // escape/merge URLs w/ fail flags
const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api],
escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|'))
},
initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null },

stream(resp, { caller, callerAPI }) {
if (config.streamingDisabled || !config.proxyAPIenabled) return
log.caller = `get.${caller.name}() » dataProcess.stream()`
const failFlagsAndURLs = this.initFailFlags(callerAPI),
reader = resp.response.getReader()
const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI)
let textToShow = '', isDone = false
reader.read().then(chunk => handleChunk(chunk, callerAPI))
.catch(err => log.error('Error processing stream', err.message))
Expand Down Expand Up @@ -3433,7 +3428,7 @@

// Show accumulated reply chunks
try {
const failMatch = failFlagsAndURLs.exec(textToShow)
const failMatch = reFailFlags?.exec(textToShow)
if (failMatch) {
log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion()
Expand Down Expand Up @@ -3471,7 +3466,7 @@
if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled
|| caller.status == 'done') return
log.caller = `get.${caller.name}() » dataProcess.text()`
const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = ''
const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = ''
if (resp.status != 200) {
log.error('Response status', resp.status)
log.info('Response text', resp.response || resp.responseText)
Expand All @@ -3482,7 +3477,7 @@
: ['openAInotWorking', 'suggestProxy'] )
else api.tryNew(caller)
} else if (callerAPI == 'OpenAI' && resp.response) { // show response or return RQs from OpenAI
const failMatch = failFlagsAndURLs.exec(resp.response)
const failMatch = reFailFlags?.exec(resp.response)
if (failMatch) { // suggest proxy or try diff API
log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
if (caller == get.reply) appAlert('openAInotWorking', 'suggestProxy')
Expand Down Expand Up @@ -3520,7 +3515,7 @@
function handleProcessCompletion() {
if (caller.status != 'done') {
log.debug('Text to show', textToShow)
const failMatch = failFlagsAndURLs.exec(textToShow)
const failMatch = reFailFlags?.exec(textToShow)
if (!textToShow || failMatch) {
if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`)
api.tryNew(caller)
Expand Down
19 changes: 7 additions & 12 deletions duckduckgpt/greasemonkey/duckduckgpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
// @description:zu Yengeza izimpendulo ze-AI ku-DuckDuckGo (inikwa amandla yi-GPT-4o!)
// @author KudoAI
// @namespace https://kudoai.com
// @version 2025.1.26.8
// @version 2025.1.26.9
// @license MIT
// @icon https://assets.ddgpt.com/images/icons/duckduckgpt/icon48.png?v=06af076
// @icon64 https://assets.ddgpt.com/images/icons/duckduckgpt/icon64.png?v=06af076
Expand Down Expand Up @@ -3269,17 +3269,12 @@

const dataProcess = {

initFailFlags(api) { // escape/merge URLs w/ fail flags
const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api],
escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|'))
},
initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null },

stream(resp, { caller, callerAPI }) {
if (config.streamingDisabled || !config.proxyAPIenabled) return
log.caller = `get.${caller.name}() » dataProcess.stream()`
const failFlagsAndURLs = this.initFailFlags(callerAPI),
reader = resp.response.getReader()
const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI)
let textToShow = '', isDone = false
reader.read().then(chunk => handleChunk(chunk, callerAPI))
.catch(err => log.error('Error processing stream', err.message))
Expand Down Expand Up @@ -3317,7 +3312,7 @@

// Show accumulated reply chunks
try {
const failMatch = failFlagsAndURLs.exec(textToShow)
const failMatch = reFailFlags?.exec(textToShow)
if (failMatch) {
log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion()
Expand Down Expand Up @@ -3355,7 +3350,7 @@
if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled
|| caller.status == 'done') return
log.caller = `get.${caller.name}() » dataProcess.text()`
const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = ''
const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = ''
if (resp.status != 200) {
log.error('Response status', resp.status)
log.info('Response text', resp.response || resp.responseText)
Expand All @@ -3366,7 +3361,7 @@
: ['openAInotWorking', 'suggestProxy'] )
else api.tryNew(caller)
} else if (callerAPI == 'OpenAI' && resp.response) { // show response or return RQs from OpenAI
const failMatch = failFlagsAndURLs.exec(resp.response)
const failMatch = reFailFlags?.exec(resp.response)
if (failMatch) { // suggest proxy or try diff API
log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
if (caller == get.reply) appAlert('openAInotWorking', 'suggestProxy')
Expand Down Expand Up @@ -3404,7 +3399,7 @@
function handleProcessCompletion() {
if (caller.status != 'done') {
log.debug('Text to show', textToShow)
const failMatch = failFlagsAndURLs.exec(textToShow)
const failMatch = reFailFlags?.exec(textToShow)
if (!textToShow || failMatch) {
if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`)
api.tryNew(caller)
Expand Down
19 changes: 7 additions & 12 deletions googlegpt/greasemonkey/googlegpt.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
// @description:zu Yengeza izimpendulo ze-AI ku-Google Search (inikwa amandla yi-Google Gemma + GPT-4o!)
// @author KudoAI
// @namespace https://kudoai.com
// @version 2025.1.26.8
// @version 2025.1.26.9
// @license MIT
// @icon https://assets.googlegpt.io/images/icons/googlegpt/black/icon48.png?v=59409b2
// @icon64 https://assets.googlegpt.io/images/icons/googlegpt/black/icon64.png?v=59409b2
Expand Down Expand Up @@ -3566,17 +3566,12 @@

const dataProcess = {

initFailFlags(api) { // escape/merge URLs w/ fail flags
const { respPatterns = {}, endpoint = apis[api].endpoints.completions, expectedOrigin } = apis[api],
escapedAPIurls = [endpoint, expectedOrigin.url].map(url => url.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
return new RegExp([respPatterns.fail, ...escapedAPIurls].filter(Boolean).join('|'))
},
initFailFlags(api) { return apis[api].respPatterns?.fail ? new RegExp(apis[api].respPatterns.fail) : null },

stream(resp, { caller, callerAPI }) {
if (config.streamingDisabled || !config.proxyAPIenabled) return
log.caller = `get.${caller.name}() » dataProcess.stream()`
const failFlagsAndURLs = this.initFailFlags(callerAPI),
reader = resp.response.getReader()
const reader = resp.response.getReader(), reFailFlags = this.initFailFlags(callerAPI)
let textToShow = '', isDone = false
reader.read().then(chunk => handleChunk(chunk, callerAPI))
.catch(err => log.error('Error processing stream', err.message))
Expand Down Expand Up @@ -3614,7 +3609,7 @@

// Show accumulated reply chunks
try {
const failMatch = failFlagsAndURLs.exec(textToShow)
const failMatch = reFailFlags?.exec(textToShow)
if (failMatch) {
log.debug('Text to show', textToShow) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
if (env.browser.isChromium) clearTimeout(this.timeout) // skip handleProcessCompletion()
Expand Down Expand Up @@ -3652,7 +3647,7 @@
if (caller == get.reply && config.proxyAPIenabled && !config.streamingDisabled
|| caller.status == 'done') return
log.caller = `get.${caller.name}() » dataProcess.text()`
const failFlagsAndURLs = this.initFailFlags(callerAPI) ; let textToShow = ''
const reFailFlags = this.initFailFlags(callerAPI) ; let textToShow = ''
if (resp.status != 200) {
log.error('Response status', resp.status)
log.info('Response text', resp.response || resp.responseText)
Expand All @@ -3663,7 +3658,7 @@
: ['openAInotWorking', 'suggestProxy'] )
else api.tryNew(caller)
} else if (callerAPI == 'OpenAI' && resp.response) { // show response or return RQs from OpenAI
const failMatch = failFlagsAndURLs.exec(resp.response)
const failMatch = reFailFlags?.exec(resp.response)
if (failMatch) { // suggest proxy or try diff API
log.debug('Response text', resp.response) ; log.error('Fail flag detected', `'${failMatch[0]}'`)
if (caller == get.reply) appAlert('openAInotWorking', 'suggestProxy')
Expand Down Expand Up @@ -3701,7 +3696,7 @@
function handleProcessCompletion() {
if (caller.status != 'done') {
log.debug('Text to show', textToShow)
const failMatch = failFlagsAndURLs.exec(textToShow)
const failMatch = reFailFlags?.exec(textToShow)
if (!textToShow || failMatch) {
if (failMatch) log.error('Fail flag detected', `'${failMatch[0]}'`)
api.tryNew(caller)
Expand Down

0 comments on commit f73c6d9

Please sign in to comment.