Update webapp.py

This commit is contained in:
Joseph Cheung 2023-02-23 12:38:50 +08:00
parent 75139c2e10
commit 5059a1ae1e

View file

@ -1012,9 +1012,9 @@ Authorization: "Bearer '''+ os.environ['GPTKEY'] + r'''",
};
let prompt = JSON.parse(document.querySelector("#prompt").textContent);
chatTextRawIntro = "";
text_offset = -1;
const optionsIntro = {
chatTextRawIntro = "";
text_offset = -1;
const optionsIntro = {
method: "POST",
headers: headers,
body: JSON.stringify({
@ -1029,9 +1029,9 @@ let prompt = JSON.parse(document.querySelector("#prompt").textContent);
"logprobs": 0,
"stream": true
})
};
fetch("https://api.openai.com/v1/engines/text-davinci-003/completions", optionsIntro)
.then((responseIntro) => {
};
fetch("https://api.openai.com/v1/engines/text-davinci-003/completions", optionsIntro)
.then((responseIntro) => {
const readerIntro = responseIntro.body.getReader();
let result = '';
readerIntro.read().then(function processText({ done, value }) {
@ -1041,23 +1041,10 @@ let prompt = JSON.parse(document.querySelector("#prompt").textContent);
if(v.length>6) result = v.slice(6);
if(result == "[DONE]")
{
return;
}
const { choices } = JSON.parse(result);
if(choices[0].logprobs.text_offset[0] > text_offset)
{
chatTextRawIntro+=choices[0].text
text_offset = choices[0].logprobs.text_offset[choices[0].logprobs.text_offset.length - 1]
}
markdownToHtml(beautify(chatTextRawIntro+'\n'), document.getElementById('chat_intro'));
})
return readerIntro.read().then(processText);
});
})
.catch((error) => {
console.error('Error:', error);
});
text_offset = -1;
const options = {
@ -1076,7 +1063,7 @@ let prompt = JSON.parse(document.querySelector("#prompt").textContent);
if(v.length>6) result = v.slice(6);
if(result == "[DONE]")
{
chatTextRawPlusComment = chatTextRaw+"\n";
chatTextRawPlusComment = chatTextRaw+"\n\n";
text_offset = -1;
const optionsPlus = {
method: "POST",
@ -1142,6 +1129,36 @@ let prompt = JSON.parse(document.querySelector("#prompt").textContent);
console.error('Error:', error);
});
return;
}
const { choices } = JSON.parse(result);
if(choices[0].logprobs.text_offset[0] > text_offset)
{
chatTextRawIntro+=choices[0].text
text_offset = choices[0].logprobs.text_offset[choices[0].logprobs.text_offset.length - 1]
}
markdownToHtml(beautify(chatTextRawIntro+'\n'), document.getElementById('chat_intro'));
})
return readerIntro.read().then(processText);
});
})
.catch((error) => {
console.error('Error:', error);
});
</script>
'''
# for i in range(1,16):