add break line and stop generate

This commit is contained in:
AceDataCloud committed 2023-04-11 23:18:29 +08:00
1 parent 62ec02e6c9
commit 5400cc08de
9 files changed
+72 -23

No files matched your search

+7 -4
View File
@@ -30,6 +30,13 @@ body {
border-radius: 9999px;
}
.el-textarea {
border-radius: 10px;
textarea {
border-radius: 10px;
}
}
.el-input {
.el-input__wrapper {
border-radius: 10px;
@@ -63,7 +70,3 @@ body {
width: 100% !important;
}
}
.color-primary {
color: var(--el-color-primary);
}
+9
View File
@@ -8,6 +8,10 @@
<font-awesome-icon icon="fa-regular fa-copy" class="icon-copy" />
{{ $t('common.button.copy') }}
</el-button>
<el-button v-if="author.type === 'bot' && content.value" class="operation" size="small" @click="onStop">
<font-awesome-icon icon="fa-regular fa-copy" class="icon-stop" />
{{ $t('common.button.stop') }}
</el-button>
</div>
</template>
@@ -56,6 +60,7 @@ export default defineComponent({
}
}
},
emits: ['stop'],
data(): IData {
return {
copied: false
@@ -75,6 +80,9 @@ export default defineComponent({
setTimeout(() => {
this.copied = false;
}, 3000);
},
onStop() {
this.$emit('stop');
}
}
});
@@ -99,6 +107,7 @@ export default defineComponent({
.operations {
width: fit-content;
margin: auto;
padding-top: 15px;
.fa-copy {
margin-right: 5px;
}
+26 -9
View File
@@ -2,16 +2,19 @@
<div class="new-message-box">
<el-input
v-model="value"
type="textarea"
resize="none"
:disabled="!application || answering"
class="new-message-input"
:placeholder="$t('conversation.message.newMessagePlaceholder')"
@keyup.enter="$emit('send')"
@keydown.enter.exact.prevent="$emit('send')"
>
<template #suffix>
<voice-recognition v-if="false" class="mr-1" @finished="value = $event" />
<font-awesome-icon icon="fa-regular fa-paper-plane" class="icon-send" @click="$emit('send')" />
</template>
</el-input>
<span class="new-message-info-input">{{ $t('conversation.message.howToBreakLine') }}</span>
<div class="new-message-operations">
<voice-recognition v-if="false" class="mr-1" @finished="value = $event" />
<font-awesome-icon icon="fa-regular fa-paper-plane" class="icon-send" @click="$emit('send')" />
</div>
<div v-if="!application" class="new-message-apply">
<div v-if="!initializing">
<span class="mr-2">{{ $t('conversation.message.apiInfo') }}</span>
@@ -38,7 +41,7 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { ElInput, ElButton } from 'element-plus';
import { ElInput, ElButton, ElText } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { IApi, IApplication } from '@/operators';
import { IApplicationType } from '@/operators';
@@ -114,12 +117,26 @@ export default defineComponent({
<style lang="scss" scoped>
.new-message-box {
position: relative;
margin-bottom: 30px;
margin-bottom: 40px;
.new-message-input {
height: 50px;
}
.icon-send {
cursor: pointer;
.new-message-operations {
position: absolute;
bottom: 12px;
right: 10px;
color: var(--el-text-color-regular);
.icon-send {
cursor: pointer;
}
}
.new-message-info-input {
position: absolute;
bottom: -25px;
left: 5px;
font-size: 12px;
color: var(--el-text-color-regular);
}
.new-message-apply {
+1
View File
@@ -6,4 +6,5 @@ export const ERROR_CODE_BAD_REQUEST = 'bad_request';
export const ERROR_CODE_NO_CONVERSATION = 'no_conversation';
export const ERROR_CODE_USED_UP = 'used_up';
export const ERROR_CODE_UNKNOWN = 'unknown';
export const ERROR_CODE_CANCELED = 'canceled';
export const ERROR_CODE_TIMEOUT = 'timeout';
+1 -1
View File
@@ -17,5 +17,5 @@ export default {
rotateCredentialSuccessfully: '密钥重置成功',
rotateCredentialFailed: '密钥重置失败,请联系客服处理',
updateFailed: '修改失败',
updateSuccessfully: '修改成功'
updateSuccessfully: '修改成功',
};
+2 -1
View File
@@ -27,5 +27,6 @@ export default {
fillExample: '填写样例',
buyMore: '购买更多',
update: '更新',
copy: '复制'
copy: '复制',
stop: '停止'
};
+2 -1
View File
@@ -21,5 +21,6 @@ export default {
confirmDelete: '确定删除',
errorUsedUp: '您的套餐次数已经用完,请购买更多次数继续使用',
errorUnknown: '服务器出现未知错误,请稍后重试或联系客服',
errorTimeout: '回答问题超时,请稍后重试'
errorTimeout: '回答问题超时,请稍后重试',
howToBreakLine: '按 Shift+Enter 键可以换行输入'
};
+22 -7
View File
@@ -22,6 +22,7 @@
:author="message.author"
:error="message.error"
:state="message.state"
@stop="onStop"
/>
</el-col>
</el-row>
@@ -65,10 +66,11 @@ import {
IApplicationType
} from '@/operators';
import { ROUTE_AUTH_LOGIN, ROUTE_CONVERSATION_DETAIL } from '@/router/constants';
import { ERROR_CODE_DUPLICATION, ERROR_CODE_UNKNOWN, ERROR_CODE_UNVERIFIED } from '@/constants';
import { ERROR_CODE_CANCELED, ERROR_CODE_DUPLICATION, ERROR_CODE_UNKNOWN, ERROR_CODE_UNVERIFIED } from '@/constants';
import { getVerificationUrl } from '@/utils';
import { IConversation } from '@/operators/conversation/models';
import Introduction from '@/components/conversation/Introduction.vue';
import axios from 'axios';
export interface IData {
input: string;
@@ -78,6 +80,7 @@ export interface IData {
token: string | undefined;
api: IApi | undefined;
application: IApplication | undefined;
canceler: AbortController | undefined;
}
export default defineComponent({
@@ -97,7 +100,8 @@ export default defineComponent({
messages: [],
token: undefined,
api: undefined,
application: undefined
application: undefined,
canceler: undefined
};
},
computed: {
@@ -158,6 +162,9 @@ export default defineComponent({
});
});
},
async onStop() {
this.canceler?.abort();
},
async onCheckApplication() {
if (!this.user) {
return;
@@ -217,7 +224,7 @@ export default defineComponent({
if (this.answering) {
return;
}
if (!this.input) {
if (!this.input.trim()) {
ElMessage.error(this.$t('conversation.message.noInput'));
return;
}
@@ -253,6 +260,7 @@ export default defineComponent({
setTimeout(() => {
this.scrollDown();
}, 100);
this.canceler = new AbortController();
chatgptOperator
.post(
{
@@ -272,18 +280,16 @@ export default defineComponent({
accept: 'application/x-ndjson',
'content-type': 'application/json'
},
signal: this.canceler.signal,
responseType: 'stream',
onDownloadProgress: (event) => {
const response = event.target.response;
const lines = response.split('\r\n').filter((line: string) => !!line);
const lastLine = lines[lines.length - 1];
if (lastLine) {
this.scrollDown();
const jsonData = JSON.parse(lastLine);
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,
@@ -292,6 +298,11 @@ export default defineComponent({
}
});
}
if (this.conversationId === conversationId) {
this.scrollDown();
this.messages[this.messages.length - 1].content.value = answer;
this.messages[this.messages.length - 1].state = IMessageState.ANSWERING;
}
}
}
}
@@ -329,7 +340,11 @@ export default defineComponent({
if (this.messages && this.messages.length > 0) {
this.messages[this.messages.length - 1].state = IMessageState.FAILED;
}
if (error?.response?.data) {
if (axios.isCancel(error)) {
this.messages[this.messages.length - 1].error = {
code: ERROR_CODE_CANCELED
};
} else if (error?.response?.data) {
const data = error?.response?.data;
if (this.messages && this.messages.length > 0) {
this.messages[this.messages.length - 1].error = data;
+2
View File
@@ -8,6 +8,7 @@ import {
} from '@fortawesome/free-regular-svg-icons';
import {
faMicrophone as faSolidMicrophone,
faStop as faSolidStop,
faRotateRight as faSolidRotateRight,
faCheck as faSolidCheck,
faPlus as faSolidPlus,
@@ -32,6 +33,7 @@ library.add(faSolidBolt);
library.add(faSolidMicrophone);
library.add(faSolidPlus);
library.add(faSolidQuestion);
library.add(faSolidStop);
library.add(faSolidTriangleExclamation);
library.add(faSolidUpRightFromSquare);
library.add(faSolidArrowsRotate);