Skip to content

Commit

Permalink
Merge pull request #18 from wangqmshf/main
Browse files Browse the repository at this point in the history
try Render Partial Question,enhace user experience
  • Loading branch information
Aomferni authored Jun 20, 2023
2 parents 772d367 + 7b2e195 commit 222f77e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/views/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,9 @@ var questionInfo = "";
const qNum = ref(1);
const qNumInner = ref(1);
const updateQuestion = () => {
qNum.value++;
qNumInner.value++;
nextQuestion();
// globleQuestion.value = JSON.parse(jsonContent);
// console.log(globleQuestion);
Expand Down Expand Up @@ -417,6 +418,7 @@ const readStream2Question = async (
while (true) {
// eslint-disable-next-line no-await-in-loop
const { value, done } = await reader.read();
qNum.value = qNumInner.value
if (done) break;
const decodedText = decoder.decode(value, { stream: true });
Expand All @@ -435,6 +437,7 @@ const readStream2Question = async (
// questionInfo += line;
// }
questionInfo += decodedText;
tryRenderPartialQuestion(questionInfo)
} else {
const chunk = partialLine + decodedText;
const newLines = chunk.split(/\r?\n/);
Expand All @@ -453,6 +456,7 @@ const readStream2Question = async (
// appendQuestionInfo(content)
questionInfo += content;
console.log("questionInfo:" + questionInfo);
tryRenderPartialQuestion(questionInfo)
// console.log('tmp content:'+content)
// resp += content
// console.log('tmp resp:'+resp)
Expand All @@ -462,6 +466,15 @@ const readStream2Question = async (
console.log("resp:" + resp);
};
const tryRenderPartialQuestion = (questionInfo: string) => {
try {
const content = questionInfo + '"}'
globleQuestion.value = JSON.parse(content);
} catch (error: any) {
// do nothing
}
};
const appendLastMessageContent = (content: string) =>
(messageList.value[messageList.value.length - 1].content += content);
Expand Down

0 comments on commit 222f77e

Please sign in to comment.