提交 eaa72034 编写于 作者: View Design's avatar View Design

Merge branch 'main' of gitcode.com:git_bot/ai-fe

......@@ -99,11 +99,12 @@
<UDivider v-if="index !== data.length - 1" class="pt-3 pb-2" />
</template>
<div class="text-xl flex items-center space-x-1">
<div class="text-xl flex items-center space-x-1" v-if="recommendQuestions.length > 0 && !asking">
<UIcon name="i-heroicons-rectangle-group-20-solid" />
<span>相关问题</span>
</div>
<UButton
v-if="!asking"
v-for="item in recommendQuestions"
color="gray"
size="md"
......@@ -155,6 +156,7 @@ const { fetchRequest } = useFetchRequest()
const repos = getMockRepo()
const initLoading = ref(true)
const editIndex = ref(0)
const { y } = useWindowScroll();
// todo mock
const repoItem = repos.find(item => 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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册