kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
fix(ChatGPTUnofficialProxyAPI): pass fetch
rodzic
70e4797615
commit
f0ce92559e
|
@ -155,47 +155,51 @@ export class ChatGPTUnofficialProxyAPI {
|
||||||
console.log('POST', url, { body, headers })
|
console.log('POST', url, { body, headers })
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchSSE(url, {
|
fetchSSE(
|
||||||
method: 'POST',
|
url,
|
||||||
headers,
|
{
|
||||||
body: JSON.stringify(body),
|
method: 'POST',
|
||||||
signal: abortSignal,
|
headers,
|
||||||
onMessage: (data: string) => {
|
body: JSON.stringify(body),
|
||||||
if (data === '[DONE]') {
|
signal: abortSignal,
|
||||||
return resolve(result)
|
onMessage: (data: string) => {
|
||||||
}
|
if (data === '[DONE]') {
|
||||||
|
return resolve(result)
|
||||||
try {
|
|
||||||
const convoResponseEvent: types.ConversationResponseEvent =
|
|
||||||
JSON.parse(data)
|
|
||||||
if (convoResponseEvent.conversation_id) {
|
|
||||||
result.conversationId = convoResponseEvent.conversation_id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (convoResponseEvent.message?.id) {
|
try {
|
||||||
result.id = convoResponseEvent.message.id
|
const convoResponseEvent: types.ConversationResponseEvent =
|
||||||
}
|
JSON.parse(data)
|
||||||
|
if (convoResponseEvent.conversation_id) {
|
||||||
|
result.conversationId = convoResponseEvent.conversation_id
|
||||||
|
}
|
||||||
|
|
||||||
const message = convoResponseEvent.message
|
if (convoResponseEvent.message?.id) {
|
||||||
// console.log('event', JSON.stringify(convoResponseEvent, null, 2))
|
result.id = convoResponseEvent.message.id
|
||||||
|
}
|
||||||
|
|
||||||
if (message) {
|
const message = convoResponseEvent.message
|
||||||
let text = message?.content?.parts?.[0]
|
// console.log('event', JSON.stringify(convoResponseEvent, null, 2))
|
||||||
|
|
||||||
if (text) {
|
if (message) {
|
||||||
result.text = text
|
let text = message?.content?.parts?.[0]
|
||||||
|
|
||||||
if (onProgress) {
|
if (text) {
|
||||||
onProgress(result)
|
result.text = text
|
||||||
|
|
||||||
|
if (onProgress) {
|
||||||
|
onProgress(result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
// ignore for now; there seem to be some non-json messages
|
||||||
|
// console.warn('fetchSSE onMessage unexpected error', err)
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
// ignore for now; there seem to be some non-json messages
|
|
||||||
// console.warn('fetchSSE onMessage unexpected error', err)
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
}).catch((err) => {
|
this._fetch
|
||||||
|
).catch((err) => {
|
||||||
const errMessageL = err.toString().toLowerCase()
|
const errMessageL = err.toString().toLowerCase()
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|
Ładowanie…
Reference in New Issue