fix experience
This commit is contained in:
1 parent
ea1c3413a5
commit
35a5854133
7 files changed
+128
-15
No files matched your search
@@ -0,0 +1,40 @@
|
||||
<template>
|
||||
<div class="box"></div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MessageContent',
|
||||
data() {
|
||||
return {};
|
||||
},
|
||||
computed: {
|
||||
conversationId() {
|
||||
return this.$route.params?.id?.toString();
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss">
|
||||
@keyframes blink {
|
||||
0% {
|
||||
opacity: 1;
|
||||
}
|
||||
50% {
|
||||
opacity: 0;
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
.box {
|
||||
width: 5px;
|
||||
height: 20px;
|
||||
margin-top: 3px;
|
||||
background-color: black;
|
||||
animation: blink 1s infinite;
|
||||
}
|
||||
</style>
|
||||
@@ -1,13 +1,13 @@
|
||||
<template>
|
||||
<div class="message">
|
||||
<el-image :src="author.avatar" class="icon" />
|
||||
<message-content :content="content" class="content" :error="error" />
|
||||
<message-content :content="content" class="content" :error="error" :state="state" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { IBot, IUser } from '@/operators';
|
||||
import { IContent, IError } from '@/operators/message/models';
|
||||
import { IContent, IError, IMessageState } from '@/operators/message/models';
|
||||
import { defineComponent } from 'vue';
|
||||
import MessageContent from './MessageContent.vue';
|
||||
import { ElImage } from 'element-plus';
|
||||
@@ -33,6 +33,13 @@ export default defineComponent({
|
||||
default() {
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
state: {
|
||||
type: Object as () => IMessageState,
|
||||
required: false,
|
||||
default() {
|
||||
return IMessageState.FINISHED;
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
<template>
|
||||
<markdown-renderer :content="content.value" />
|
||||
<el-alert v-if="error" :title="error?.detail" type="error" />
|
||||
<markdown-renderer :content="content?.value" />
|
||||
<answering-mark v-if="shouldShowAnsweringMark" />
|
||||
<el-alert v-if="errorText" :title="errorText" type="error" :closable="false" />
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { IContent, IError } from '@/operators/message/models';
|
||||
import { IContent, IError, IMessageState } from '@/operators/message/models';
|
||||
import { defineComponent } from 'vue';
|
||||
import MarkdownRenderer from '@/components/common/MarkdownRenderer.vue';
|
||||
import { ElAlert } from 'element-plus';
|
||||
import { ERROR_CODE_API_ERROR, ERROR_CODE_BUSY, ERROR_CODE_BAD_REQUEST } from '@/constants';
|
||||
import AnsweringMark from './AnsweringMark.vue';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MessageContent',
|
||||
components: {
|
||||
MarkdownRenderer,
|
||||
ElAlert
|
||||
ElAlert,
|
||||
AnsweringMark
|
||||
},
|
||||
props: {
|
||||
content: {
|
||||
@@ -26,11 +30,34 @@ export default defineComponent({
|
||||
default() {
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
state: {
|
||||
type: Object as () => IMessageState,
|
||||
required: false,
|
||||
default() {
|
||||
return IMessageState.FINISHED;
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
conversationId() {
|
||||
return this.$route.params?.id?.toString();
|
||||
},
|
||||
shouldShowAnsweringMark() {
|
||||
// @ts-ignore
|
||||
return this.state === IMessageState.PENDING;
|
||||
},
|
||||
errorText() {
|
||||
if (this.error?.code === ERROR_CODE_BUSY) {
|
||||
return this.$t('conversation.message.errorBusy');
|
||||
}
|
||||
if (this.error?.code === ERROR_CODE_API_ERROR) {
|
||||
return this.$t('conversation.message.errorApiError');
|
||||
}
|
||||
if (this.error?.code === ERROR_CODE_BAD_REQUEST) {
|
||||
return this.$t('conversation.message.errorBadRequest');
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,2 +1,5 @@
|
||||
export const ERROR_CODE_UNVERIFIED = 'unverified';
|
||||
export const ERROR_CODE_DUPLICATION = 'duplication';
|
||||
export const ERROR_CODE_BUSY = 'busy';
|
||||
export const ERROR_CODE_API_ERROR = 'api_error';
|
||||
export const ERROR_CODE_BAD_REQUEST = 'bad_request';
|
||||
@@ -13,5 +13,8 @@ export default {
|
||||
rejectInvalidPrompt: '可以拒绝回答不恰当的提问',
|
||||
generateInCorrect: '可能偶尔产生不正确的信息',
|
||||
generateHarmfulInfo: '可能偶尔产生有害的指令或有偏见的内容',
|
||||
onlyKnowBefore2021: '对2021年之后的世界和事件了解有限'
|
||||
onlyKnowBefore2021: '对2021年之后的世界和事件了解有限',
|
||||
errorBusy: 'Worker正在忙碌中,请稍后重试',
|
||||
errorApiError: '回答失败,请稍后重试',
|
||||
errorBadRequest: '请求内容不规范,请重新提问'
|
||||
};
|
||||
@@ -10,7 +10,15 @@ export interface IError {
|
||||
detail: string;
|
||||
}
|
||||
|
||||
export enum IMessageState {
|
||||
PENDING = 'pending',
|
||||
ANSWERING = 'answering',
|
||||
FINISHED = 'finished',
|
||||
FAILED = 'failed'
|
||||
}
|
||||
|
||||
export interface IMessage {
|
||||
state?: IMessageState;
|
||||
content: IContent;
|
||||
author: IUser | IBot;
|
||||
error?: IError;
|
||||
|
||||
@@ -17,7 +17,12 @@
|
||||
>
|
||||
<el-row>
|
||||
<el-col :span="12" :offset="6">
|
||||
<message :content="message.content" :author="message.author" :error="message.error"> </message>
|
||||
<message
|
||||
:content="message.content"
|
||||
:author="message.author"
|
||||
:error="message.error"
|
||||
:state="message.state"
|
||||
/>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</div>
|
||||
@@ -41,7 +46,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { IMessage } from '@/operators/message/models';
|
||||
import { IMessage, IMessageState } from '@/operators/message/models';
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElRow, ElCol, ElMessage } from 'element-plus';
|
||||
import Message from '@/components/conversation/Message.vue';
|
||||
@@ -152,6 +157,7 @@ export default defineComponent({
|
||||
if (!this.user) {
|
||||
return;
|
||||
}
|
||||
this.loading = true;
|
||||
applicationOperator
|
||||
.getAll({
|
||||
user_id: this.user.id,
|
||||
@@ -166,6 +172,10 @@ export default defineComponent({
|
||||
this.token = token;
|
||||
}
|
||||
}
|
||||
this.loading = false;
|
||||
})
|
||||
.catch(() => {
|
||||
this.loading = false;
|
||||
});
|
||||
},
|
||||
onApply() {
|
||||
@@ -216,7 +226,8 @@ export default defineComponent({
|
||||
...this.user,
|
||||
avatar: this.user?.avatar || userAvatar,
|
||||
type: 'user'
|
||||
}
|
||||
},
|
||||
state: IMessageState.FINISHED
|
||||
});
|
||||
this.messages.push({
|
||||
content: {
|
||||
@@ -226,7 +237,8 @@ export default defineComponent({
|
||||
type: 'bot',
|
||||
nickname: 'ChatGPT',
|
||||
avatar: chatgptAvatar
|
||||
}
|
||||
},
|
||||
state: IMessageState.PENDING
|
||||
});
|
||||
this.answering = true;
|
||||
this.input = '';
|
||||
@@ -259,6 +271,7 @@ export default defineComponent({
|
||||
const answer = jsonData.answer;
|
||||
const conversationId = jsonData.conversation_id;
|
||||
this.messages[this.messages.length - 1].content.value = answer;
|
||||
this.messages[this.messages.length - 1].state = IMessageState.ANSWERING;
|
||||
if (conversationId && this.$route.name !== ROUTE_CONVERSATION_DETAIL) {
|
||||
this.$router.push({
|
||||
name: ROUTE_CONVERSATION_DETAIL,
|
||||
@@ -273,6 +286,9 @@ export default defineComponent({
|
||||
)
|
||||
.then(() => {
|
||||
this.answering = false;
|
||||
if (this.messages && this.messages.length > 0) {
|
||||
this.messages[this.messages.length - 1].state = IMessageState.FINISHED;
|
||||
}
|
||||
const conversations: IConversation[] = this.$store.getters.conversations;
|
||||
const hitConversations = conversations.filter((c: IConversation) => c.id === this.conversationId);
|
||||
if (!hitConversations || hitConversations.length === 0) {
|
||||
@@ -296,6 +312,9 @@ export default defineComponent({
|
||||
})
|
||||
.catch((error) => {
|
||||
this.answering = false;
|
||||
if (this.messages && this.messages.length > 0) {
|
||||
this.messages[this.messages.length - 1].state = IMessageState.FAILED;
|
||||
}
|
||||
if (error?.response?.data) {
|
||||
const data = error?.response?.data;
|
||||
if (this.messages && this.messages.length > 0) {
|
||||
@@ -311,9 +330,12 @@ export default defineComponent({
|
||||
<style lang="scss" scoped>
|
||||
.conversation {
|
||||
min-height: 100vh;
|
||||
position: relative;
|
||||
flex-direction: column;
|
||||
display: flex;
|
||||
.messages-wrapper,
|
||||
.messages-wrapper {
|
||||
margin-bottom: 200px;
|
||||
}
|
||||
.introduction-wrapper {
|
||||
flex: 1;
|
||||
}
|
||||
@@ -330,9 +352,12 @@ export default defineComponent({
|
||||
background-color: #ffffff;
|
||||
}
|
||||
}
|
||||
.new-message {
|
||||
height: 50px;
|
||||
margin-bottom: 30px;
|
||||
.footer {
|
||||
background-image: linear-gradient(180deg, hsla(0, 0%, 100%, 0) 13.94%, #fff 54.73%);
|
||||
position: fixed;
|
||||
left: 300px;
|
||||
bottom: 0;
|
||||
width: calc(100% - 300px);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user