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