Browse Source

fix-sse-answer-only-parsing

master
Serge Shutov 2 weeks ago
parent
commit
c79d67f63b
  1. 5
      injected/chat-logger.js

5
injected/chat-logger.js

@ -109,6 +109,7 @@ @@ -109,6 +109,7 @@
function extractAssistant(sse) {
if (!sse) return ''
var __ri = sse.indexOf('"type":"RESPONSE"'); if (__ri > 0) { var __bs = sse.lastIndexOf('data: ', __ri); if (__bs > 0) { sse = sse.slice(__bs) } }
var out = []
var blocks = sse.split(SEP); evTotal = blocks.length
for (var i = 0; i !== blocks.length; i++) {
@ -120,10 +121,10 @@ @@ -120,10 +121,10 @@
var o = null
try { o = JSON.parse(json) } catch (e) { continue }
if (!o || typeof o !== 'object') continue
if (o.p) { evP = evP + 1; var __pp = String(o.p); if (__pp.indexOf(String.fromCharCode(114,101,115,112,111,110,115,101)) === 0) { if (Array.isArray(o.v)) { for (var __q = 0; __q < o.v.length; __q++) { var __fr = o.v[__q]; if (__fr && String(__fr['type']) === 'RESPONSE' && typeof __fr['content'] === 'string') { evV = evV + 1; out.push(__fr['content']) } } } else if (typeof o.v === 'string') { evV = evV + 1; out.push(o.v) } } continue }
if (o.p) { evP = evP + 1; var __pp = String(o.p); if (__pp.indexOf('response/fragments') === 0) { if (Array.isArray(o.v)) { for (var __q = 0; __q < o.v.length; __q++) { var __fr = o.v[__q]; if (__fr && String(__fr['type']) === 'RESPONSE' && typeof __fr['content'] === 'string') { evV = evV + 1; out.push(__fr['content']) } } } else if (typeof o.v === 'string') { evV = evV + 1; out.push(o.v) } } continue }
if (typeof o.v !== 'string') continue
if (Object.keys(o).length !== 1) continue
evT = evT + 1
evV = evV + 1; out.push(o.v)
}
return out.join('')
}

Loading…
Cancel
Save