This commit is contained in:
AceDataCloud committed 2023-12-11 01:39:36 +08:00
1 parent cea31c5011
commit 297dd3ef2f
30 files changed
+55 -1386

No files matched your search

+2 -3
View File
@@ -29,9 +29,8 @@
import { defineComponent } from 'vue';
import { ElTooltip, ElButton, ElSkeleton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_INDEX } from '@/router/constants';
import { apiUsageOperator, midjourneyOperator, MidjourneyImagineState, IApplication, chatOperator } from '@/operators';
import { chatgptOperator } from '@/operators/api/chatgpt/operator';
import { ROUTE_CHAT_CONVERSATION } from '@/router/constants';
import { apiUsageOperator, IApplication, chatOperator } from '@/operators';
import { IChatConversation } from '@/operators/chat/models';
interface IData {
+2 -2
View File
@@ -1,8 +1,8 @@
<template>
<div v-if="application" class="status">
<span class="info">
{{ $t('conversation.message.usedCount') }}: {{ application?.used_amount }}
{{ $t('conversation.message.remainingCount') }}: {{ application?.remaining_amount }}
{{ $t('common.message.usedCount') }}: {{ application?.used_amount }} {{ $t('common.message.remainingCount') }}:
{{ application?.remaining_amount }}
</span>
<span class="actions">
<el-button size="small" type="primary" @click="onBuy">{{ $t('common.button.buyMore') }}</el-button>
@@ -1,40 +0,0 @@
<template>
<div class="box"></div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: 'AnwseringMark',
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,117 +0,0 @@
<template>
<div class="navigation-item">
<div class="icon">
<font-awesome-icon :icon="icon" class="icon-rotate" />
</div>
<div v-if="!editing && !deleting" class="title">
{{ title }}
</div>
<div v-if="deleting && !editing" class="title">
{{ `${$t('conversation.message.confirmDelete')}"${title}"?` }}
</div>
<div v-if="editing && !deleting" class="title">
<el-input v-model="newTitle" @keydown.enter="onConfirm" />
</div>
<div v-if="!editing && !deleting" class="edit">
<font-awesome-icon icon="fa-solid fa-pen-to-square" class="icon-edit" @click="editing = true" />
</div>
<div v-if="!editing && !deleting" class="delete">
<font-awesome-icon icon="fa-solid fa-trash" class="icon-delete" @click="deleting = true" />
</div>
<div v-if="editing || deleting" class="confirm">
<font-awesome-icon icon="fa-solid fa-check" class="icon-confirm" @click="onConfirm" />
</div>
<div v-if="editing || deleting" class="cancel">
<font-awesome-icon icon="fa-solid fa-xmark" class="icon-cancel" @click="onCancel" />
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { ElInput } from 'element-plus';
export default defineComponent({
name: 'ConversationNavigatorItem',
components: {
FontAwesomeIcon,
ElInput
},
props: {
icon: {
type: String,
required: true
},
title: {
type: String,
required: true
}
},
emits: ['update:title', 'delete'],
data() {
return {
deleting: false,
editing: false,
newTitle: this.title
};
},
methods: {
onChangeTitle(val: string) {
this.newTitle = val;
},
onConfirm() {
if (this.editing) {
this.$emit('update:title', this.newTitle);
this.editing = false;
} else if (this.deleting) {
this.$emit('delete');
this.deleting = false;
}
},
onCancel() {
if (this.editing) {
this.editing = false;
} else if (this.deleting) {
this.deleting = false;
}
}
}
});
</script>
<style lang="scss">
.navigation-item {
display: flex;
flex-direction: row;
cursor: pointer;
height: 44px;
margin-top: 5px;
padding: 0 15px;
line-height: 44px;
border-radius: 3px;
&:hover {
background-color: hsla(240, 9%, 59%, 0.1);
}
.icon {
width: 30px;
height: 30px;
min-width: 30px;
}
.title {
flex: 1;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.edit,
.delete,
.confirm,
.cancel {
width: 25px;
height: 30px;
min-width: 25px;
text-align: right;
}
}
</style>
@@ -1,110 +0,0 @@
<template>
<div class="introduction">
<h2 class="title">ChatGPT</h2>
<el-row class="introduction-items" justify="center" :gutter="15">
<el-col :md="8" :sm="24" :xs="24">
<div class="text-center">
<font-awesome-icon icon="fa-regular fa-sun" class="icon icon-rotate" />
</div>
<h3 class="subtitle">{{ $t('conversation.title.example') }}</h3>
<introduction-item
:content="$t('conversation.message.writeCode')"
class="cursor-pointer"
@click="$emit('draft', $t('conversation.message.writeCode'))"
/>
<introduction-item
:content="$t('conversation.message.writeEmail')"
class="cursor-pointer"
@click="$emit('draft', $t('conversation.message.writeEmail'))"
/>
<introduction-item
:content="$t('conversation.message.explainDefinition')"
class="cursor-pointer"
@click="$emit('draft', $t('conversation.message.explainDefinition'))"
/>
</el-col>
<el-col :md="8" :sm="24" :xs="24">
<div class="text-center">
<font-awesome-icon icon="fa-solid fa-bolt" class="icon icon-rotate" />
</div>
<h3 class="subtitle">{{ $t('conversation.title.capabilities') }}</h3>
<introduction-item :content="$t('conversation.message.rememberHistory')" />
<introduction-item :content="$t('conversation.message.supportStream')" />
<introduction-item :content="$t('conversation.message.rejectInvalidPrompt')" />
</el-col>
<el-col :md="8" :sm="24" :xs="24">
<div class="text-center">
<font-awesome-icon icon="fa-solid fa-triangle-exclamation" class="icon icon-rotate" />
</div>
<h3 class="subtitle">{{ $t('conversation.title.limitations') }}</h3>
<introduction-item :content="$t('conversation.message.generateInCorrect')" />
<introduction-item :content="$t('conversation.message.generateHarmfulInfo')" />
<introduction-item :content="$t('conversation.message.onlyKnowBefore2021')" />
</el-col>
</el-row>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import IntroductionItem from './IntroductionItem.vue';
import { ElRow, ElCol } from 'element-plus';
export default defineComponent({
name: 'ConversationIntroduction',
components: {
FontAwesomeIcon,
IntroductionItem,
ElRow,
ElCol
},
emits: ['draft'],
data() {
return {};
},
computed: {}
});
</script>
<style lang="scss" scoped>
.introduction {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
.title {
height: 70px;
text-align: center;
display: block;
font-size: 36px;
font-weight: 600;
margin-bottom: 50px;
}
.introduction-items {
height: fit-content;
margin-bottom: 100px;
.icon {
font-size: 20px;
margin-bottom: 10px;
}
.subtitle {
text-align: center;
font-size: 18px;
margin-bottom: 20px;
}
.introduction-item {
margin-bottom: 15px;
}
}
}
@media (max-width: 767px) {
.introduction {
width: 90%;
left: 5%;
transform: translateY(-50%);
}
}
</style>
@@ -1,32 +0,0 @@
<template>
<div class="introduction-item">
{{ content }}
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
name: 'ConversationIntroductionItem',
props: {
content: {
type: String,
required: true
}
},
data() {
return {};
},
computed: {}
});
</script>
<style lang="scss" scoped>
.introduction-item {
font-size: 14px;
background-color: #eee;
color: #333;
padding: 10px 20px;
}
</style>
-125
View File
@@ -1,125 +0,0 @@
<template>
<div class="message">
<el-image :src="author.avatar" class="icon" />
<message-content :content="content" class="content" :error="error" :state="state" />
</div>
<div class="operations">
<el-button v-if="author.type === 'bot' && content.value" class="operation" size="small" @click="onCopy">
<font-awesome-icon icon="fa-regular fa-copy" class="icon-copy" />
{{ $t('common.button.copy') }}
</el-button>
<el-button
v-if="author.type === 'bot' && (state === messageState.ANSWERING || state === messageState.PENDING)"
class="operation"
size="small"
@click="onStop"
>
<font-awesome-icon icon="fa-solid fa-stop" class="icon-stop" />
{{ $t('common.button.stop') }}
</el-button>
</div>
</template>
<script lang="ts">
import { IBot, IUser } from '@/operators';
import { IContent, IError, IMessageState } from '@/operators/message/models';
import { defineComponent } from 'vue';
import MessageContent from './MessageContent.vue';
import { ElImage, ElButton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import copy from 'copy-to-clipboard';
interface IData {
copied: boolean;
messageState: typeof IMessageState;
}
export default defineComponent({
name: 'Message',
components: {
MessageContent,
ElImage,
ElButton,
FontAwesomeIcon
},
props: {
content: {
type: Object as () => IContent,
required: true
},
author: {
type: Object as () => IUser | IBot,
required: true
},
error: {
type: Object as () => IError | undefined,
required: false,
default() {
return undefined;
}
},
state: {
type: Object as () => IMessageState,
required: false,
default() {
return IMessageState.FINISHED;
}
}
},
emits: ['stop'],
data(): IData {
return {
copied: false,
messageState: IMessageState
};
},
computed: {
conversationId() {
return this.$route.params?.id?.toString();
}
},
methods: {
onCopy() {
copy(this.content.value, {
debug: true
});
this.copied = true;
setTimeout(() => {
this.copied = false;
}, 3000);
},
onStop() {
this.$emit('stop');
}
}
});
</script>
<style lang="scss" scoped>
.message {
display: flex;
flex-direction: row;
.icon {
width: 30px;
height: 30px;
margin-right: 20px;
border-radius: 3px;
min-width: 30px;
}
.content {
flex: 1;
}
}
.operations {
width: fit-content;
margin: auto;
.operation {
margin-top: 15px;
}
.fa-copy,
.fa-stop {
margin-right: 5px;
}
}
</style>
@@ -1,107 +0,0 @@
<template>
<markdown-renderer :content="content?.value" class="content" />
<answering-mark v-if="shouldShowAnsweringMark" />
<div class="alerts">
<el-alert v-if="errorText" :title="errorText" type="error" :closable="false" />
</div>
<div class="operations pt-2 ml-2">
<el-button v-if="shouldBuyMore" type="primary" size="small" @click="onBuyMore">{{
$t('common.button.buyMore')
}}</el-button>
</div>
</template>
<script lang="ts">
import { IContent, IError, IMessageState } from '@/operators/message/models';
import { defineComponent } from 'vue';
import MarkdownRenderer from '@/components/common/MarkdownRenderer.vue';
import { ElAlert, ElButton } from 'element-plus';
import {
ERROR_CODE_API_ERROR,
ERROR_CODE_BUSY,
ERROR_CODE_BAD_REQUEST,
ERROR_CODE_NO_CONVERSATION,
ERROR_CODE_USED_UP,
ERROR_CODE_UNKNOWN,
ERROR_CODE_TIMEOUT
} from '@/constants';
import AnsweringMark from './AnsweringMark.vue';
export default defineComponent({
name: 'MessageContent',
components: {
MarkdownRenderer,
ElAlert,
AnsweringMark,
ElButton
},
props: {
content: {
type: Object as () => IContent,
required: true
},
error: {
type: Object as () => IError | undefined,
required: false,
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;
},
shouldBuyMore() {
// @ts-ignore
return this.error?.code === ERROR_CODE_USED_UP;
},
errorText() {
if (this.error?.code === ERROR_CODE_USED_UP) {
return this.$t('conversation.message.errorUsedUp');
}
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');
}
if (this.error?.code === ERROR_CODE_NO_CONVERSATION) {
return this.$t('conversation.message.errorNoConversation');
}
if (this.error?.code === ERROR_CODE_UNKNOWN) {
return this.$t('conversation.message.errorUnknown');
}
if (this.error?.code === ERROR_CODE_TIMEOUT) {
return this.$t('conversation.message.errorTimeout');
}
return undefined;
}
},
methods: {
onBuyMore() {
window.open('https://data.zhishuyun.com/services/b1fbcc32-e218-4253-9dc3-4fe600a1bfb9', '_blank');
}
}
});
</script>
<style lang="scss">
.content {
overflow-x: hidden;
}
</style>
@@ -1,176 +0,0 @@
<template>
<div class="new-message-box">
<span v-if="application" class="new-message-box-usage-info">
{{ $t('conversation.message.usedCount') }}: {{ application?.used_amount }}
{{ $t('conversation.message.remainingCount') }}: {{ application?.remaining_amount }}
</span>
<div class="flex">
<div class="new-message-input-box">
<el-input
v-model="value"
type="textarea"
resize="none"
:disabled="initializing || !application || answering"
class="new-message-input"
:placeholder="$t('conversation.message.newMessagePlaceholder')"
@keydown.enter.exact.prevent="$emit('send')"
>
</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="initializing" class="new-message-apply">
<span class="ml-1">{{ $t('conversation.message.initializing') }}</span>
</div>
<div v-else-if="!application" class="new-message-apply">
<span class="mr-2">{{ $t('conversation.message.apiInfo') }}</span>
<span>
<el-button type="primary" size="small" @click="confirming = true">
{{ $t('common.button.apply') }}
</el-button>
</span>
<span class="ml-1">{{ $t('conversation.message.tryForFree') }}</span>
</div>
</div>
</div>
</div>
<application-confirm
v-if="api"
v-model.visible="confirming"
:object="api"
:type="applicationType.API"
@apply="$emit('apply')"
/>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElInput, ElButton, ElSelect, ElOption } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { IApi, IApplication } from '@/operators';
import { IApplicationType } from '@/operators';
import ApplicationConfirm from '@/components/application/Confirm.vue';
import VoiceRecognition from './VoiceRecognition.vue';
import { APIS } from '@/constants/api';
interface IData {
applicationType: typeof IApplicationType;
value: string;
confirming: boolean;
}
export default defineComponent({
name: 'NewMessageBox',
components: {
ElInput,
ElButton,
FontAwesomeIcon,
ApplicationConfirm,
VoiceRecognition
},
props: {
initializing: {
type: Boolean,
required: false,
default: false
},
answering: {
type: Boolean,
required: false,
default: false
},
modelValue: {
type: String,
required: true
},
api: {
type: Object as () => IApi | undefined,
required: true
},
application: {
type: Object as () => IApplication | undefined,
required: true
}
},
emits: ['send', 'update:modelValue', 'apply'],
data(): IData {
return {
applicationType: IApplicationType,
value: this.modelValue,
confirming: false
};
},
computed: {
conversationId() {
return this.$route.params?.id?.toString();
},
activeApiId() {
return this.$store.getters.activeApiId;
}
},
watch: {
value(val) {
this.$emit('update:modelValue', val);
},
modelValue(val) {
if (val !== this.value) {
this.value = val;
}
}
},
methods: {}
});
</script>
<style lang="scss" scoped>
.new-message-box {
position: relative;
margin-bottom: 40px;
.new-message-input-box {
position: relative;
width: 100%;
height: 100%;
.new-message-input {
height: 50px;
}
.new-message-info-input {
position: absolute;
bottom: -25px;
left: 5px;
font-size: 12px;
color: var(--el-text-color-regular);
}
.new-message-operations {
position: absolute;
bottom: 12px;
right: 10px;
color: var(--el-text-color-regular);
.icon-send {
cursor: pointer;
}
}
.new-message-apply {
position: absolute;
top: 50%;
left: 50%;
width: 100%;
text-align: center;
transform: translate(-50%, -50%);
font-size: 12px;
color: #666;
}
}
.new-message-box-usage-info {
color: #999;
font-size: 12px;
text-align: center;
display: block;
margin-bottom: 3px;
}
}
</style>
Whitespace-only changes.
@@ -1,81 +0,0 @@
<template>
<font-awesome-icon icon="fa-solid fa-microphone" class="icon-edit" @click="onToggleRecognition" />
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
export default defineComponent({
name: 'VoiceRecognition',
components: {
FontAwesomeIcon
},
emits: ['finished'],
data() {
return {
supported: false,
recognition: undefined,
started: false,
result: ''
};
},
mounted() {
if ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) {
this.supported = true;
// @ts-ignore
this.recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
if (this.recognition) {
// @ts-ignore
this.recognition.lang = 'zh-CN';
}
}
// @ts-ignore
this.recognition?.addEventListener('result', (event) => {
const transcript = event.results[0][0].transcript;
this.result = transcript;
console.log('result', this.result);
});
// @ts-ignore
this.recognition?.addEventListener('error', (event) => {
console.log('Recognition error:', event.error);
});
// @ts-ignore
this.recognition?.addEventListener('end', () => {
console.log('Recognition ended');
console.log('result', this.result);
this.$emit('finished', this.result);
});
},
methods: {
startRecognition() {
// @ts-ignore
this.recognition?.start();
this.started = true;
},
stopRecognition() {
// @ts-ignore
this.recognition?.stop();
this.started = true;
},
onToggleRecognition() {
if (!this.started) {
this.startRecognition();
} else {
this.stopRecognition();
}
}
}
});
</script>
<style lang="scss" scoped>
.introduction-item {
font-size: 14px;
background-color: #eee;
color: #333;
padding: 10px 20px;
}
</style>