chatgpt ui

This commit is contained in:
AceDataCloud committed 2023-04-06 20:13:16 +08:00
1 parent 523ab178a4
commit ed43ab5afd
24 files changed
+495 -34

No files matched your search

+51
View File
@@ -0,0 +1,51 @@
<template>
<div class="message">
<el-image :src="author.avatar" class="icon" />
<message-content :content="content" class="content" />
</div>
</template>
<script lang="ts">
import { IBot, IUser } from '@/operators';
import { IContent } from '@/operators/message/models';
import { defineComponent } from 'vue';
import MessageContent from './MessageContent.vue';
export default defineComponent({
name: 'Message',
components: {
MessageContent
},
props: {
content: {
type: Object as () => IContent,
required: true
},
author: {
type: Object as () => IUser | IBot,
required: true
}
},
data() {
return {};
},
computed: {
conversationId() {
return this.$route.params?.id?.toString();
}
}
});
</script>
<style lang="scss" scoped>
.message {
display: flex;
flex-direction: row;
.icon {
width: 100px;
}
.content {
flex: 1;
}
}
</style>
@@ -0,0 +1,30 @@
<template>
<markdown-renderer :content="content.value" />
</template>
<script lang="ts">
import { IContent } from '@/operators/message/models';
import { defineComponent } from 'vue';
import MarkdownRenderer from '@/components/common/MarkdownRenderer.vue';
export default defineComponent({
name: 'MessageContent',
components: {
MarkdownRenderer
},
props: {
content: {
type: Object as () => IContent,
required: true
}
},
data() {
return {};
},
computed: {
conversationId() {
return this.$route.params?.id?.toString();
}
}
});
</script>
@@ -0,0 +1,42 @@
<template>
<el-input v-model="value" placeholder="Type something">
<template #suffix>
<el-icon class="el-input__icon" @click="$emit('send')">send</el-icon>
</template>
</el-input>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElInput, ElButton, ElIcon } from 'element-plus';
export default defineComponent({
name: 'NewMessageBox',
components: {
ElInput,
ElIcon
},
props: {
modelValue: {
type: String,
required: true
}
},
emits: ['send', 'update:modelValue'],
data() {
return {
value: this.modelValue
};
},
computed: {
conversationId() {
return this.$route.params?.id?.toString();
}
},
watch: {
value(val) {
console.log('ccc', this.value);
this.$emit('update:modelValue', this.value);
}
}
});
</script>
-3
View File
@@ -3,9 +3,6 @@
<el-aside class="aside">
<navigator />
</el-aside>
<el-header class="header">
<navigator />
</el-header>
<el-main class="main"> <router-view /> </el-main>
</div>
</template>
+72
View File
@@ -0,0 +1,72 @@
<template>
<div class="container">
<el-main class="main"> <router-view /> </el-main>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElMain, ElAside } from 'element-plus';
export default defineComponent({
name: 'LayoutConversation',
components: {
ElMain
}
});
</script>
<style lang="scss" scoped>
.container {
display: flex;
height: 100vh;
width: 100%;
max-width: initial;
}
.header {
padding: 0;
}
$width: 300px;
.aside {
width: $width;
height: 100%;
background-color: white;
padding: 15px;
padding-top: 50px;
}
.header {
display: none;
}
.main {
width: calc(100% - $width);
background-color: #f3f5f6;
height: 100%;
}
@media (max-width: 800px) {
.container {
display: block;
}
.aside {
display: none;
}
.header {
display: block;
background: white;
padding: 15px;
padding-top: 50px;
height: fit-content;
overflow: hidden;
.logo {
width: 100%;
}
}
.main {
width: 100%;
}
}
</style>
+10
View File
@@ -0,0 +1,10 @@
export interface IRequest {
question: string;
stateful?: boolean;
conversation_id?: string;
}
export interface IResponse {
answer: string;
conversation_id?: string;
}
+20
View File
@@ -0,0 +1,20 @@
import { AxiosResponse } from 'axios';
import { httpClient } from '../../instance';
import { IRequest, IResponse } from './models';
export interface IQuery {
token: string;
}
const baseUrl = 'https://api.zhishuyun.com';
class ChatGPTOperator {
async post(data: IRequest, query: IQuery): Promise<AxiosResponse<IResponse>> {
return await httpClient.post(`/chatgpt`, data, {
params: query,
baseURL: baseUrl
});
}
}
export const chatgptOperator = new ChatGPTOperator();
+11
View File
@@ -0,0 +1,11 @@
import { IUser, IBot } from '../user';
export interface IContent {
value: string;
type?: string;
}
export interface IMessage {
content: IContent;
author: IUser | IBot;
}
+9
View File
@@ -10,6 +10,15 @@ export interface IUser {
province?: string;
country?: string;
avatar?: string;
type: 'user';
}
export interface IBot {
id?: string;
username?: string;
nickname?: string;
avatar?: string;
type: 'bot';
}
export interface IUserDetailResponse extends IUser {}
+127
View File
@@ -0,0 +1,127 @@
<template>
<div class="conversation">
<div class="messages">
<div
v-for="(message, messageIndex) in messages"
:key="messageIndex"
:class="{
'message-wrapper': true,
user: message.author.type === 'user',
bot: message.author.type === 'bot'
}"
>
<el-row>
<el-col :span="18" :offset="3">
<message :content="message.content" :author="message.author"> </message>
</el-col>
</el-row>
</div>
</div>
<div class="footer">
<el-row>
<el-col :span="18" :offset="3">
<new-message-box v-model="input" class="new-message" @send="onSend" />
</el-col>
</el-row>
</div>
</div>
</template>
<script lang="ts">
import { IMessage } from '@/operators/message/models';
import { defineComponent } from 'vue';
import { ElRow, ElCol } from 'element-plus';
import Message from '@/components/conversation/Message.vue';
import { chatgptOperator } from '@/operators/api/chatgpt/operator';
import { IResponse } from '@/operators/api/chatgpt/models';
import NewMessageBox from '@/components/conversation/NewMessageBox.vue';
export interface IData {
input: string;
messages: IMessage[];
}
export default defineComponent({
name: 'ChatDetail',
components: {
Message,
ElRow,
ElCol,
NewMessageBox
},
data(): IData {
return {
input: '',
messages: [
{
author: {
type: 'bot',
nickname: 'ChatGPT'
},
content: {
value: '你好啊'
}
},
{
author: {
id: 'x',
type: 'user',
nickname: 'fdsf'
},
content: {
value: '很高兴为你服务'
}
}
]
};
},
computed: {
conversationId() {
return this.$route.params?.id?.toString();
}
},
methods: {
onSend() {
console.log('send', this.input);
chatgptOperator
.post(
{
question: this.input
},
{
token: 'ec5cc681720b4923b05f669a853c5629'
}
)
.then(({ data: data }: { data: IResponse }) => {
console.log('data', data);
});
}
}
});
</script>
<style lang="scss" scoped>
.conversation {
min-height: 100vh;
flex-direction: column;
display: flex;
.messages {
flex: 1;
}
.message-wrapper {
border-color: rgba(0, 0, 0, 0.1);
border-bottom-width: 1px;
padding-bottom: 1.5rem;
padding-top: 1.5rem;
&.bot {
background-color: #f7f7f8;
}
&.user {
background-color: #ffffff;
}
}
.new-message {
height: 50px;
}
}
</style>
+70
View File
@@ -0,0 +1,70 @@
<template>
<div class="conversation">
<div class="introduction"></div>
<div class="footer">
<el-row>
<el-col :span="18" :offset="3">
<new-message-box v-model="input" class="new-message" @send="onSend" />
</el-col>
</el-row>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElRow, ElCol } from 'element-plus';
import NewMessageBox from '@/components/conversation/NewMessageBox.vue';
import { chatgptOperator } from '@/operators/api/chatgpt/operator';
import { IResponse } from '@/operators/api/chatgpt/models';
export default defineComponent({
name: 'ChatMain',
components: {
NewMessageBox,
ElRow,
ElCol
},
data() {
return {
input: ''
};
},
computed: {},
methods: {
onSend() {
console.log('send', this.input);
chatgptOperator
.post(
{
question: this.input
},
{
token: 'ec5cc681720b4923b05f669a853c5629'
}
)
.then(({ data: data }: { data: IResponse }) => {
console.log('data', data);
});
}
}
});
</script>
<style lang="scss" scoped>
.conversation {
display: flex;
flex-direction: column;
min-height: 100vh;
.introduction {
flex-grow: 1;
flex-shrink: 1;
flex-basis: 0%;
}
.footer {
height: 50px;
}
}
</style>
+2
View File
@@ -12,6 +12,8 @@ export const ROUTE_CONSOLE_ADMIN_APPLICATION = 'console-application-admin-applic
export const ROUTE_DOCUMENT_LIST = 'document-list';
export const ROUTE_DOCUMENT_DETAIL = 'document-detail';
export const ROUTE_CONVERSATION_NEW = 'conversation-new';
export const ROUTE_CONVERSATION_DETAIL = 'conversation-detail';
export const ROUTE_SERVICE_LIST = 'service-list';
export const ROUTE_SERVICE_DETAIL = 'service-detail';
+18
View File
@@ -0,0 +1,18 @@
import { ROUTE_CONVERSATION_DETAIL, ROUTE_CONVERSATION_NEW, ROUTE_DOCUMENT_LIST } from './constants';
export default {
path: '/conversations',
component: () => import('@/layouts/Conversation.vue'),
children: [
{
path: '',
name: ROUTE_CONVERSATION_NEW,
component: () => import('@/pages/conversation/New.vue')
},
{
path: ':id',
name: ROUTE_CONVERSATION_DETAIL,
component: () => import('@/pages/conversation/Detail.vue')
}
]
};
+3 -1
View File
@@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router';
import service from './service';
import auth from './auth';
import console from './console';
import conversation from './conversation';
import document from './document';
import store from '@/store';
import { ROUTE_AUTH_LOGIN, ROUTE_INDEX, ROUTE_SERVICE_LIST } from './constants';
@@ -17,7 +18,8 @@ const routes = [
service,
auth,
console,
document
document,
conversation
];
const router = createRouter({
+1 -1
View File
@@ -8,7 +8,7 @@ import { getEnv } from './env';
export const getDataBaseUrl = () => {
const env = getEnv();
if (env === ENV_LOCAL) {
return 'https://data.local.zhishuyun.com';
return 'https://chat.local.zhishuyun.com';
} else if (env === ENV_TEST) {
return 'https://data.test.zhishuyun.com';
} else {