chatgpt ui
This commit is contained in:
1 parent
523ab178a4
commit
ed43ab5afd
24 files changed
+495
-34
No files matched your search
@@ -5,7 +5,7 @@
|
||||
Modify the host file, like `/etc/hosts`, add this line:
|
||||
|
||||
```
|
||||
127.0.0.1 data.local.zhishuyun.com
|
||||
127.0.0.1 chat.local.zhishuyun.com
|
||||
```
|
||||
|
||||
Then save it.
|
||||
@@ -28,4 +28,4 @@ Run below command to start local server:
|
||||
sudo yarn start
|
||||
```
|
||||
|
||||
Then open `https://data.local.zhishuyun.com` to view the content.
|
||||
Then open `https://chat.local.zhishuyun.com` to view the content.
|
||||
@@ -2,23 +2,23 @@ apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: data-frontend
|
||||
name: data-frontend
|
||||
app: chat-frontend
|
||||
name: chat-frontend
|
||||
namespace: zhishuyun
|
||||
spec:
|
||||
replicas: 2
|
||||
revisionHistoryLimit: 5
|
||||
selector:
|
||||
matchLabels:
|
||||
app: data-frontend
|
||||
app: chat-frontend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: data-frontend
|
||||
app: chat-frontend
|
||||
spec:
|
||||
containers:
|
||||
- image: ghcr.io/zhishuyun/data-frontend:${TAG}
|
||||
name: data-frontend
|
||||
- image: ghcr.io/zhishuyun/chat-frontend:${TAG}
|
||||
name: chat-frontend
|
||||
ports:
|
||||
- containerPort: 80
|
||||
livenessProbe:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
apiVersion: networking.k8s.io/v1beta1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: data-frontend
|
||||
name: chat-frontend
|
||||
namespace: zhishuyun
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: 'nginx'
|
||||
@@ -17,6 +17,6 @@ spec:
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
serviceName: data-frontend
|
||||
serviceName: chat-frontend
|
||||
servicePort: 8083
|
||||
path: /
|
||||
@@ -2,8 +2,8 @@ apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app: data-frontend
|
||||
name: data-frontend
|
||||
app: chat-frontend
|
||||
name: chat-frontend
|
||||
namespace: zhishuyun
|
||||
spec:
|
||||
ports:
|
||||
@@ -11,4 +11,4 @@ spec:
|
||||
port: 8083
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: data-frontend
|
||||
app: chat-frontend
|
||||
@@ -2,23 +2,23 @@ apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: data-frontend
|
||||
name: data-frontend
|
||||
app: chat-frontend
|
||||
name: chat-frontend
|
||||
namespace: zhishuyun-test
|
||||
spec:
|
||||
replicas: 1
|
||||
revisionHistoryLimit: 5
|
||||
selector:
|
||||
matchLabels:
|
||||
app: data-frontend
|
||||
app: chat-frontend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: data-frontend
|
||||
app: chat-frontend
|
||||
spec:
|
||||
containers:
|
||||
- image: ghcr.io/zhishuyun/data-frontend:${TAG}
|
||||
name: data-frontend
|
||||
- image: ghcr.io/zhishuyun/chat-frontend:${TAG}
|
||||
name: chat-frontend
|
||||
ports:
|
||||
- containerPort: 80
|
||||
resources:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
apiVersion: networking.k8s.io/v1beta1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: data-frontend
|
||||
name: chat-frontend
|
||||
namespace: zhishuyun-test
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: 'nginx'
|
||||
@@ -17,6 +17,6 @@ spec:
|
||||
http:
|
||||
paths:
|
||||
- backend:
|
||||
serviceName: data-frontend
|
||||
serviceName: chat-frontend
|
||||
servicePort: 8083
|
||||
path: /
|
||||
@@ -2,8 +2,8 @@ apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
labels:
|
||||
app: data-frontend
|
||||
name: data-frontend
|
||||
app: chat-frontend
|
||||
name: chat-frontend
|
||||
namespace: zhishuyun-test
|
||||
spec:
|
||||
ports:
|
||||
@@ -11,4 +11,4 @@ spec:
|
||||
port: 8083
|
||||
targetPort: 80
|
||||
selector:
|
||||
app: data-frontend
|
||||
app: chat-frontend
|
||||
+2
-2
@@ -11,8 +11,8 @@
|
||||
"lint": "npx eslint src --fix --ext .ts,.tsx,.vue,.js,.jsx",
|
||||
"prettier": "npx prettier --write .",
|
||||
"init:https": "npm run init:ca && npm run init:cert",
|
||||
"init:ca": "npx mkcert create-ca --validity 36500 --key certs/data.local.zhishuyun.com.ca.key --cert certs/data.local.zhishuyun.com.ca.crt",
|
||||
"init:cert": "npx mkcert create-cert --ca-key certs/data.local.zhishuyun.com.ca.key --ca-cert certs/data.local.zhishuyun.com.ca.crt --validity 36500 --key certs/data.local.zhishuyun.com.cert.key --cert certs/data.local.zhishuyun.com.cert.crt --domains data.local.zhishuyun.com"
|
||||
"init:ca": "npx mkcert create-ca --validity 36500 --key certs/chat.local.zhishuyun.com.ca.key --cert certs/chat.local.zhishuyun.com.ca.crt",
|
||||
"init:cert": "npx mkcert create-cert --ca-key certs/chat.local.zhishuyun.com.ca.key --ca-cert certs/chat.local.zhishuyun.com.ca.crt --validity 36500 --key certs/chat.local.zhishuyun.com.cert.key --cert certs/chat.local.zhishuyun.com.cert.crt --domains chat.local.zhishuyun.com"
|
||||
},
|
||||
"dependencies": {
|
||||
"@codemirror/lang-java": "^6.0.1",
|
||||
|
||||
@@ -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,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>
|
||||
|
||||
@@ -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>
|
||||
@@ -0,0 +1,10 @@
|
||||
export interface IRequest {
|
||||
question: string;
|
||||
stateful?: boolean;
|
||||
conversation_id?: string;
|
||||
}
|
||||
|
||||
export interface IResponse {
|
||||
answer: string;
|
||||
conversation_id?: string;
|
||||
}
|
||||
@@ -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();
|
||||
@@ -0,0 +1,11 @@
|
||||
import { IUser, IBot } from '../user';
|
||||
|
||||
export interface IContent {
|
||||
value: string;
|
||||
type?: string;
|
||||
}
|
||||
|
||||
export interface IMessage {
|
||||
content: IContent;
|
||||
author: IUser | IBot;
|
||||
}
|
||||
@@ -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 {}
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
@@ -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';
|
||||
@@ -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
@@ -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({
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+3
-3
@@ -31,11 +31,11 @@ const getDataEndpoint = () => {
|
||||
|
||||
export default defineConfig({
|
||||
server: {
|
||||
host: 'data.local.zhishuyun.com',
|
||||
host: 'chat.local.zhishuyun.com',
|
||||
port: 443,
|
||||
https: {
|
||||
key: fs.readFileSync('certs/data.local.zhishuyun.com.cert.key'),
|
||||
cert: fs.readFileSync('certs/data.local.zhishuyun.com.cert.crt')
|
||||
key: fs.readFileSync('certs/chat.local.zhishuyun.com.cert.key'),
|
||||
cert: fs.readFileSync('certs/chat.local.zhishuyun.com.cert.crt')
|
||||
},
|
||||
proxy: {
|
||||
'/api/v1/me': {
|
||||
|
||||
Reference in new issue
Block a user