mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: move to self-hosted chatgpt proxy
This commit is contained in:
parent
3c60bc1ee9
commit
3b50d28f8e
1 changed files with 10 additions and 7 deletions
|
|
@ -90,16 +90,19 @@ export class OfficialChatGPTClient {
|
|||
const bodyBytes = await res.arrayBuffer()
|
||||
const bodyText = decoder.decode(bodyBytes)
|
||||
const events = bodyText.split('\n\n').filter(item => !_.isEmpty(item))
|
||||
let fullResponse = events[events.length - 2]
|
||||
fullResponse = _.trimStart(fullResponse, 'data: ')
|
||||
let fullResponse
|
||||
for (let i = 0; i < events.length; i++) {
|
||||
let event = events[i]
|
||||
event = _.trimStart(event, 'data: ')
|
||||
try {
|
||||
fullResponse = JSON.parse(event)
|
||||
} catch (err) {
|
||||
console.log(event)
|
||||
}
|
||||
}
|
||||
if (Config.debug) {
|
||||
logger.mark(fullResponse)
|
||||
}
|
||||
try {
|
||||
fullResponse = JSON.parse(fullResponse)
|
||||
} catch (e) {
|
||||
throw new Error(bodyText || 'unkown error, please check log')
|
||||
}
|
||||
if (!fullResponse?.message) {
|
||||
throw new Error(bodyText || 'unkown error, please check log')
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue