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