From ab2112121e95379e038f495bf1b1438f52a22b99 Mon Sep 17 00:00:00 2001 From: Germey Date: Sun, 28 Jan 2024 02:13:18 +0800 Subject: [PATCH] update conversation --- src/components/chat/Message.vue | 3 - src/components/chatdoc/AnsweringMark.vue | 40 ++++ src/components/chatdoc/Conversations.vue | 26 ++- src/components/chatdoc/InputBox.vue | 223 +++++++++++++++++++++++ src/components/chatdoc/Message.vue | 175 ++++++++++++++++++ src/i18n/zh/chatdoc/message.ts | 13 +- src/operators/chat/models.ts | 2 +- src/operators/chatdoc/models.ts | 15 ++ src/operators/chatdoc/operator.ts | 7 +- src/pages/chatdoc/Conversation.vue | 218 +++++++++++++++++++++- 10 files changed, 699 insertions(+), 23 deletions(-) create mode 100644 src/components/chatdoc/AnsweringMark.vue create mode 100644 src/components/chatdoc/InputBox.vue create mode 100644 src/components/chatdoc/Message.vue diff --git a/src/components/chat/Message.vue b/src/components/chat/Message.vue index ccaa925..3e4c20d 100644 --- a/src/components/chat/Message.vue +++ b/src/components/chat/Message.vue @@ -126,9 +126,6 @@ export default defineComponent({ } }); } - // onStop() { - // this.$emit('stop'); - // } } }); diff --git a/src/components/chatdoc/AnsweringMark.vue b/src/components/chatdoc/AnsweringMark.vue new file mode 100644 index 0000000..91e9102 --- /dev/null +++ b/src/components/chatdoc/AnsweringMark.vue @@ -0,0 +1,40 @@ + + + + + diff --git a/src/components/chatdoc/Conversations.vue b/src/components/chatdoc/Conversations.vue index 3a1f965..ec9851c 100644 --- a/src/components/chatdoc/Conversations.vue +++ b/src/components/chatdoc/Conversations.vue @@ -68,9 +68,8 @@ import { defineComponent } from 'vue'; import { ElSkeleton, ElInput } from 'element-plus'; import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome'; -import { ROUTE_CHAT_CONVERSATION } from '@/router/constants'; -import { IChatdocRepository, chatdocOperator } from '@/operators'; -import { IChatdocConversation } from '@/operators'; +import { ROUTE_CHATDOC_CONVERSATION, ROUTE_CHATDOC_CONVERSATION_NEW } from '@/router/constants'; +import { IChatdocRepository, chatdocOperator, IChatdocConversation } from '@/operators'; export default defineComponent({ name: 'SidePanel', @@ -82,11 +81,14 @@ export default defineComponent({ props: {}, emits: ['click'], computed: { + repositoryId() { + return this.$route.params?.repositoryId?.toString(); + }, conversationId() { - return this.$route.params?.id?.toString(); + return this.$route.params?.conversationId?.toString(); }, repository(): IChatdocRepository | undefined { - return this.$store.state?.chatdoc?.repositories?.find((repository) => repository.id === this.id); + return this.$store.state?.chatdoc?.repositories?.find((repository) => repository.id === this.repositoryId); }, conversations() { return this.repository?.conversations; @@ -97,9 +99,12 @@ export default defineComponent({ }, methods: { async onNewConversation() { - // this.$router.push({ - // name: ROUTE_CHATDOC_CONVERSATION - // }); + this.$router.push({ + name: ROUTE_CHATDOC_CONVERSATION_NEW, + params: { + repositoryId: this.repositoryId + } + }); }, async onConfirm(conversation: IChatdocConversation) { if (conversation?.deleting) { @@ -117,9 +122,10 @@ export default defineComponent({ return; } this.$router.push({ - name: ROUTE_CHAT_CONVERSATION, + name: ROUTE_CHATDOC_CONVERSATION, params: { - id + repositoryId: this.repositoryId, + conversationId: id } }); this.$emit('click', id); diff --git a/src/components/chatdoc/InputBox.vue b/src/components/chatdoc/InputBox.vue new file mode 100644 index 0000000..d8f7343 --- /dev/null +++ b/src/components/chatdoc/InputBox.vue @@ -0,0 +1,223 @@ + + + + + + + diff --git a/src/components/chatdoc/Message.vue b/src/components/chatdoc/Message.vue new file mode 100644 index 0000000..23941d6 --- /dev/null +++ b/src/components/chatdoc/Message.vue @@ -0,0 +1,175 @@ + + + + + diff --git a/src/i18n/zh/chatdoc/message.ts b/src/i18n/zh/chatdoc/message.ts index 707f0f7..792051f 100644 --- a/src/i18n/zh/chatdoc/message.ts +++ b/src/i18n/zh/chatdoc/message.ts @@ -8,5 +8,16 @@ export default { createDocumentError: '录入文档失败', dragOrClickToUpload: '拖拽或点击上传', learningDocument: '学习中,请稍后...', - startNewChat: '开始新会话' + startNewChat: '开始新会话', + errorApiError: '回答失败,请稍后重试', + errorBadRequest: '请求内容不规范,请重新提问', + errorNoConversation: '对话内容不存在或者已经过期,请发起新的会话', + errorContentTooLarge: '问题内容过长,请缩短后重试', + errorTooManyRequests: '您的操作过于频繁,请稍后重试', + errorUsedUp: '您的套餐次数已经用完,请购买更多次数继续使用', + errorUnknown: '服务器出现未知错误,请稍后重试或联系客服', + errorTimeout: '回答问题超时,请稍后重试', + errorNotApplied: '您尚未申请该服务,请先申请再继续提问', + confirmDelete: '确定删除', + howToUse: '按 Shift+Enter 键可以换行' }; diff --git a/src/operators/chat/models.ts b/src/operators/chat/models.ts index 51447de..905ad2f 100644 --- a/src/operators/chat/models.ts +++ b/src/operators/chat/models.ts @@ -23,7 +23,7 @@ export interface IChatModel { description: string; } -export interface IError { +interface IError { code: string; detail?: string; } diff --git a/src/operators/chatdoc/models.ts b/src/operators/chatdoc/models.ts index dbd5101..ce07606 100644 --- a/src/operators/chatdoc/models.ts +++ b/src/operators/chatdoc/models.ts @@ -1,5 +1,10 @@ import { ACTION_CREATE, ACTION_DELETE, ACTION_UPDATE, ROLE_ASSISTANT, ROLE_SYSTEM, ROLE_USER } from '@/constants'; +export interface IError { + code: string; + detail?: string; +} + export interface IChatdocRepository { id: string; name?: string; @@ -27,9 +32,18 @@ export interface IChatdocConversation { export interface IChatdocMessage { content?: string; + error?: IError; + state?: IChatdocMessageState; role?: typeof ROLE_SYSTEM | typeof ROLE_ASSISTANT | typeof ROLE_USER; } +export enum IChatdocMessageState { + PENDING = 'pending', + ANSWERING = 'answering', + FINISHED = 'finished', + FAILED = 'failed' +} + export interface IChatdocChatRequest { repository_id: string; messages: IChatdocMessage[]; @@ -58,4 +72,5 @@ export interface IChatdocChatResponse { answer: string; delta_answer: string; repository_id?: string; + conversation_id?: string; } diff --git a/src/operators/chatdoc/operator.ts b/src/operators/chatdoc/operator.ts index d97c7d4..d716499 100644 --- a/src/operators/chatdoc/operator.ts +++ b/src/operators/chatdoc/operator.ts @@ -254,13 +254,16 @@ class ChatdocOperator { } async chat( - repositoryId: string, + payload: { repositoryId: string; question: string; conversationId?: string; knowledgeFallback?: boolean }, options: { token: string; stream: (response: IChatdocChatResponse) => void } ): Promise> { return await axios.post( `/chatdoc/chat`, { - repository_id: repositoryId + repository_id: payload.repositoryId, + question: payload.question, + conversation_id: payload.conversationId, + stateful: true }, { headers: { diff --git a/src/pages/chatdoc/Conversation.vue b/src/pages/chatdoc/Conversation.vue index 2d5a3c7..c2214bb 100644 --- a/src/pages/chatdoc/Conversation.vue +++ b/src/pages/chatdoc/Conversation.vue @@ -3,7 +3,27 @@ @@ -12,27 +32,74 @@ @@ -56,9 +240,31 @@ export default defineComponent({ display: flex; flex-direction: row; height: 100%; + width: 100%; } .chat { flex: 1; width: calc(100% - 300px); + padding: 15px; + flex-direction: column; + height: 100%; + display: flex; + + .dialogue { + flex: 1; + overflow-y: scroll; + margin: 20px 0; + position: relative; + .messages { + padding-top: 30px; + .message { + margin-bottom: 15px; + } + } + } + .bottom { + width: 100%; + height: 90px; + } }