diff --git a/pages/search/[id].vue b/pages/search/[id].vue index 56ca11e9095d20d027942c5d61563b493708f885..fed4c54166572d5abe2f5829079ea91ba698a47c 100644 --- a/pages/search/[id].vue +++ b/pages/search/[id].vue @@ -99,11 +99,12 @@ -
+
相关问题
route.query.repo === item.label) const state = reactive({ @@ -167,7 +169,7 @@ const state = reactive({ const scrollToView = () => { const $target = document.querySelector('#scrollElement') const height = $target.clientHeight - window.scrollTo(0, height, { behavior: 'smooth' }) + y.value = height; } const isEditTitle = ref(false) const titleRef = ref(null) @@ -208,17 +210,7 @@ const handleReGenerate = (index) => { const data = ref([]) -const recommendQuestions = [ - { - title: 'ViewUIPlus Select 组件如何按需加载' - }, - { - title: 'ViewUIPlus Select 组件如何按需加载' - }, - { - title: 'ViewUIPlus Select 组件如何按需加载' - } -] +const recommendQuestions = ref([]); const continueQuestion = ref(null) defineShortcuts({ enter: { @@ -258,15 +250,17 @@ const handleFormFetchData = (fetchData) => { let message = {} try { message = JSON.parse(fetchData) - } catch(error) { - console.log(error) - } + } catch(error) { } if (Object.keys(message).length === 0) return const { meta, choices } = message const index = editIndex.value nextTick(() => { scrollToView() }) + // 处理报错信息 + if (!meta) { + handleStopGenerate(); + } if (meta.type === 'answer') { Object.assign(data.value[index], { ansLoading: true, @@ -321,10 +315,34 @@ const handleMessage = (event) => { const handleStopGenerate = () => { asking.value && aiChatController && aiChatController.abort() asking.value = false + data.value.forEach(item => { + item.desLoading = false; + item.ansLoading = false; + }) } const handleError = (event) => { handleStopGenerate() } +const fetchLinkedQuestion = (query) => { + const { gitPath, id } = state + const messages = [] + messages.push({ role: 'user', content: query }) + fetchRequest('/v1/chat/recomend_question', { + method: 'post', + body: { + repo_path: gitPath, + c_id: id, + messages, + rephrase_question: true + } + }).then((res) => { + if (res && res.data && res.data.items) { + recommendQuestions.value = res.data.items.map(item => { + return { title: item } + }) + } + }) +} const generateFetchData = (query) => { const { gitPath, id } = state const messages = [] @@ -343,6 +361,8 @@ const generateFetchData = (query) => { onerror: handleError, controller: aiChatController }) + // 重新生成相关问题 + fetchLinkedQuestion(query) } onMounted(() => { generateFetchData(state.query)