Upgrade to openai style for aichat (#46)

This commit is contained in:
AceDataCloud committed 2024-06-13 16:03:13 +00:00
1 parent 3918446e7a
commit 7869cc0acd
14 files changed
+431 -220

No files matched your search

+13 -12
View File
@@ -155,6 +155,7 @@ export default defineComponent({
<style lang="scss">
textarea.input {
font-size: 14px;
min-height: 35px;
max-height: 350px;
border: none;
@@ -171,7 +172,6 @@ textarea.input:focus {
outline: none;
}
.input-box {
// height: auto;
position: relative;
.input {
textarea {
@@ -197,11 +197,12 @@ textarea.input:focus {
<style lang="scss" scoped>
.input-box {
width: 100%;
border: 1px solid var(--el-border-color);
border-radius: 10px;
background: none;
box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
width: 800px;
margin: auto;
position: relative;
border-radius: 20px;
background: var(--el-bg-color-page);
padding: 5px;
.upload {
display: inline-block;
&.disabled {
@@ -216,18 +217,18 @@ textarea.input:focus {
.input {
border: none;
width: calc(100% - 80px);
margin-left: 30px;
margin-left: 35px;
}
.btn {
display: block;
z-index: 100;
cursor: pointer;
bottom: 15px;
position: absolute;
top: 7px;
&.btn-upload {
left: 10px;
left: 15px;
.icon-attachment {
font-size: 14px;
font-size: 16px;
color: var(--el-text-color-primary);
}
}
@@ -250,9 +251,9 @@ textarea.input:focus {
.info {
display: block;
font-size: 12px;
color: #666;
color: var(--el-text-color-secondary);
margin-top: 5px;
margin-left: 3px;
text-align: center;
margin-bottom: 0;
}
</style>
+39 -93
View File
@@ -1,67 +1,13 @@
<template>
<div class="introduction">
<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('chat.title.complexQuestion') }}</h3>
<el-row class="items" justify="center" :gutter="15">
<el-col v-for="(item, itemKey) in items" :key="itemKey" :md="6" :sm="12" :xs="24">
<introduction-item
:content="$t('chat.message.question1')"
:content="item.content"
:icon="item.icon"
:color="item.color"
class="cursor-pointer"
@click="$emit('draft', $t('chat.message.question1'))"
/>
<introduction-item
:content="$t('chat.message.question2')"
class="cursor-pointer"
@click="$emit('draft', $t('chat.message.question2'))"
/>
<introduction-item
:content="$t('chat.message.question3')"
class="cursor-pointer"
@click="$emit('draft', $t('chat.message.question3'))"
/>
</el-col>
<el-col :md="8" :sm="24" :xs="24">
<div class="text-center">
<font-awesome-icon icon="fa-solid fa-book" class="icon icon-rotate" />
</div>
<h3 class="subtitle">{{ $t('chat.title.professionalQuestion') }}</h3>
<introduction-item
:content="$t('chat.message.question4')"
class="cursor-pointer"
@click="$emit('draft', $t('chat.message.question4'))"
/>
<introduction-item
:content="$t('chat.message.question5')"
class="cursor-pointer"
@click="$emit('draft', $t('chat.message.question5'))"
/>
<introduction-item
:content="$t('chat.message.question6')"
class="cursor-pointer"
@click="$emit('draft', $t('chat.message.question6'))"
/>
</el-col>
<el-col :md="8" :sm="24" :xs="24">
<div class="text-center">
<font-awesome-icon icon="fa-solid fa-fire" class="icon icon-rotate" />
</div>
<h3 class="subtitle">{{ $t('chat.title.getTips') }}</h3>
<introduction-item
:content="$t('chat.message.question7')"
class="cursor-pointer"
@click="$emit('draft', $t('chat.message.question7'))"
/>
<introduction-item
:content="$t('chat.message.question8')"
class="cursor-pointer"
@click="$emit('draft', $t('chat.message.question8'))"
/>
<introduction-item
:content="$t('chat.message.question9')"
class="cursor-pointer"
@click="$emit('draft', $t('chat.message.question9'))"
@click="$emit('draft', item.content)"
/>
</el-col>
</el-row>
@@ -70,21 +16,42 @@
<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 {};
return {
items: [
{
icon: 'fa-solid fa-pen-nib',
content: this.$t('chat.message.question1'),
color: 'rgb(226, 197, 65)'
},
{
icon: 'fa-solid fa-laptop-code',
content: this.$t('chat.message.question2'),
color: 'rgb(203, 139, 208)'
},
{
icon: 'fa-solid fa-fan',
content: this.$t('chat.message.question3'),
color: 'rgb(118, 208, 235)'
},
{
icon: 'fa-solid fa-plane-departure',
content: this.$t('chat.message.question4'),
color: 'rgb(237, 98, 98)'
}
].sort(() => Math.random() - 0.5)
};
},
computed: {}
});
@@ -92,34 +59,16 @@ export default defineComponent({
<style lang="scss" scoped>
.introduction {
width: 80%;
margin: auto;
padding: 30px 0;
padding: 60px;
width: 100%;
height: 100%;
flex: 1;
display: flex;
align-items: center;
justify-content: center;
.title {
height: 70px;
text-align: center;
display: block;
font-size: 36px;
font-weight: 600;
margin-bottom: 50px;
}
.introduction-items {
height: fit-content;
.icon {
font-size: 20px;
}
.subtitle {
text-align: center;
font-size: 18px;
margin-top: 10px;
margin-bottom: 40px;
}
.introduction-item {
margin-bottom: 15px;
}
.items {
width: 800px;
margin: auto;
}
}
@@ -131,9 +80,6 @@ export default defineComponent({
transform: initial;
width: 90%;
margin: auto;
.introduction-items {
margin-bottom: 0;
}
}
}
</style>
+35 -4
View File
@@ -1,18 +1,41 @@
<template>
<div class="introduction-item">
{{ content }}
<div class="item">
<div class="icon">
<font-awesome-icon
:icon="icon"
:style="{
color: color
}"
/>
</div>
<div class="content">
{{ content }}
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { color } from '@codemirror/theme-one-dark';
export default defineComponent({
name: 'ConversationIntroductionItem',
components: {
FontAwesomeIcon
},
props: {
content: {
type: String,
required: true
},
icon: {
type: String,
required: true
},
color: {
type: String,
default: 'rgb(0, 0, 0)'
}
},
data() {
@@ -23,12 +46,20 @@ export default defineComponent({
</script>
<style lang="scss" scoped>
.introduction-item {
.item {
height: 100px;
font-size: 14px;
background-color: var(--el-fill-color-extra-light);
background-color: var(--el-color-white);
color: var(--el-text-color-primary);
border: 1px solid var(--el-border-color-lighter);
padding: 10px 20px;
border-radius: 20px;
&:hover {
background-color: var(--el-bg-color-page);
}
.icon {
font-size: 14px;
margin-bottom: 10px;
}
}
</style>
+4 -6
View File
@@ -46,7 +46,7 @@ import {
ERROR_CODE_USED_UP,
ROLE_ASSISTANT
} from '@/constants';
import message from '@/i18n/zh/common/message';
// import message from '@/i18n/zh/common/message';
import { ROUTE_CONSOLE_APPLICATION_BUY } from '@/router';
interface IData {
@@ -159,19 +159,17 @@ export default defineComponent({
.content {
background-color: var(--el-bg-color-page);
color: var(--el-text-color-primary);
border-bottom-left-radius: 0;
}
}
&.user {
align-items: end;
.content {
background-color: var(--el-color-primary);
color: var(--el-color-white);
border-bottom-right-radius: 0;
background-color: var(--el-bg-color-page);
color: var(--el-text-color-primary);
}
}
.content {
border-radius: 10px;
border-radius: 20px;
padding: 8px 15px;
max-width: 800px;
.image {
+2 -2
View File
@@ -1,5 +1,5 @@
<template>
<div class="model-selector">
<div class="selector">
<el-dropdown
v-for="(group, groupIndex) in groups"
:key="groupIndex"
@@ -137,7 +137,7 @@ export default defineComponent({
</style>
<style lang="scss" scoped>
.model-selector {
.selector {
background-color: var(--el-bg-color-page);
padding: 7px 6px;
border-radius: 15px;
+166
View File
@@ -0,0 +1,166 @@
<template>
<div class="selector">
<el-dropdown trigger="click" popper-class="popper">
<div>
<span class="name">{{ model?.getDisplayName() }}</span>
<span class="angle">
<font-awesome-icon icon="fa-solid fa-angle-down" />
</span>
</div>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item
v-for="(option, optionKey) in options"
:key="optionKey"
@click="onCommandChange(option.model)"
>
<div class="item">
<div class="icon" :style="{ color: option.color }">
<font-awesome-icon :icon="option.icon" />
</div>
<div class="info">
<p class="name">{{ option.model.getDisplayName() }}</p>
<p class="description">{{ option.model.getDescription() }}</p>
</div>
</div>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElDropdown, ElDropdownItem, ElDropdownMenu } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import { IChatModel } from '@/models';
import {
CHAT_MODEL_GPT_3_5,
CHAT_MODEL_GPT_3_5_BROWSING,
CHAT_MODEL_GPT_4,
CHAT_MODEL_GPT_4_BROWSING,
CHAT_MODEL_GPT_4_VISION
} from '@/constants';
export default defineComponent({
name: 'ModelSelector',
components: {
ElDropdown,
ElDropdownMenu,
ElDropdownItem,
FontAwesomeIcon
},
emits: ['update:modelValue', 'select'],
data() {
return {
options: [
{
icon: 'fa-solid fa-bolt',
color: '#ff9900',
model: CHAT_MODEL_GPT_3_5
},
{
icon: 'fa-solid fa-bolt',
color: '#ff9900',
model: CHAT_MODEL_GPT_3_5_BROWSING
},
{
icon: 'fa-solid fa-wand-magic-sparkles',
color: '#ce65e6',
model: CHAT_MODEL_GPT_4
},
{
icon: 'fa-solid fa-wand-magic-sparkles',
color: '#ce65e6',
model: CHAT_MODEL_GPT_4_BROWSING
},
{
icon: 'fa-solid fa-wand-magic-sparkles',
color: '#ce65e6',
model: CHAT_MODEL_GPT_4_VISION
}
]
};
},
computed: {
model() {
const modelName = this.$store.state.chat.model.name;
const model = [
CHAT_MODEL_GPT_3_5,
CHAT_MODEL_GPT_3_5_BROWSING,
CHAT_MODEL_GPT_4,
CHAT_MODEL_GPT_4_BROWSING,
CHAT_MODEL_GPT_4_VISION
].find((model) => model.name === modelName);
return model;
}
},
methods: {
onCommandChange(command: IChatModel) {
this.$emit('select', command);
this.$store.dispatch('chat/setModel', command);
}
}
});
</script>
<style lang="scss">
.popper {
border-radius: 20px;
overflow: hidden;
}
</style>
<style lang="scss" scoped>
.selector {
cursor: pointer;
padding: 7px 6px;
border-radius: 15px;
margin-bottom: 5px;
.name {
font-size: 16px;
font-weight: bold;
display: inline-block;
margin-right: 5px;
}
.angle {
display: inline-block;
max-width: 5px;
}
}
.item {
display: flex;
flex-direction: row;
.icon {
width: 15px;
display: flex;
align-items: flex-start;
justify-content: center;
margin-right: 5px;
margin-top: 3px;
&.base {
color: #ff9900;
}
&.plus {
color: #ce65e6;
}
}
.info {
width: calc(100% - 15px);
.name {
font-size: 14px;
font-weight: bold;
color: var(--el-text-color-primary);
margin: 0;
}
.description {
font-size: 12px;
color: var(--el-text-color-secondary);
margin: 0;
}
}
}
</style>
+110 -60
View File
@@ -1,6 +1,6 @@
<template>
<div class="panel">
<el-skeleton v-if="loading && conversations === undefined" />
<el-skeleton v-if="loading && conversationGroups === undefined" />
<div v-else class="conversations">
<div class="conversation" @click="onNewConversation">
<div class="icons">
@@ -10,54 +10,56 @@
{{ $t('chat.message.startNewChat') }}
</div>
</div>
<div
v-for="(conversation, conversationIndex) in conversations"
:key="conversationIndex"
:class="{ conversation: true, active: conversation.id === conversationId }"
@click="onClick(conversation.id)"
>
<div class="icons">
<font-awesome-icon icon="fa-regular fa-comment" class="icon" />
<div v-for="(conversations, groupKey) in conversationGroups" :key="groupKey" class="group">
<div class="key">
{{ $t(`chat.group.${groupKey}`) }}
</div>
<div class="title">
<span v-if="conversation?.deleting">
{{ `${$t('chat.message.confirmDelete')}?` }}
</span>
<span v-else-if="conversation?.editing">
<el-input v-model="conversation.title" @keydown.enter="onConfirm(conversation)" />
</span>
<span v-else-if="conversation?.title || conversation?.messages">{{
conversation?.title || conversation?.messages[conversation?.messages.length - 1]?.content
}}</span>
</div>
<div class="operations">
<font-awesome-icon
v-if="!conversation?.editing && !conversation.deleting"
icon="fa-solid fa-edit"
class="icon icon-edit"
@click.stop="conversation.editing = true"
/>
<font-awesome-icon
v-if="!conversation?.editing && !conversation.deleting"
icon="fa-solid fa-trash"
class="icon icon-delete"
@click.stop="conversation.deleting = true"
/>
<font-awesome-icon
v-if="conversation?.editing || conversation.deleting"
icon="fa-solid fa-check"
class="icon icon-confirm"
@click.stop="onConfirm(conversation)"
/>
<font-awesome-icon
v-if="conversation?.editing || conversation.deleting"
icon="fa-solid fa-xmark"
class="icon icon-cancel"
@click.stop="
conversation.editing = false;
conversation.deleting = false;
"
/>
<div
v-for="(conversation, conversationIndex) in conversations"
:key="conversationIndex"
:class="{ conversation: true, active: conversation.id === conversationId }"
@click="onClick(conversation.id)"
>
<div class="title">
<span v-if="conversation?.deleting">
{{ `${$t('chat.message.confirmDelete')}?` }}
</span>
<span v-else-if="conversation?.editing">
<el-input v-model="conversation.title" @keydown.enter="onConfirm(conversation)" />
</span>
<span v-else-if="conversation?.title || conversation?.messages">{{
conversation?.title || conversation?.messages[conversation?.messages.length - 1]?.content
}}</span>
</div>
<div class="operations">
<font-awesome-icon
v-if="!conversation?.editing && !conversation.deleting"
icon="fa-solid fa-edit"
class="icon icon-edit"
@click.stop="conversation.editing = true"
/>
<font-awesome-icon
v-if="!conversation?.editing && !conversation.deleting"
icon="fa-solid fa-trash"
class="icon icon-delete"
@click.stop="conversation.deleting = true"
/>
<font-awesome-icon
v-if="conversation?.editing || conversation.deleting"
icon="fa-solid fa-check"
class="icon icon-confirm"
@click.stop="onConfirm(conversation)"
/>
<font-awesome-icon
v-if="conversation?.editing || conversation.deleting"
icon="fa-solid fa-xmark"
class="icon icon-cancel"
@click.stop="
conversation.editing = false;
conversation.deleting = false;
"
/>
</div>
</div>
</div>
</div>
@@ -86,8 +88,41 @@ export default defineComponent({
conversationId() {
return this.$route.params?.id?.toString();
},
conversations() {
return this.$store.state.chat.conversations;
conversationGroups() {
const conversations = this.$store.state.chat.conversations;
// split our 4 groups according to the `updated_at` field, to 'today', 'yesterday', 'this week', 'earlier'.
// if (conversations) {
const today = new Date();
today.setHours(0, 0, 0, 0);
const yesterday = new Date(today);
yesterday.setDate(yesterday.getDate() - 1);
const thisWeek = new Date(today);
thisWeek.setDate(thisWeek.getDate() - today.getDay());
const earlier = new Date(thisWeek);
earlier.setDate(earlier.getDate() - 7);
const groups = conversations?.reduce(
(acc, conversation: IChatConversation) => {
const updatedAt = new Date(conversation.updated_at * 1000);
if (updatedAt >= today) {
(acc.today as IChatConversation[]).push(conversation);
} else if (updatedAt >= yesterday) {
(acc.yesterday as IChatConversation[]).push(conversation);
} else if (updatedAt >= thisWeek) {
(acc.thisWeek as IChatConversation[]).push(conversation);
} else {
(acc.earlier as IChatConversation[]).push(conversation);
}
return acc;
},
{ today: [], yesterday: [], thisWeek: [], earlier: [] }
) as Record<string, IChatConversation[]>;
// sort every group by `updated_at` field.
return {
today: groups?.today?.sort((a, b) => b.updated_at - a.updated_at),
yesterday: groups?.yesterday?.sort((a, b) => b.updated_at - a.updated_at),
thisWeek: groups?.thisWeek?.sort((a, b) => b.updated_at - a.updated_at),
earlier: groups?.earlier?.sort((a, b) => b.updated_at - a.updated_at)
};
},
application() {
return this.$store.state.chat.application;
@@ -146,33 +181,47 @@ export default defineComponent({
display: flex;
flex-direction: column;
align-items: flex-end;
padding: 15px;
width: 300px;
padding: 10px;
width: 250px;
height: 100%;
border-right: 1px solid var(--el-border-color);
overflow-y: scroll;
.conversations {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
.group {
width: 100%;
display: flex;
flex-direction: column;
margin-top: 10px;
.key {
font-size: 12px;
font-weight: 600;
width: 100%;
line-height: 40px;
padding-left: 10px;
color: var(--el-text-color-secondary);
}
}
.conversation {
width: 100%;
height: 55px;
height: 40px;
display: flex;
flex-direction: row;
padding: 10px;
margin-bottom: 5px;
border: 1px dashed var(--el-border-color);
line-height: 30px;
line-height: 40px;
border-radius: 10px;
padding: 0 10px;
color: var(--el-text-color-primary);
cursor: pointer;
&.active,
&:hover {
background-color: var(--el-fill-color-extra-light);
background-color: var(--el-bg-color-page);
.operations {
display: block;
}
}
.icons {
@@ -185,13 +234,14 @@ export default defineComponent({
.title {
flex: 1;
font-size: 14px;
line-height: 32px;
line-height: 40px;
overflow: hidden;
text-overflow: ellipsis;
padding-right: 8px;
color: var(--el-text-color-primary);
}
.operations {
display: none;
width: 40px;
color: var(--el-text-color-regular);
.icon {