'); scrollToBottom(); streamData(question) } async function streamData(text) { try { const response = await fetch('/aiinfo/chat?opt=' + text, { method: 'GET', headers: { "Authorization": Author.Authorization } }); const reader = response.body.getReader(); aiobj.aiNum++; var strid = 'answ' + aiobj.aiNum; $('#aiDuihua').append('
'); const outputDiv = document.getElementById(strid); let result; while (!(result = await reader.read()).done) { $("#waitAi").hide(); const chunk = new TextDecoder().decode(result.value); var arr = chunk.split('data: '); arr.map((item, index) => { if (index > 0) { var json_str = item; data = JSON.parse(json_str); text = data['text']; outputDiv.innerHTML += text; } }) scrollToBottom(); } aiobj.isload = false; $('#zhezhao').hide(); } catch (error) { $("#waitAi").hide(); aiobj.isload = false; scrollToBottom(); $('#zhezhao').hide(); } }