diff --git a/apps/application/chat_pipeline/step/search_dataset_step/i_search_dataset_step.py b/apps/application/chat_pipeline/step/search_dataset_step/i_search_dataset_step.py index 11431cafc..3731a6aef 100644 --- a/apps/application/chat_pipeline/step/search_dataset_step/i_search_dataset_step.py +++ b/apps/application/chat_pipeline/step/search_dataset_step/i_search_dataset_step.py @@ -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列表 diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index 10af298d3..123c7dce1 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -2,7 +2,7 @@
-
+
@@ -189,6 +189,11 @@ const props = defineProps({ record: { type: Array, 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) }) } } diff --git a/ui/src/request/index.ts b/ui/src/request/index.ts index 85354b032..1f994ec7f 100644 --- a/ui/src/request/index.ts +++ b/ui/src/request/index.ts @@ -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' }) } } diff --git a/ui/src/views/chat/index.vue b/ui/src/views/chat/index.vue index 6dde80f90..d2bab84aa 100644 --- a/ui/src/views/chat/index.vue +++ b/ui/src/views/chat/index.vue @@ -6,7 +6,11 @@
- +
@@ -25,16 +29,27 @@ const { application, user } = useStore() const loading = ref(false) const applicationDetail = ref({}) +const applicationAvailable = ref(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)