Update onboarding and error handling experience (#29)
This commit is contained in:
1 parent
916df4b482
commit
9c54ffb7a8
23 files changed
+228
-43
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "minor",
|
||||||
|
"comment": "update onboarding experience ",
|
||||||
|
"packageName": "@zhishuyun/hub",
|
||||||
|
"email": "cqc@germey.cn",
|
||||||
|
"dependentChangeType": "patch"
|
||||||
|
}
|
||||||
@@ -1,18 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-dialog
|
<el-dialog :model-value="visible" width="500px" center @close="$emit('update:visible', false)">
|
||||||
:model-value="visible"
|
|
||||||
width="500px"
|
|
||||||
:title="$t('application.message.confirmApplying')"
|
|
||||||
center
|
|
||||||
@close="$emit('update:visible', false)"
|
|
||||||
>
|
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<el-descriptions :column="1">
|
<el-descriptions :column="1">
|
||||||
<el-descriptions-item :label="$t('application.field.type')">
|
|
||||||
<span>
|
|
||||||
{{ $t('application.field.api') }}
|
|
||||||
</span>
|
|
||||||
</el-descriptions-item>
|
|
||||||
<el-descriptions-item :label="$t('application.field.name')">
|
<el-descriptions-item :label="$t('application.field.name')">
|
||||||
{{ object?.title }}
|
{{ object?.title }}
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
@@ -22,6 +11,9 @@
|
|||||||
</span>
|
</span>
|
||||||
</el-descriptions-item>
|
</el-descriptions-item>
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
|
<p class="description">
|
||||||
|
{{ $t('application.message.applyDescription') }}
|
||||||
|
</p>
|
||||||
<el-divider class="my-2" />
|
<el-divider class="my-2" />
|
||||||
<div class="policy">
|
<div class="policy">
|
||||||
<el-checkbox v-model="checked" size="large" class="policy-checkbox" />
|
<el-checkbox v-model="checked" size="large" class="policy-checkbox" />
|
||||||
@@ -29,7 +21,9 @@
|
|||||||
<span class="policy-title highlight" @click="showPolicy = true"> {{ $t('application.message.policy') }} </span>
|
<span class="policy-title highlight" @click="showPolicy = true"> {{ $t('application.message.policy') }} </span>
|
||||||
<application-policy v-model.visible="showPolicy" />
|
<application-policy v-model.visible="showPolicy" />
|
||||||
</div>
|
</div>
|
||||||
<el-button type="primary" class="btn btn-apply" @click="onApply">{{ $t('common.button.apply') }}</el-button>
|
<el-button type="primary" class="btn btn-apply" @click="onApply">
|
||||||
|
{{ $t('common.button.applyForFree') }}
|
||||||
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
</el-dialog>
|
</el-dialog>
|
||||||
</template>
|
</template>
|
||||||
@@ -76,7 +70,7 @@ export default defineComponent({
|
|||||||
data(): IData {
|
data(): IData {
|
||||||
return {
|
return {
|
||||||
applicationType: IApplicationType,
|
applicationType: IApplicationType,
|
||||||
checked: false,
|
checked: true,
|
||||||
showPolicy: false
|
showPolicy: false
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@@ -97,6 +91,10 @@ export default defineComponent({
|
|||||||
.content {
|
.content {
|
||||||
padding: 10px 40px;
|
padding: 10px 40px;
|
||||||
|
|
||||||
|
.description {
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
.btn-apply {
|
.btn-apply {
|
||||||
border-radius: 20px;
|
border-radius: 20px;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
<el-input
|
<el-input
|
||||||
v-model="questionValue"
|
v-model="questionValue"
|
||||||
:rows="1"
|
:rows="1"
|
||||||
|
:disabled="disabled"
|
||||||
class="input"
|
class="input"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
:placeholder="$t('chat.message.newMessagePlaceholder')"
|
:placeholder="$t('chat.message.newMessagePlaceholder')"
|
||||||
@@ -60,6 +61,11 @@ export default defineComponent({
|
|||||||
ElUpload
|
ElUpload
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
|
disabled: {
|
||||||
|
type: Boolean,
|
||||||
|
required: false,
|
||||||
|
default: false
|
||||||
|
},
|
||||||
references: {
|
references: {
|
||||||
type: Array,
|
type: Array,
|
||||||
required: false,
|
required: false,
|
||||||
@@ -146,6 +152,10 @@ export default defineComponent({
|
|||||||
width: 400px;
|
width: 400px;
|
||||||
bottom: 45px;
|
bottom: 45px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.el-textarea.is-disabled .el-textarea__inner {
|
||||||
|
background-color: initial;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :class="'message ' + message.role" :role="message.role">
|
<div
|
||||||
|
:class="{
|
||||||
|
message: true,
|
||||||
|
[message.role as string]: true,
|
||||||
|
hidden: errorText && message.role === 'assistant'
|
||||||
|
}"
|
||||||
|
:role="message.role"
|
||||||
|
>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<markdown-renderer v-if="!Array.isArray(message.content)" :content="message?.content" />
|
<markdown-renderer v-if="!Array.isArray(message.content)" :content="message?.content" />
|
||||||
<div v-else>
|
<div v-else>
|
||||||
@@ -9,31 +16,37 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<answering-mark v-if="message.state === messageState.PENDING" />
|
<answering-mark v-if="message.state === messageState.PENDING" />
|
||||||
<el-alert v-if="errorText && message.role === 'assistant'" :title="errorText" type="error" :closable="false" />
|
|
||||||
</div>
|
</div>
|
||||||
<div class="operations">
|
<div class="operations">
|
||||||
<copy-to-clipboard v-if="!Array.isArray(message.content)" :content="message.content" class="btn-copy" />
|
<copy-to-clipboard v-if="!Array.isArray(message.content)" :content="message.content!" class="btn-copy" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<el-alert v-if="errorText" class="error" :title="errorText" type="error" :closable="false" />
|
||||||
|
<el-button v-if="showBuyMore" type="primary" class="btn btn-buy" size="small" @click="onBuyMore">
|
||||||
|
{{ $t('common.button.buyMore') }}
|
||||||
|
</el-button>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import AnsweringMark from './AnsweringMark.vue';
|
import AnsweringMark from './AnsweringMark.vue';
|
||||||
import copy from 'copy-to-clipboard';
|
import copy from 'copy-to-clipboard';
|
||||||
import { ElAlert } from 'element-plus';
|
import { ElAlert, ElButton } from 'element-plus';
|
||||||
import MarkdownRenderer from '@/components/common/MarkdownRenderer.vue';
|
import MarkdownRenderer from '@/components/common/MarkdownRenderer.vue';
|
||||||
import { IChatMessage, IChatMessageState } from '@/operators';
|
import { IApplication, IChatMessage, IChatMessageState, ROLE_ASSISTANT } from '@/operators';
|
||||||
import CopyToClipboard from '../common/CopyToClipboard.vue';
|
import CopyToClipboard from '../common/CopyToClipboard.vue';
|
||||||
import {
|
import {
|
||||||
ERROR_CODE_API_ERROR,
|
ERROR_CODE_API_ERROR,
|
||||||
ERROR_CODE_BAD_REQUEST,
|
ERROR_CODE_BAD_REQUEST,
|
||||||
ERROR_CODE_CONTENT_TOO_LARGE,
|
ERROR_CODE_CONTENT_TOO_LARGE,
|
||||||
|
ERROR_CODE_NOT_APPLIED,
|
||||||
ERROR_CODE_TIMEOUT,
|
ERROR_CODE_TIMEOUT,
|
||||||
ERROR_CODE_TOO_MANY_REQUESTS,
|
ERROR_CODE_TOO_MANY_REQUESTS,
|
||||||
ERROR_CODE_UNKNOWN,
|
ERROR_CODE_UNKNOWN,
|
||||||
ERROR_CODE_USED_UP
|
ERROR_CODE_USED_UP
|
||||||
} from '@/constants';
|
} from '@/constants';
|
||||||
|
import message from '@/i18n/zh/common/message';
|
||||||
|
import { ROUTE_CONSOLE_APPLICATION_BUY } from '@/router';
|
||||||
interface IData {
|
interface IData {
|
||||||
copied: boolean;
|
copied: boolean;
|
||||||
messageState: typeof IChatMessageState;
|
messageState: typeof IChatMessageState;
|
||||||
@@ -45,12 +58,17 @@ export default defineComponent({
|
|||||||
CopyToClipboard,
|
CopyToClipboard,
|
||||||
AnsweringMark,
|
AnsweringMark,
|
||||||
MarkdownRenderer,
|
MarkdownRenderer,
|
||||||
ElAlert
|
ElAlert,
|
||||||
|
ElButton
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
message: {
|
message: {
|
||||||
type: Object as () => IChatMessage,
|
type: Object as () => IChatMessage,
|
||||||
required: true
|
required: true
|
||||||
|
},
|
||||||
|
application: {
|
||||||
|
type: Object as () => IApplication | undefined,
|
||||||
|
required: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['stop'],
|
emits: ['stop'],
|
||||||
@@ -78,21 +96,34 @@ export default defineComponent({
|
|||||||
return this.$t('chat.message.errorTooManyRequests');
|
return this.$t('chat.message.errorTooManyRequests');
|
||||||
case ERROR_CODE_CONTENT_TOO_LARGE:
|
case ERROR_CODE_CONTENT_TOO_LARGE:
|
||||||
return this.$t('chat.message.errorContentTooLarge');
|
return this.$t('chat.message.errorContentTooLarge');
|
||||||
|
case ERROR_CODE_NOT_APPLIED:
|
||||||
|
return this.$t('chat.message.errorNotApplied');
|
||||||
case ERROR_CODE_UNKNOWN:
|
case ERROR_CODE_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
return this.$t('chat.message.errorUnknown');
|
return this.$t('chat.message.errorUnknown');
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
showBuyMore() {
|
||||||
|
return this.message.role === ROLE_ASSISTANT && this.message.error?.code === ERROR_CODE_USED_UP;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onCopy() {
|
onCopy() {
|
||||||
copy(this.message.content.toString(), {
|
copy(this.message.content!.toString(), {
|
||||||
debug: true
|
debug: true
|
||||||
});
|
});
|
||||||
this.copied = true;
|
this.copied = true;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
this.copied = false;
|
this.copied = false;
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
},
|
||||||
|
onBuyMore() {
|
||||||
|
this.$router.push({
|
||||||
|
name: ROUTE_CONSOLE_APPLICATION_BUY,
|
||||||
|
params: {
|
||||||
|
id: this.application?.id
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// onStop() {
|
// onStop() {
|
||||||
// this.$emit('stop');
|
// this.$emit('stop');
|
||||||
@@ -102,12 +133,27 @@ export default defineComponent({
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
|
.error {
|
||||||
|
width: fit-content;
|
||||||
|
padding: 10px 5px 8px 5px;
|
||||||
|
height: 45px;
|
||||||
|
border-radius: 10px;
|
||||||
|
border-bottom-left-radius: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.btn-buy {
|
||||||
|
margin: 10px auto;
|
||||||
|
border-radius: 20px;
|
||||||
|
}
|
||||||
.message {
|
.message {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
&[role='system'] {
|
&[role='system'] {
|
||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
|
&.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
&.assistant {
|
&.assistant {
|
||||||
align-items: start;
|
align-items: start;
|
||||||
.content {
|
.content {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
}}</el-button>
|
}}</el-button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div v-else class="text-center info">
|
<div v-if="needApply && api" class="text-center info">
|
||||||
<span class="mr-2">{{ $t('chat.message.notApplied') }}</span>
|
<span class="mr-2">{{ $t('chat.message.notApplied') }}</span>
|
||||||
<span>
|
<span>
|
||||||
<el-button type="primary" class="btn btn-apply" size="small" @click="confirming = true">
|
<el-button type="primary" class="btn btn-apply" size="small" @click="confirming = true">
|
||||||
@@ -61,18 +61,34 @@ export default defineComponent({
|
|||||||
initializing: {
|
initializing: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false
|
default: false
|
||||||
|
},
|
||||||
|
needApply: {
|
||||||
|
type: Boolean,
|
||||||
|
default: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
emits: ['apply', 'refresh'],
|
emits: ['apply', 'refresh'],
|
||||||
data(): IData {
|
data(): IData {
|
||||||
return {
|
return {
|
||||||
confirming: false,
|
confirming: this.needApply,
|
||||||
applicationType: IApplicationType,
|
applicationType: IApplicationType,
|
||||||
api: undefined
|
api: undefined
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {},
|
computed: {
|
||||||
|
authenticated() {
|
||||||
|
return !!this.$store.state.token.access;
|
||||||
|
},
|
||||||
|
user() {
|
||||||
|
return this.$store.state.user;
|
||||||
|
}
|
||||||
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
needApply(val) {
|
||||||
|
if (val) {
|
||||||
|
this.confirming = val;
|
||||||
|
}
|
||||||
|
},
|
||||||
apiId() {
|
apiId() {
|
||||||
this.onFetchApi();
|
this.onFetchApi();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,8 +89,10 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
onLogout() {
|
async onLogout() {
|
||||||
this.$store.dispatch('resetToken');
|
await this.$store.dispatch('resetAll');
|
||||||
|
await this.$store.dispatch('chat/resetAll');
|
||||||
|
await this.$store.dispatch('midjourney/resetAll');
|
||||||
},
|
},
|
||||||
onConsole() {
|
onConsole() {
|
||||||
this.$router.push({ name: ROUTE_CONSOLE_ROOT });
|
this.$router.push({ name: ROUTE_CONSOLE_ROOT });
|
||||||
|
|||||||
@@ -8,3 +8,4 @@ export const ERROR_CODE_CANCELED = 'canceled';
|
|||||||
export const ERROR_CODE_TIMEOUT = 'timeout';
|
export const ERROR_CODE_TIMEOUT = 'timeout';
|
||||||
export const ERROR_CODE_CONTENT_TOO_LARGE = 'content_too_large';
|
export const ERROR_CODE_CONTENT_TOO_LARGE = 'content_too_large';
|
||||||
export const ERROR_CODE_TOO_MANY_REQUESTS = 'too_many_requests';
|
export const ERROR_CODE_TOO_MANY_REQUESTS = 'too_many_requests';
|
||||||
|
export const ERROR_CODE_NOT_APPLIED = 'not_applied';
|
||||||
@@ -17,5 +17,7 @@ export default {
|
|||||||
rotateCredentialSuccessfully: '密钥重置成功',
|
rotateCredentialSuccessfully: '密钥重置成功',
|
||||||
rotateCredentialFailed: '密钥重置失败,请联系客服处理',
|
rotateCredentialFailed: '密钥重置失败,请联系客服处理',
|
||||||
updateFailed: '修改失败',
|
updateFailed: '修改失败',
|
||||||
updateSuccessfully: '修改成功'
|
updateSuccessfully: '修改成功',
|
||||||
|
applyDescription: '申请之后即可立即使用,同时您会获赠一定的免费次数。',
|
||||||
|
applyDescription2: '本次申请不会产生任何费用,请放心使用。'
|
||||||
};
|
};
|
||||||
@@ -24,6 +24,7 @@ export default {
|
|||||||
errorUsedUp: '您的套餐次数已经用完,请购买更多次数继续使用',
|
errorUsedUp: '您的套餐次数已经用完,请购买更多次数继续使用',
|
||||||
errorUnknown: '服务器出现未知错误,请稍后重试或联系客服',
|
errorUnknown: '服务器出现未知错误,请稍后重试或联系客服',
|
||||||
errorTimeout: '回答问题超时,请稍后重试',
|
errorTimeout: '回答问题超时,请稍后重试',
|
||||||
|
errorNotApplied: '您尚未申请该服务,请先申请再继续提问',
|
||||||
howToUse: '按 Shift+Enter 键可以换行',
|
howToUse: '按 Shift+Enter 键可以换行',
|
||||||
noConversations: '没有历史会话,请先发起一个新的会话'
|
noConversations: '没有历史会话,请先发起一个新的会话'
|
||||||
};
|
};
|
||||||
@@ -18,6 +18,7 @@ export default {
|
|||||||
buy: '购买',
|
buy: '购买',
|
||||||
try: '测试',
|
try: '测试',
|
||||||
startForFree: '免费体验',
|
startForFree: '免费体验',
|
||||||
|
applyForFree: '免费申请',
|
||||||
apply: '申请',
|
apply: '申请',
|
||||||
refresh: '刷新',
|
refresh: '刷新',
|
||||||
pay: '支付',
|
pay: '支付',
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export interface IChatMessageContentItem {
|
|||||||
|
|
||||||
export interface IChatMessage {
|
export interface IChatMessage {
|
||||||
state?: IChatMessageState;
|
state?: IChatMessageState;
|
||||||
content: string | IChatMessageContentItem[];
|
content?: string | IChatMessageContentItem[];
|
||||||
role?: typeof ROLE_SYSTEM | typeof ROLE_ASSISTANT | typeof ROLE_USER;
|
role?: typeof ROLE_SYSTEM | typeof ROLE_ASSISTANT | typeof ROLE_USER;
|
||||||
error?: IError;
|
error?: IError;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const httpClient: AxiosInstance = axios.create({
|
|||||||
});
|
});
|
||||||
|
|
||||||
httpClient.interceptors.request.use((config) => {
|
httpClient.interceptors.request.use((config) => {
|
||||||
const accessToken = store.state.token?.access;
|
const accessToken = store.getters.token?.access;
|
||||||
if (accessToken) {
|
if (accessToken) {
|
||||||
config.headers['Authorization'] = `Bearer ${accessToken}`;
|
config.headers['Authorization'] = `Bearer ${accessToken}`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,17 +5,25 @@
|
|||||||
<api-status
|
<api-status
|
||||||
:initializing="initializing"
|
:initializing="initializing"
|
||||||
:application="application"
|
:application="application"
|
||||||
|
:need-apply="needApply"
|
||||||
:api-id="model.apiId"
|
:api-id="model.apiId"
|
||||||
@refresh="$store.dispatch('chat/getApplications')"
|
@refresh="$store.dispatch('chat/getApplications')"
|
||||||
/>
|
/>
|
||||||
<div class="dialogue">
|
<div class="dialogue">
|
||||||
<introduction v-if="messages.length === 0" @draft="onDraft" />
|
<introduction v-if="messages.length === 0" @draft="onDraft" />
|
||||||
<div v-else class="messages">
|
<div v-else class="messages">
|
||||||
<message v-for="(message, messageIndex) in messages" :key="messageIndex" :message="message" class="message" />
|
<message
|
||||||
|
v-for="(message, messageIndex) in messages"
|
||||||
|
:key="messageIndex"
|
||||||
|
:message="message"
|
||||||
|
:application="application"
|
||||||
|
class="message"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="bottom">
|
<div class="bottom">
|
||||||
<input-box
|
<input-box
|
||||||
|
:disabled="answering"
|
||||||
:question="question"
|
:question="question"
|
||||||
:references="references"
|
:references="references"
|
||||||
@update:question="question = $event"
|
@update:question="question = $event"
|
||||||
@@ -44,17 +52,19 @@ import {
|
|||||||
} from '@/operators';
|
} from '@/operators';
|
||||||
import InputBox from '@/components/chat/InputBox.vue';
|
import InputBox from '@/components/chat/InputBox.vue';
|
||||||
import ModelSelector from '@/components/chat/ModelSelector.vue';
|
import ModelSelector from '@/components/chat/ModelSelector.vue';
|
||||||
import { ERROR_CODE_CANCELED, ERROR_CODE_UNKNOWN } from '@/constants/errorCode';
|
import { ERROR_CODE_CANCELED, ERROR_CODE_NOT_APPLIED, ERROR_CODE_UNKNOWN } from '@/constants/errorCode';
|
||||||
import ApiStatus from '@/components/common/ApiStatus.vue';
|
import ApiStatus from '@/components/common/ApiStatus.vue';
|
||||||
import { ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW } from '@/router';
|
import { ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_CONVERSATION_NEW } from '@/router';
|
||||||
import { Status } from '@/store/common/models';
|
import { Status } from '@/store/common/models';
|
||||||
import { log } from '@/utils/log';
|
import { log } from '@/utils/log';
|
||||||
import Introduction from '@/components/chat/Introduction.vue';
|
import Introduction from '@/components/chat/Introduction.vue';
|
||||||
import Layout from '@/layouts/Chat.vue';
|
import Layout from '@/layouts/Chat.vue';
|
||||||
|
import { isJSONString } from '@/utils/is';
|
||||||
|
|
||||||
export interface IData {
|
export interface IData {
|
||||||
question: string;
|
question: string;
|
||||||
references: string[];
|
references: string[];
|
||||||
|
answering: boolean;
|
||||||
messages: IChatMessage[];
|
messages: IChatMessage[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +82,7 @@ export default defineComponent({
|
|||||||
return {
|
return {
|
||||||
question: '',
|
question: '',
|
||||||
references: [],
|
references: [],
|
||||||
|
answering: false,
|
||||||
messages:
|
messages:
|
||||||
this.$store.state.chat.conversations?.find(
|
this.$store.state.chat.conversations?.find(
|
||||||
(conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString()
|
(conversation: IChatConversation) => conversation.id === this.$route.params.id?.toString()
|
||||||
@@ -93,6 +104,9 @@ export default defineComponent({
|
|||||||
application() {
|
application() {
|
||||||
return this.applications?.find((application: IApplication) => application.api?.id === this.model.apiId);
|
return this.applications?.find((application: IApplication) => application.api?.id === this.model.apiId);
|
||||||
},
|
},
|
||||||
|
needApply() {
|
||||||
|
return this.$store.state.chat.getApplicationsStatus === Status.Success && !this.application;
|
||||||
|
},
|
||||||
applications() {
|
applications() {
|
||||||
return this.$store.state.chat.applications;
|
return this.$store.state.chat.applications;
|
||||||
},
|
},
|
||||||
@@ -177,14 +191,21 @@ export default defineComponent({
|
|||||||
const path = this.application?.api?.path;
|
const path = this.application?.api?.path;
|
||||||
const question = this.question;
|
const question = this.question;
|
||||||
const references = this.references;
|
const references = this.references;
|
||||||
if (!token || !endpoint || !question || !path) {
|
|
||||||
console.error('no token or endpoint or question');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
log(this.onFetchAnswer, 'validated', question, references);
|
log(this.onFetchAnswer, 'validated', question, references);
|
||||||
// reset question and references
|
// reset question and references
|
||||||
this.question = '';
|
this.question = '';
|
||||||
this.references = [];
|
this.references = [];
|
||||||
|
if (!token || !endpoint || !question || !path) {
|
||||||
|
console.error('no token or endpoint or question');
|
||||||
|
this.messages.push({
|
||||||
|
error: {
|
||||||
|
code: ERROR_CODE_NOT_APPLIED
|
||||||
|
},
|
||||||
|
role: ROLE_ASSISTANT,
|
||||||
|
state: IChatMessageState.FAILED
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
let conversationId = this.conversationId;
|
let conversationId = this.conversationId;
|
||||||
this.messages.push({
|
this.messages.push({
|
||||||
content: '',
|
content: '',
|
||||||
@@ -194,6 +215,7 @@ export default defineComponent({
|
|||||||
log(this.onFetchAnswer, 'start to get answer', this.messages);
|
log(this.onFetchAnswer, 'start to get answer', this.messages);
|
||||||
this.onScrollDown();
|
this.onScrollDown();
|
||||||
// request server to get answer
|
// request server to get answer
|
||||||
|
this.answering = true;
|
||||||
chatOperator
|
chatOperator
|
||||||
.askQuestion(
|
.askQuestion(
|
||||||
{
|
{
|
||||||
@@ -224,6 +246,7 @@ export default defineComponent({
|
|||||||
id: conversationId,
|
id: conversationId,
|
||||||
messages: this.messages
|
messages: this.messages
|
||||||
});
|
});
|
||||||
|
this.answering = false;
|
||||||
if (!this.conversationId) {
|
if (!this.conversationId) {
|
||||||
await this.$router.push({
|
await this.$router.push({
|
||||||
name: ROUTE_CHAT_CONVERSATION,
|
name: ROUTE_CHAT_CONVERSATION,
|
||||||
@@ -240,12 +263,16 @@ export default defineComponent({
|
|||||||
if (this.messages && this.messages.length > 0) {
|
if (this.messages && this.messages.length > 0) {
|
||||||
this.messages[this.messages.length - 1].state = IChatMessageState.FAILED;
|
this.messages[this.messages.length - 1].state = IChatMessageState.FAILED;
|
||||||
}
|
}
|
||||||
|
console.error(error);
|
||||||
if (axios.isCancel(error)) {
|
if (axios.isCancel(error)) {
|
||||||
this.messages[this.messages.length - 1].error = {
|
this.messages[this.messages.length - 1].error = {
|
||||||
code: ERROR_CODE_CANCELED
|
code: ERROR_CODE_CANCELED
|
||||||
};
|
};
|
||||||
} else if (error?.response?.data && error?.response?.data.code) {
|
} else if (error?.response?.data) {
|
||||||
const data = error?.response?.data;
|
let data = error?.response?.data;
|
||||||
|
if (isJSONString(data)) {
|
||||||
|
data = JSON.parse(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;
|
||||||
}
|
}
|
||||||
@@ -256,6 +283,7 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.answering = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
<api-status
|
<api-status
|
||||||
:initializing="initializing"
|
:initializing="initializing"
|
||||||
:application="application"
|
:application="application"
|
||||||
|
:need-apply="needApply"
|
||||||
class="mb-4"
|
class="mb-4"
|
||||||
:api-id="channel.apiId"
|
:api-id="channel.apiId"
|
||||||
@refresh="onGetApplications"
|
@refresh="onGetApplications"
|
||||||
@@ -62,6 +63,9 @@ export default defineComponent({
|
|||||||
initializing() {
|
initializing() {
|
||||||
return this.$store.state.midjourney.getApplicationsStatus === Status.Request;
|
return this.$store.state.midjourney.getApplicationsStatus === Status.Request;
|
||||||
},
|
},
|
||||||
|
needApply() {
|
||||||
|
return this.$store.state.midjourney.getApplicationsStatus === Status.Success && !this.application;
|
||||||
|
},
|
||||||
application() {
|
application() {
|
||||||
if (this.applications && this.applications.length > 0) {
|
if (this.applications && this.applications.length > 0) {
|
||||||
return this.applications.filter((item: IApplication) => item.api_id === this.channel.apiId)[0];
|
return this.applications.filter((item: IApplication) => item.api_id === this.channel.apiId)[0];
|
||||||
|
|||||||
@@ -9,8 +9,9 @@
|
|||||||
:initializing="initializing"
|
:initializing="initializing"
|
||||||
:application="application"
|
:application="application"
|
||||||
:api-id="channel.apiId"
|
:api-id="channel.apiId"
|
||||||
|
:need-apply="needApply"
|
||||||
class="mb-4"
|
class="mb-4"
|
||||||
@apply="onGetApplications"
|
@refresh="onGetApplications"
|
||||||
/>
|
/>
|
||||||
<div class="pt-4">
|
<div class="pt-4">
|
||||||
<reference-image class="mb-4" @change="references = $event" />
|
<reference-image class="mb-4" @change="references = $event" />
|
||||||
@@ -98,6 +99,9 @@ export default defineComponent({
|
|||||||
applications() {
|
applications() {
|
||||||
return this.$store.state.midjourney.applications;
|
return this.$store.state.midjourney.applications;
|
||||||
},
|
},
|
||||||
|
needApply() {
|
||||||
|
return this.$store.state.midjourney.getApplicationsStatus === Status.Success && !this.application;
|
||||||
|
},
|
||||||
application() {
|
application() {
|
||||||
if (this.applications && this.applications.length > 0) {
|
if (this.applications && this.applications.length > 0) {
|
||||||
return this.applications.filter((item: IApplication) => item.api_id === this.channel.apiId)[0];
|
return this.applications.filter((item: IApplication) => item.api_id === this.channel.apiId)[0];
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ import { ActionContext } from 'vuex';
|
|||||||
import { log } from '@/utils/log';
|
import { log } from '@/utils/log';
|
||||||
import { IChatState } from './models';
|
import { IChatState } from './models';
|
||||||
|
|
||||||
|
export const resetAll = ({ commit }: ActionContext<IChatState, IRootState>): void => {
|
||||||
|
commit('resetAll');
|
||||||
|
};
|
||||||
|
|
||||||
export const setModel = async ({ commit }: any, payload: IChatModel): Promise<void> => {
|
export const setModel = async ({ commit }: any, payload: IChatModel): Promise<void> => {
|
||||||
commit('setModel', payload);
|
commit('setModel', payload);
|
||||||
};
|
};
|
||||||
@@ -96,6 +100,7 @@ export const getConversations = async ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
resetAll,
|
||||||
setModel,
|
setModel,
|
||||||
setApplications,
|
setApplications,
|
||||||
setConversation,
|
setConversation,
|
||||||
|
|||||||
@@ -2,6 +2,13 @@ import { IApplication, IChatConversation, IChatModel } from '@/operators';
|
|||||||
import { IChatState } from './models';
|
import { IChatState } from './models';
|
||||||
import { Status } from '../common/models';
|
import { Status } from '../common/models';
|
||||||
|
|
||||||
|
export const resetAll = (state: IChatState): void => {
|
||||||
|
state.applications = [];
|
||||||
|
state.getApplicationsStatus = Status.None;
|
||||||
|
state.conversations = [];
|
||||||
|
state.getConversationsStatus = Status.None;
|
||||||
|
};
|
||||||
|
|
||||||
export const setModel = (state: IChatState, payload: IChatModel): void => {
|
export const setModel = (state: IChatState, payload: IChatModel): void => {
|
||||||
state.model = payload;
|
state.model = payload;
|
||||||
};
|
};
|
||||||
@@ -27,5 +34,6 @@ export default {
|
|||||||
setApplications,
|
setApplications,
|
||||||
setGetApplicationsStatus,
|
setGetApplicationsStatus,
|
||||||
setConversations,
|
setConversations,
|
||||||
setGetConversationsStatus
|
setGetConversationsStatus,
|
||||||
|
resetAll
|
||||||
};
|
};
|
||||||
@@ -1,9 +1,22 @@
|
|||||||
import { ActionContext } from 'vuex';
|
import { ActionContext } from 'vuex';
|
||||||
import { IRootState, IToken } from '../common/models';
|
import { IRootState, IToken } from '../common/models';
|
||||||
import { IApplication, IUser, userOperator } from '@/operators';
|
import { IUser, userOperator } from '@/operators';
|
||||||
import { log } from '@/utils/log';
|
import { log } from '@/utils/log';
|
||||||
import { oauthOperator } from '@/operators/auth/operator';
|
import { oauthOperator } from '@/operators/auth/operator';
|
||||||
|
|
||||||
|
export const resetAll = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||||
|
commit('resetToken');
|
||||||
|
commit('resetUser');
|
||||||
|
};
|
||||||
|
|
||||||
|
export const resetUser = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||||
|
commit('resetUser');
|
||||||
|
};
|
||||||
|
|
||||||
|
export const resetSetting = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||||
|
commit('resetSetting');
|
||||||
|
};
|
||||||
|
|
||||||
export const resetToken = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
export const resetToken = ({ commit }: ActionContext<IRootState, IRootState>) => {
|
||||||
commit('resetToken');
|
commit('resetToken');
|
||||||
};
|
};
|
||||||
@@ -41,6 +54,9 @@ export const getToken = async ({ commit }: ActionContext<IRootState, IRootState>
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
resetToken,
|
resetToken,
|
||||||
|
resetAll,
|
||||||
|
resetUser,
|
||||||
|
resetSetting,
|
||||||
setToken,
|
setToken,
|
||||||
setUser,
|
setUser,
|
||||||
getToken,
|
getToken,
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import { IChatState } from '../chat/models';
|
|||||||
export enum Status {
|
export enum Status {
|
||||||
Request = 'Request',
|
Request = 'Request',
|
||||||
Success = 'Success',
|
Success = 'Success',
|
||||||
Error = 'Error'
|
Error = 'Error',
|
||||||
|
None = 'None'
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IToken {
|
export interface IToken {
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ export const resetToken = (state: IRootState): void => {
|
|||||||
state.token = {};
|
state.token = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const resetSetting = (state: IRootState): void => {
|
||||||
|
state.setting = {};
|
||||||
|
};
|
||||||
|
|
||||||
|
export const resetUser = (state: IRootState): void => {
|
||||||
|
state.user = {};
|
||||||
|
};
|
||||||
|
|
||||||
export const setSetting = (state: IRootState, payload: any): void => {
|
export const setSetting = (state: IRootState, payload: any): void => {
|
||||||
state.setting = {
|
state.setting = {
|
||||||
...state.setting,
|
...state.setting,
|
||||||
@@ -28,7 +36,9 @@ export const setSetting = (state: IRootState, payload: any): void => {
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
setUser,
|
setUser,
|
||||||
|
resetUser,
|
||||||
setToken,
|
setToken,
|
||||||
resetToken,
|
resetToken,
|
||||||
setSetting
|
setSetting,
|
||||||
|
resetSetting
|
||||||
};
|
};
|
||||||
@@ -15,6 +15,10 @@ import { ActionContext } from 'vuex';
|
|||||||
import { log } from '@/utils/log';
|
import { log } from '@/utils/log';
|
||||||
import { IRootState, Status } from '../common/models';
|
import { IRootState, Status } from '../common/models';
|
||||||
|
|
||||||
|
export const resetAll = ({ commit }: ActionContext<IMidjourneyState, IRootState>): void => {
|
||||||
|
commit('resetAll');
|
||||||
|
};
|
||||||
|
|
||||||
export const setPreset = ({ commit }: any, payload: IMidjourneyPreset) => {
|
export const setPreset = ({ commit }: any, payload: IMidjourneyPreset) => {
|
||||||
commit('setPreset', payload);
|
commit('setPreset', payload);
|
||||||
};
|
};
|
||||||
@@ -79,6 +83,7 @@ export const getImagineTasks = async (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
resetAll,
|
||||||
setPreset,
|
setPreset,
|
||||||
setChannel,
|
setChannel,
|
||||||
setApplications,
|
setApplications,
|
||||||
|
|||||||
@@ -2,6 +2,13 @@ import { IApplication, IMidjourneyChannel, IMidjourneyPreset } from '@/operators
|
|||||||
import { IMidjourneyState } from './models';
|
import { IMidjourneyState } from './models';
|
||||||
import { Status } from '../common/models';
|
import { Status } from '../common/models';
|
||||||
|
|
||||||
|
export const resetAll = (state: IMidjourneyState): void => {
|
||||||
|
state.applications = [];
|
||||||
|
state.preset = {};
|
||||||
|
state.getApplicationsStatus = Status.None;
|
||||||
|
state.imagineTasks = [];
|
||||||
|
};
|
||||||
|
|
||||||
export const setApplications = (state: IMidjourneyState, payload: IApplication[]): void => {
|
export const setApplications = (state: IMidjourneyState, payload: IApplication[]): void => {
|
||||||
state.applications = payload;
|
state.applications = payload;
|
||||||
};
|
};
|
||||||
@@ -37,5 +44,6 @@ export default {
|
|||||||
setGetApplicationsStatus,
|
setGetApplicationsStatus,
|
||||||
setImagineTasks,
|
setImagineTasks,
|
||||||
setGetImagineTasksStatus,
|
setGetImagineTasksStatus,
|
||||||
setImagineTasksTotal
|
setImagineTasksTotal,
|
||||||
|
resetAll
|
||||||
};
|
};
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Js JSON string
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const isJSONString = (str: string): boolean => {
|
||||||
|
try {
|
||||||
|
JSON.parse(str);
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
Reference in new issue
Block a user