Skip to content

Commit 5856fd9

Browse files
committed
Bumped ai-chat-apis.json, utilized parsingRequired
1 parent 556cbfe commit 5856fd9

File tree

4 files changed

+172
-156
lines changed

4 files changed

+172
-156
lines changed

amazongpt/greasemonkey/amazongpt.user.js

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @description Adds the magic of AI to Amazon shopping
44
// @author KudoAI
55
// @namespace https://kudoai.com
6-
// @version 2025.1.26.1
6+
// @version 2025.1.26.2
77
// @license MIT
88
// @icon https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon48.png?v=0fddfc7
99
// @icon64 https://amazongpt.kudoai.com/assets/images/icons/amazongpt/black-gold-teal/icon64.png?v=0fddfc7
@@ -226,7 +226,7 @@
226226

227227
// Init API data
228228
const apis = Object.assign(Object.create(null), await new Promise(resolve => xhr({
229-
method: 'GET', url: 'https://assets.aiwebextensions.com/data/ai-chat-apis.json?v=b529a64',
229+
method: 'GET', url: 'https://assets.aiwebextensions.com/data/ai-chat-apis.json?v=556cbfe',
230230
onload: resp => resolve(JSON.parse(resp.responseText))
231231
})))
232232
apis.AIchatOS.userID = '#/chat/' + Date.now()
@@ -2655,25 +2655,27 @@
26552655
clearTimeout(this.timeout) ; this.timeout = setTimeout(handleProcessCompletion, 1500) }
26562656

26572657
// Process/accumulate reply chunk
2658-
let replyChunk = ''
2659-
if (callerAPI == 'GPTforLove') { // extract parentID + deltas
2660-
const chunkObjs = respChunk.trim().split('\n').map(line => JSON.parse(line))
2661-
if (typeof chunkObjs[0].text == 'undefined') // error response
2662-
replyChunk = JSON.stringify(chunkObjs[0]) // for fail flag check
2663-
else { // AI response
2664-
apis.GPTforLove.parentID = chunkObjs[0].id || null // for contextual replies
2665-
chunkObjs.forEach(obj => replyChunk += obj.delta || '') // accumulate AI reply text
2666-
if (respChunk.includes('"finish_reason":"stop"')) isDone = true
2667-
}
2668-
} else if (callerAPI == 'MixerBox AI') { // extract/normalize AI reply data
2669-
replyChunk = [...respChunk.matchAll(/data:(.*)/g)] // arrayify data
2670-
.filter(match => !/message_(?:start|end)|done/.test(match)) // exclude signals
2671-
.map(match => // normalize whitespace
2672-
match[1].replace(/\[SPACE\]/g, ' ').replace(/\[NEWLINE\]/g, '\n'))
2673-
.join('') // stringify AI reply text
2674-
if (/data:(?:message_end|done)/.test(respChunk)) isDone = true
2675-
} else replyChunk = respChunk // no processing required for all other APIs
2676-
textToShow += replyChunk
2658+
if (!apis[callerAPI].parsingRequired) textToShow += respChunk
2659+
else { // parse structured chunk(s)
2660+
let replyChunk = ''
2661+
if (callerAPI == 'GPTforLove') { // extract parentID + deltas
2662+
const chunkObjs = respChunk.trim().split('\n').map(line => JSON.parse(line))
2663+
if (typeof chunkObjs[0].text == 'undefined') // error response
2664+
replyChunk = JSON.stringify(chunkObjs[0]) // for fail flag check
2665+
else { // AI response
2666+
apis.GPTforLove.parentID = chunkObjs[0].id || null // for contextual replies
2667+
chunkObjs.forEach(obj => replyChunk += obj.delta || '') // accumulate AI reply text
2668+
if (respChunk.includes('"finish_reason":"stop"')) isDone = true
2669+
}
2670+
} else if (callerAPI == 'MixerBox AI') { // extract/normalize AI reply data
2671+
replyChunk = [...respChunk.matchAll(/data:(.*)/g)] // arrayify data
2672+
.filter(match => !/message_(?:start|end)|done/.test(match)) // exclude signals
2673+
.map(match => // normalize whitespace
2674+
match[1].replace(/\[SPACE\]/g, ' ').replace(/\[NEWLINE\]/g, '\n'))
2675+
.join('') // stringify AI reply text
2676+
if (/data:(?:message_end|done)/.test(respChunk)) isDone = true
2677+
} textToShow += replyChunk
2678+
}
26772679

26782680
// Show accumulated reply chunks
26792681
try {
@@ -2737,24 +2739,26 @@
27372739
} catch (err) { handleProcessError(err) }
27382740
}
27392741
} else if (resp.responseText) { // show response from proxy API
2740-
if (callerAPI == 'GPTforLove') {
2741-
try {
2742-
const chunkLines = resp.responseText.trim().split('\n'),
2743-
lastChunkObj = JSON.parse(chunkLines[chunkLines.length -1])
2744-
apis.GPTforLove.parentID = lastChunkObj.id || null
2745-
textToShow = lastChunkObj.text ; handleProcessCompletion()
2746-
} catch (err) { handleProcessError(err) }
2747-
} else if (callerAPI == 'MixerBox AI') {
2748-
try {
2749-
textToShow = [...resp.responseText.matchAll(/data:(.*)/g)] // arrayify data
2750-
.filter(match => !/message_(?:start|end)|done/.test(match)) // exclude signals
2751-
.map(match => // normalize whitespace
2752-
match[1].replace(/\[SPACE\]/g, ' ').replace(/\[NEWLINE\]/g, '\n'))
2753-
.join('') // stringify AI reply text
2754-
handleProcessCompletion()
2755-
} catch (err) { handleProcessError(err) }
2756-
} else { // no processing required for all other APIs
2757-
textToShow = resp.responseText ; handleProcessCompletion() }
2742+
if (!apis[callerAPI].parsingRequired) { textToShow = resp.responseText ; handleProcessCompletion }
2743+
else { // parse structured responseText
2744+
if (callerAPI == 'GPTforLove') {
2745+
try {
2746+
const chunkLines = resp.responseText.trim().split('\n'),
2747+
lastChunkObj = JSON.parse(chunkLines[chunkLines.length -1])
2748+
apis.GPTforLove.parentID = lastChunkObj.id || null
2749+
textToShow = lastChunkObj.text ; handleProcessCompletion()
2750+
} catch (err) { handleProcessError(err) }
2751+
} else if (callerAPI == 'MixerBox AI') {
2752+
try {
2753+
textToShow = [...resp.responseText.matchAll(/data:(.*)/g)] // arrayify data
2754+
.filter(match => !/message_(?:start|end)|done/.test(match)) // exclude signals
2755+
.map(match => // normalize whitespace
2756+
match[1].replace(/\[SPACE\]/g, ' ').replace(/\[NEWLINE\]/g, '\n'))
2757+
.join('') // stringify AI reply text
2758+
handleProcessCompletion()
2759+
} catch (err) { handleProcessError(err) }
2760+
}
2761+
}
27582762
} else if (caller.status != 'done') { // proxy 200 response failure
27592763
log.info('Response text', resp.responseText) ; api.tryNew(caller) }
27602764

bravegpt/greasemonkey/bravegpt.user.js

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
// @description:zu Yengeza izimpendulo ze-AI ku-Brave Search (inikwa amandla yi-GPT-4o!)
149149
// @author KudoAI
150150
// @namespace https://kudoai.com
151-
// @version 2025.1.26.1
151+
// @version 2025.1.26.2
152152
// @license MIT
153153
// @icon https://assets.bravegpt.com/images/icons/bravegpt/icon48.png?v=df624b0
154154
// @icon64 https://assets.bravegpt.com/images/icons/bravegpt/icon64.png?v=df624b0
@@ -380,7 +380,7 @@
380380

381381
// Init API data
382382
const apis = Object.assign(Object.create(null), await new Promise(resolve => xhr({
383-
method: 'GET', url: 'https://assets.aiwebextensions.com/data/ai-chat-apis.json?v=b529a64',
383+
method: 'GET', url: 'https://assets.aiwebextensions.com/data/ai-chat-apis.json?v=556cbfe',
384384
onload: resp => resolve(JSON.parse(resp.responseText))
385385
})))
386386
apis.AIchatOS.userID = '#/chat/' + Date.now()
@@ -3405,25 +3405,27 @@
34053405
clearTimeout(this.timeout) ; this.timeout = setTimeout(handleProcessCompletion, 1500) }
34063406

34073407
// Process/accumulate reply chunk
3408-
let replyChunk = ''
3409-
if (callerAPI == 'GPTforLove') { // extract parentID + deltas
3410-
const chunkObjs = respChunk.trim().split('\n').map(line => JSON.parse(line))
3411-
if (typeof chunkObjs[0].text == 'undefined') // error response
3412-
replyChunk = JSON.stringify(chunkObjs[0]) // for fail flag check
3413-
else { // AI response
3414-
apis.GPTforLove.parentID = chunkObjs[0].id || null // for contextual replies
3415-
chunkObjs.forEach(obj => replyChunk += obj.delta || '') // accumulate AI reply text
3416-
if (respChunk.includes('"finish_reason":"stop"')) isDone = true
3417-
}
3418-
} else if (callerAPI == 'MixerBox AI') { // extract/normalize AI reply data
3419-
replyChunk = [...respChunk.matchAll(/data:(.*)/g)] // arrayify data
3420-
.filter(match => !/message_(?:start|end)|done/.test(match)) // exclude signals
3421-
.map(match => // normalize whitespace
3422-
match[1].replace(/\[SPACE\]/g, ' ').replace(/\[NEWLINE\]/g, '\n'))
3423-
.join('') // stringify AI reply text
3424-
if (/data:(?:message_end|done)/.test(respChunk)) isDone = true
3425-
} else replyChunk = respChunk // no processing required for all other APIs
3426-
textToShow += replyChunk
3408+
if (!apis[callerAPI].parsingRequired) textToShow += respChunk
3409+
else { // parse structured chunk(s)
3410+
let replyChunk = ''
3411+
if (callerAPI == 'GPTforLove') { // extract parentID + deltas
3412+
const chunkObjs = respChunk.trim().split('\n').map(line => JSON.parse(line))
3413+
if (typeof chunkObjs[0].text == 'undefined') // error response
3414+
replyChunk = JSON.stringify(chunkObjs[0]) // for fail flag check
3415+
else { // AI response
3416+
apis.GPTforLove.parentID = chunkObjs[0].id || null // for contextual replies
3417+
chunkObjs.forEach(obj => replyChunk += obj.delta || '') // accumulate AI reply text
3418+
if (respChunk.includes('"finish_reason":"stop"')) isDone = true
3419+
}
3420+
} else if (callerAPI == 'MixerBox AI') { // extract/normalize AI reply data
3421+
replyChunk = [...respChunk.matchAll(/data:(.*)/g)] // arrayify data
3422+
.filter(match => !/message_(?:start|end)|done/.test(match)) // exclude signals
3423+
.map(match => // normalize whitespace
3424+
match[1].replace(/\[SPACE\]/g, ' ').replace(/\[NEWLINE\]/g, '\n'))
3425+
.join('') // stringify AI reply text
3426+
if (/data:(?:message_end|done)/.test(respChunk)) isDone = true
3427+
} textToShow += replyChunk
3428+
}
34273429

34283430
// Show accumulated reply chunks
34293431
try {
@@ -3488,24 +3490,26 @@
34883490
} catch (err) { handleProcessError(err) }
34893491
}
34903492
} else if (resp.responseText) { // show response or return RQs from proxy API
3491-
if (callerAPI == 'GPTforLove') {
3492-
try {
3493-
const chunkLines = resp.responseText.trim().split('\n'),
3494-
lastChunkObj = JSON.parse(chunkLines[chunkLines.length -1])
3495-
apis.GPTforLove.parentID = lastChunkObj.id || null
3496-
textToShow = lastChunkObj.text ; handleProcessCompletion()
3497-
} catch (err) { handleProcessError(err) }
3498-
} else if (callerAPI == 'MixerBox AI') {
3499-
try {
3500-
textToShow = [...resp.responseText.matchAll(/data:(.*)/g)] // arrayify data
3501-
.filter(match => !/message_(?:start|end)|done/.test(match)) // exclude signals
3502-
.map(match => // normalize whitespace
3503-
match[1].replace(/\[SPACE\]/g, ' ').replace(/\[NEWLINE\]/g, '\n'))
3504-
.join('') // stringify AI reply text
3505-
handleProcessCompletion()
3506-
} catch (err) { handleProcessError(err) }
3507-
} else { // no processing required for all other APIs
3508-
textToShow = resp.responseText ; handleProcessCompletion() }
3493+
if (!apis[callerAPI].parsingRequired) { textToShow = resp.responseText ; handleProcessCompletion }
3494+
else { // parse structured responseText
3495+
if (callerAPI == 'GPTforLove') {
3496+
try {
3497+
const chunkLines = resp.responseText.trim().split('\n'),
3498+
lastChunkObj = JSON.parse(chunkLines[chunkLines.length -1])
3499+
apis.GPTforLove.parentID = lastChunkObj.id || null
3500+
textToShow = lastChunkObj.text ; handleProcessCompletion()
3501+
} catch (err) { handleProcessError(err) }
3502+
} else if (callerAPI == 'MixerBox AI') {
3503+
try {
3504+
textToShow = [...resp.responseText.matchAll(/data:(.*)/g)] // arrayify data
3505+
.filter(match => !/message_(?:start|end)|done/.test(match)) // exclude signals
3506+
.map(match => // normalize whitespace
3507+
match[1].replace(/\[SPACE\]/g, ' ').replace(/\[NEWLINE\]/g, '\n'))
3508+
.join('') // stringify AI reply text
3509+
handleProcessCompletion()
3510+
} catch (err) { handleProcessError(err) }
3511+
}
3512+
}
35093513
} else if (caller.status != 'done') { // proxy 200 response failure
35103514
log.info('Response text', resp.responseText) ; api.tryNew(caller) }
35113515

0 commit comments

Comments
 (0)