mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: 对话时,服务错误不跳404页面
This commit is contained in:
parent
d38a9c2659
commit
68beaad8ea
|
|
@ -20,7 +20,7 @@ from dataset.models import Paragraph
|
|||
class ISearchDatasetStep(IBaseChatPipelineStep):
|
||||
class InstanceSerializer(serializers.Serializer):
|
||||
# 原始问题文本
|
||||
problem_text = serializers.CharField(required=True, error_messages=ErrMessage.char("文档id"))
|
||||
problem_text = serializers.CharField(required=True, error_messages=ErrMessage.char("问题"))
|
||||
# 系统补全问题文本
|
||||
padding_problem_text = serializers.CharField(required=False, error_messages=ErrMessage.char("系统补全问题文本"))
|
||||
# 需要查询的数据集id列表
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
<div ref="aiChatRef" class="ai-chat" :class="log ? 'chart-log' : ''">
|
||||
<el-scrollbar ref="scrollDiv" @scroll="handleScrollTop">
|
||||
<div ref="dialogScrollbar" class="ai-chat__content p-24">
|
||||
<div class="item-content mb-16">
|
||||
<div class="item-content mb-16" v-if="!props.available || props.data?.prologue">
|
||||
<div class="avatar">
|
||||
<AppAvatar class="avatar-gradient">
|
||||
<img src="@/assets/icon_robot.svg" style="width: 75%" alt="" />
|
||||
|
|
@ -189,6 +189,11 @@ const props = defineProps({
|
|||
record: {
|
||||
type: Array<chatType[]>,
|
||||
default: () => []
|
||||
},
|
||||
// 应用是否可用
|
||||
available: {
|
||||
type: Boolean,
|
||||
default: true
|
||||
}
|
||||
})
|
||||
const { application } = useStore()
|
||||
|
|
@ -208,7 +213,9 @@ const isDisabledChart = computed(
|
|||
)
|
||||
const isMdArray = (val: string) => val.match(/^-\s.*/m)
|
||||
const prologueList = computed(() => {
|
||||
const temp = props.data?.prologue
|
||||
const temp = props.available
|
||||
? props.data?.prologue
|
||||
: '抱歉,当前正在维护,无法提供服务,请稍后再试!'
|
||||
let arr: any = []
|
||||
const lines = temp?.split('\n')
|
||||
lines?.forEach((str: string, index: number) => {
|
||||
|
|
@ -281,34 +288,36 @@ const startChat = (chat: chatType) => {
|
|||
/**
|
||||
* 对话
|
||||
*/
|
||||
function getChartOpenId() {
|
||||
function getChartOpenId(chat?: any) {
|
||||
loading.value = true
|
||||
const obj = props.data
|
||||
if (props.appId) {
|
||||
applicationApi
|
||||
return applicationApi
|
||||
.getChatOpen(props.appId)
|
||||
.then((res) => {
|
||||
chartOpenId.value = res.data
|
||||
chatMessage()
|
||||
chatMessage(chat)
|
||||
})
|
||||
.catch((res) => {
|
||||
console.log(res)
|
||||
if (res.response.status === 403) {
|
||||
application.asyncAppAuthentication(accessToken).then(() => {
|
||||
getChartOpenId()
|
||||
})
|
||||
} else {
|
||||
loading.value = false
|
||||
return Promise.reject(res)
|
||||
}
|
||||
loading.value = false
|
||||
})
|
||||
} else {
|
||||
applicationApi
|
||||
return applicationApi
|
||||
.postChatOpen(obj)
|
||||
.then((res) => {
|
||||
chartOpenId.value = res.data
|
||||
chatMessage()
|
||||
chatMessage(chat)
|
||||
})
|
||||
.catch(() => {
|
||||
.catch((res) => {
|
||||
loading.value = false
|
||||
return Promise.reject(res)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -389,39 +398,51 @@ const getWrite = (chat: any, reader: any, stream: boolean) => {
|
|||
}
|
||||
return stream ? write_stream : write_json
|
||||
}
|
||||
|
||||
const errorWrite = (chat: any) => {
|
||||
ChatManagement.addChatRecord(chat, 50, loading)
|
||||
ChatManagement.write(chat.id)
|
||||
ChatManagement.append(chat.id, '抱歉,当前正在维护,无法提供服务,请稍后再试!')
|
||||
ChatManagement.close(chat.id)
|
||||
}
|
||||
function chatMessage(chat?: any) {
|
||||
loading.value = true
|
||||
if (!chat) {
|
||||
chat = reactive({
|
||||
id: randomId(),
|
||||
problem_text: inputValue.value,
|
||||
answer_text: '',
|
||||
buffer: [],
|
||||
write_ed: false,
|
||||
is_stop: false,
|
||||
record_id: '',
|
||||
vote_status: '-1'
|
||||
})
|
||||
chatList.value.push(chat)
|
||||
inputValue.value = ''
|
||||
nextTick(() => {
|
||||
// 将滚动条滚动到最下面
|
||||
scrollDiv.value.setScrollTop(getMaxHeight())
|
||||
})
|
||||
}
|
||||
if (!chartOpenId.value) {
|
||||
getChartOpenId()
|
||||
getChartOpenId(chat).catch((e) => {
|
||||
errorWrite(chat)
|
||||
})
|
||||
} else {
|
||||
if (!chat) {
|
||||
chat = reactive({
|
||||
id: randomId(),
|
||||
problem_text: inputValue.value,
|
||||
answer_text: '',
|
||||
buffer: [],
|
||||
write_ed: false,
|
||||
is_stop: false,
|
||||
record_id: '',
|
||||
vote_status: '-1'
|
||||
})
|
||||
chatList.value.push(chat)
|
||||
inputValue.value = ''
|
||||
nextTick(() => {
|
||||
// 将滚动条滚动到最下面
|
||||
scrollDiv.value.setScrollTop(getMaxHeight())
|
||||
})
|
||||
}
|
||||
// 对话
|
||||
applicationApi
|
||||
.postChatMessage(chartOpenId.value, chat.problem_text)
|
||||
.then((response) => {
|
||||
console.log(response.status)
|
||||
if (response.status === 401) {
|
||||
application.asyncAppAuthentication(accessToken).then(() => {
|
||||
chatMessage(chat)
|
||||
})
|
||||
application
|
||||
.asyncAppAuthentication(accessToken)
|
||||
.then(() => {
|
||||
chatMessage(chat)
|
||||
})
|
||||
.catch((err) => {
|
||||
errorWrite(chat)
|
||||
})
|
||||
} else {
|
||||
nextTick(() => {
|
||||
// 将滚动条滚动到最下面
|
||||
|
|
@ -447,7 +468,6 @@ function chatMessage(chat?: any) {
|
|||
})
|
||||
.catch((e: any) => {
|
||||
MsgError(e)
|
||||
ChatManagement.close(chat.id)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,12 +53,12 @@ instance.interceptors.response.use(
|
|||
console.error(err)
|
||||
}
|
||||
if (err.response?.status === 404) {
|
||||
router.push('/404 ')
|
||||
if (!err.response.config.url.includes('/application/authentication')) {
|
||||
router.push('/404 ')
|
||||
}
|
||||
}
|
||||
if (err.response?.status === 401) {
|
||||
if (err.response.config.url.includes('chat/open')) {
|
||||
router.push('/404 ')
|
||||
} else {
|
||||
if (!err.response.config.url.includes('chat/open')) {
|
||||
router.push({ name: 'login' })
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@
|
|||
</div>
|
||||
</div>
|
||||
<div class="chat__main chat-width">
|
||||
<AiChat v-model:data="applicationDetail" :appId="applicationDetail?.id"></AiChat>
|
||||
<AiChat
|
||||
v-model:data="applicationDetail"
|
||||
:available="applicationAvailable"
|
||||
:appId="applicationDetail?.id"
|
||||
></AiChat>
|
||||
</div>
|
||||
<div class="chat__footer"></div>
|
||||
</div>
|
||||
|
|
@ -25,16 +29,27 @@ const { application, user } = useStore()
|
|||
|
||||
const loading = ref(false)
|
||||
const applicationDetail = ref<any>({})
|
||||
const applicationAvailable = ref<boolean>(true)
|
||||
|
||||
function getAccessToken(token: string) {
|
||||
application.asyncAppAuthentication(token, loading).then((res) => {
|
||||
getProfile()
|
||||
})
|
||||
application
|
||||
.asyncAppAuthentication(token, loading)
|
||||
.then((res) => {
|
||||
getProfile()
|
||||
})
|
||||
.catch(() => {
|
||||
applicationAvailable.value = false
|
||||
})
|
||||
}
|
||||
function getProfile() {
|
||||
applicationApi.getProfile(loading).then((res) => {
|
||||
applicationDetail.value = res.data
|
||||
})
|
||||
applicationApi
|
||||
.getProfile(loading)
|
||||
.then((res) => {
|
||||
applicationDetail.value = res.data
|
||||
})
|
||||
.catch(() => {
|
||||
applicationAvailable.value = false
|
||||
})
|
||||
}
|
||||
onMounted(() => {
|
||||
user.changeUserType(2)
|
||||
|
|
|
|||
Loading…
Reference in New Issue