Skip to content

Commit 89fd351

Browse files
committed
Fixed GPTforLove API stopped working ↞ [auto-sync from https://github.com/adamlui/ai-web-extensions/tree/main/duckduckgpt]
1 parent 619a111 commit 89fd351

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

chatgpt/duckduckgpt/duckduckgpt.user.js

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
// @description:zu Yengeza izimpendulo ze-AI ku-DuckDuckGo (inikwa amandla yi-GPT-4o!)
149149
// @author KudoAI
150150
// @namespace https://kudoai.com
151-
// @version 2025.1.13.6
151+
// @version 2025.1.14
152152
// @license MIT
153153
// @icon https://assets.ddgpt.com/images/icons/duckduckgpt/icon48.png?v=06af076
154154
// @icon64 https://assets.ddgpt.com/images/icons/duckduckgpt/icon64.png?v=06af076
@@ -595,7 +595,7 @@
595595
'GPTforLove': {
596596
endpoint: 'https://api11.gptforlove.com/chat-process',
597597
expectedOrigin: {
598-
url: 'https://ai27.gptforlove.com',
598+
url: 'https://ai28.gptforlove.com',
599599
headers: {
600600
'Accept': 'application/json, text/plain, */*', 'Priority': 'u=0', 'Sec-Fetch-Site': 'same-site'
601601
}
@@ -3296,34 +3296,32 @@
32963296
chunk = extractedChunks.join('')
32973297
}
32983298
accumulatedChunks = apis[caller.api].accumulatesText ? chunk : accumulatedChunks + chunk
3299-
if (/^(?:\{|event:)/.test(accumulatedChunks)) api.tryNew(caller)
3300-
else {
3301-
try { // to show stream text
3302-
let textToShow = ''
3303-
if (caller.api == 'GPTforLove') { // extract parentID + latest chunk text
3304-
const jsonLines = accumulatedChunks.split('\n'),
3305-
nowResult = JSON.parse(jsonLines[jsonLines.length - 1])
3306-
if (nowResult.id) apis.GPTforLove.parentID = nowResult.id // for contextual replies
3307-
textToShow = nowResult.text
3308-
} else textToShow = accumulatedChunks
3309-
const failMatch = failFlagsAndURLs.exec(textToShow)
3310-
if (failMatch) {
3311-
log.debug('Response text', textToShow)
3312-
log.error('Fail flag detected', `'${failMatch[0]}'`)
3313-
if (caller.status != 'done' && !caller.sender) api.tryNew(caller)
3314-
return
3315-
} else if (caller.status != 'done') { // app waiting or sending
3316-
if (!caller.sender) caller.sender = caller.api // app is waiting, become sender
3317-
if (caller.sender == caller.api // app is sending from this caller.api
3318-
&& textToShow.trim() != '' // empty chunk not read
3319-
) show.reply(textToShow)
3320-
}
3321-
} catch (err) { log.error('Error showing stream', err.message) }
3322-
return reader.read().then(({ done, value }) => {
3323-
if (caller.sender == caller.api) // am designated sender, recurse
3324-
processStreamText({ done, value })
3325-
}).catch(err => log.error('Error reading stream', err.message))
3326-
}
3299+
try { // to show stream text
3300+
let textToShow = ''
3301+
if (caller.api == 'GPTforLove') { // extract parentID + latest chunk text
3302+
const jsonLines = accumulatedChunks.split('\n'),
3303+
nowResult = JSON.parse(jsonLines[jsonLines.length -1])
3304+
if (nowResult.id) apis.GPTforLove.parentID = nowResult.id // for contextual replies
3305+
textToShow = nowResult.text // for AI response
3306+
|| JSON.stringify(nowResult) // for error response
3307+
} else textToShow = accumulatedChunks
3308+
const failMatch = failFlagsAndURLs.exec(textToShow)
3309+
if (failMatch) {
3310+
log.debug('Response text', textToShow)
3311+
log.error('Fail flag detected', `'${failMatch[0]}'`)
3312+
if (caller.status != 'done' && !caller.sender) api.tryNew(caller)
3313+
return
3314+
} else if (caller.status != 'done') { // app waiting or sending
3315+
if (!caller.sender) caller.sender = caller.api // app is waiting, become sender
3316+
if (caller.sender == caller.api // app is sending from this caller.api
3317+
&& textToShow.trim() != '' // empty chunk not read
3318+
) show.reply(textToShow)
3319+
}
3320+
} catch (err) { log.error('Error showing stream', err.message) }
3321+
return reader.read().then(({ done, value }) => {
3322+
if (caller.sender == caller.api) // am designated sender, recurse
3323+
processStreamText({ done, value })
3324+
}).catch(err => log.error('Error reading stream', err.message))
33273325
}
33283326
},
33293327

0 commit comments

Comments
 (0)