9393 <ChatRow :current-chat =" currentChat" :msg =" message" :hide-avatar =" message.first_chat" >
9494 <RecommendQuestion
9595 v-if =" message.role === 'assistant' && message.first_chat"
96+ ref =" recommendQuestionRef"
97+ :current-chat =" currentChat"
98+ :record-id =" message.record?.id"
9699 :questions =" message.recommended_question"
97100 :first-chat =" message.first_chat"
98101 @click-question =" quickAsk"
181184 </template >
182185 <template #footer >
183186 <RecommendQuestion
187+ ref =" recommendQuestionRef"
188+ :current-chat =" currentChat"
189+ :record-id =" message.record?.id"
184190 :questions =" message.recommended_question"
185191 :first-chat =" message.first_chat"
186192 @click-question =" quickAsk"
@@ -303,7 +309,7 @@ import ChatListContainer from './ChatListContainer.vue'
303309import ChatCreator from ' @/views/chat/ChatCreator.vue'
304310import ChatToolBar from ' ./ChatToolBar.vue'
305311import { useI18n } from ' vue-i18n'
306- import { endsWith , find , startsWith } from ' lodash-es'
312+ import { find } from ' lodash-es'
307313import icon_new_chat_outlined from ' @/assets/svg/icon_new_chat_outlined.svg'
308314import icon_sidebar_outlined from ' @/assets/svg/icon_sidebar_outlined.svg'
309315import icon_replace_outlined from ' @/assets/svg/icon_replace_outlined.svg'
@@ -373,6 +379,7 @@ const computedMessages = computed<Array<ChatMessage>>(() => {
373379 })
374380 }
375381
382+ console .log (messages )
376383 return messages
377384})
378385
@@ -465,72 +472,24 @@ function onChatCreated(chat: ChatInfo) {
465472 }
466473}
467474
468- async function getRecommendQuestions(record_id ? : number ) {
469- const response = await chatApi .recommendQuestions (record_id )
470- const reader = response .body .getReader ()
471- const decoder = new TextDecoder ()
475+ const recommendQuestionRef = ref ()
472476
473- while (true ) {
474- const { done, value } = await reader .read ()
475- if (done ) {
476- break
477- }
478-
479- const chunk = decoder .decode (value )
480-
481- let _list = [chunk ]
482-
483- const lines = chunk .trim ().split (' }\n\n {' )
484- if (lines .length > 1 ) {
485- _list = []
486- for (let line of lines ) {
487- if (! line .trim ().startsWith (' {' )) {
488- line = ' {' + line .trim ()
489- }
490- if (! line .trim ().endsWith (' }' )) {
491- line = line .trim () + ' }'
492- }
493- _list .push (line )
494- }
495- }
496-
497- for (const str of _list ) {
498- let data
499- try {
500- data = JSON .parse (str )
501- } catch (err ) {
502- console .error (' JSON string:' , str )
503- throw err
504- }
505-
506- if (data .code && data .code !== 200 ) {
507- ElMessage ({
508- message: data .msg ,
509- type: ' error' ,
510- showClose: true ,
511- })
512- return
513- }
514-
515- switch (data .type ) {
516- case ' recommended_question' :
517- if (
518- data .content &&
519- data .content .length > 0 &&
520- startsWith (data .content .trim (), ' [' ) &&
521- endsWith (data .content .trim (), ' ]' )
522- ) {
523- if (currentChat .value ?.records ) {
524- for (let record of currentChat .value .records ) {
525- if (record .id === record_id ) {
526- record .recommended_question = data .content
527- }
528- }
529- }
477+ function getRecommendQuestions(id ? : number ) {
478+ nextTick (() => {
479+ if (recommendQuestionRef .value ) {
480+ if (recommendQuestionRef .value instanceof Array ) {
481+ for (let i = 0 ; i < recommendQuestionRef .value .length ; i ++ ) {
482+ const _id = recommendQuestionRef .value [i ].id ()
483+ if (_id === id ) {
484+ recommendQuestionRef .value [i ].getRecommendQuestions ()
485+ break
530486 }
487+ }
488+ } else {
489+ recommendQuestionRef .value .getRecommendQuestions ()
531490 }
532491 }
533- }
492+ })
534493}
535494
536495onMounted (() => {
@@ -549,7 +508,7 @@ const chartAnswerRef = ref()
549508async function onChartAnswerFinish(id : number ) {
550509 loading .value = false
551510 isTyping .value = false
552- await getRecommendQuestions (id )
511+ getRecommendQuestions (id )
553512}
554513
555514function onChartAnswerError() {
0 commit comments