forked from xusenlin/chatGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
284 lines (272 loc) · 13.4 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>XuSenLin GPT</title>
<!-- Import style -->
<link rel="stylesheet" href="//unpkg.com/element-plus/dist/index.css"/>
<!-- Import Vue 3 -->
<script src="https://unpkg.com/vue@3/dist/vue.global.prod.js"></script>
<!-- <script src="//unpkg.com/vue@3"></script>-->
<!-- Import component library -->
<script src="//unpkg.com/element-plus"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/default.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
<!-- and it's easy to individually load additional languages -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/languages/go.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/4.3.0/marked.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/a11y-light.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/highlight.min.js"></script>
<style>
.container {
width: 100%;
max-width: 1200px;
margin: 0 auto;
}
.head {
height: 40px;
display: flex;
align-items: center;
}
.mt {
margin-bottom: 20px;
}
.send-group {
margin-top: 20px;
display: flex;
justify-content: flex-end;
}
pre{
background: #f7f7f7!important;
border-radius: 2px;
padding: 10px;
}
.card-header{
display: flex;
align-items: center;
justify-content: space-between;
}
.dialog-msg{
font-size: 14px;
white-space: pre-wrap;
word-wrap: break-word;
}
</style>
</head>
<body>
<div id="app">
<el-container>
<el-header class="head">
<div class="container" style="display: flex;justify-content: space-between">
<div>XuSenLin ChatGPT</div>
<div style="font-size: 12px;color: #999">id:{{ dialog.uuid }}</div>
</div>
</el-header>
<el-main>
<div class="container">
<el-card v-for="(n,i) in dialog.chat" class="box-card mt" shadow="never">
<template #header>
<div class="card-header">
<span>{{ n.role.charAt(0).toUpperCase() + n.role.slice(1) }}</span>
<el-button link type="warning" @click="dialog.chat.splice(i,1)">
Remove
</el-button>
</div>
</template>
<div class="dialog-msg" v-html="markedParse(n.content)"></div>
</el-card>
<el-card class="box-card mt" shadow="never">
<template #header>
<div class="card-header">
<span>Question</span>
<el-button type="success" link @click="dialogTableVisible = true">
Prompts
</el-button>
</div>
</template>
<div>
<el-input
v-model="question"
:rows="3"
type="textarea"
placeholder="Please input question"
/>
</div>
<div class="send-group">
<el-button type="warning" round :disabled="answering" @click="resetDialog">Reset</el-button>
<el-button type="success" round :disabled="answering" @click="sendQuestion">Send</el-button>
</div>
</el-card>
<el-dialog width="80%" v-model="dialogTableVisible" title="Prompts">
<el-collapse model-value="">
<el-collapse-item v-for="n in gridData" :title="n.title">
<div>
{{n.prompt}}
</div>
<div style="display: flex;justify-content: flex-end">
<el-button round size="small" type="success" :disabled="answering" @click="question=n.prompt;dialogTableVisible=false">Utilize this prompt.</el-button>
</div>
</el-collapse-item>
</el-collapse>
</el-dialog>
</div>
</el-main>
<el-footer >
<div style="width: 100%;text-align: center;color: #aa0000;font-size: 12px">
本项目是一个实验性项目,可能存在不足和错误,仅供学术研究和讨论目的使用,不以任何形式获利,也不得用于任何商业用途,请谨慎使用。
<div style="color: #999;margin-top: 10px">如果你觉得此项目帮助到了你,想请我喝一杯☕️,<a style="color: #999" href="./coffee" target="_blank">请点此扫码</a>😄</div>
</div>
</el-footer>
</el-container>
</div>
<script>
function htmlEncode(str) {
var temp = "";
if (str.length == 0) return "";
temp = str.replace(/&/g, "&");
temp = temp.replace(/</g, "<");
temp = temp.replace(/>/g, ">");
temp = temp.replace(/\s/g, " ");
temp = temp.replace(/\'/g, "'");
temp = temp.replace(/\"/g, """);
return temp;
}
const App = {
data() {
return {
question: "",
dialogTableVisible:false,
answering:false,
dialog: {
uuid: "",
chat: [],
},
gridData:[
{
title:"英文翻译中文",
prompt:"你是一款人工智能翻译助手,专门为我提供英文翻译成中文的服务。无论我需要翻译常用短语、商务文件或其他日常交流,你都能为我提供最准确的中文翻译。只需输入我的英文句子或短语,你就可以提供给我最准确的中文翻译。让我们开始吧!我的第一句英文是\" hello \""
},
{
title:"Linux Terminal",
prompt:"I want you to act as a linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. do not write explanations. do not type commands unless I instruct you to do so. when i need to tell you something in english, i will do so by putting text inside curly brackets {like this}. my first command is pwd"
},
{
title:"English Translator and Improver",
prompt:"I want you to act as an English translator, spelling corrector and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper level English words and sentences. Keep the meaning same, but make them more literary. I want you to only reply the correction, the improvements and nothing else, do not write explanations. My first sentence is \"istanbulu cok seviyom burada olmak cok guzel\""
},
{
title:"`position` Interviewer",
prompt:"I want you to act as an interviewer. I will be the candidate and you will ask me the interview questions for the `position` position. I want you to only reply as the interviewer. Do not write all the conservation at once. I want you to only do the interview with me. Ask me the questions and wait for my answers. Do not write explanations. Ask me the questions one by one like an interviewer does and wait for my answers. My first sentence is \"Hi\""
},
{
title:"JavaScript Console",
prompt:"I want you to act as a javascript console. I will type commands and you will reply with what the javascript console should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. do not write explanations. do not type commands unless I instruct you to do so. when i need to tell you something in english, i will do so by putting text inside curly brackets {like this}. my first command is console.log(\"Hello World\");"
},
{
title:"Storyteller",
prompt:"I want you to act as a storyteller. You will come up with entertaining stories that are engaging, imaginative and captivating for the audience. It can be fairy tales, educational stories or any other type of stories which has the potential to capture people's attention and imagination. Depending on the target audience, you may choose specific themes or topics for your storytelling session e.g., if it’s children then you can talk about animals; If it’s adults then history-based tales might engage them better etc. My first request is \"I need an interesting story on perseverance.\""
},
]
};
},
methods: {
markedParse(t){
return marked.parse(t)
},
resetDialog(){
this.dialog.chat = []
},
sendQuestion() {
this.question = this.question.trim()
if (this.question.length == 0) {
ElementPlus.ElNotification.warning({
title: "warning",
message: "请输入你的问题!"
})
return
}
this.answering = true
this.dialog.chat.push({
role: "user",
content: htmlEncode(this.question)
})
this.question = ""
const loadingInstance = ElementPlus.ElLoading.service()
let json = JSON.stringify(this.dialog)
this.dialog.chat.push({
role: "assistant",
content: ""
})
fetch("./send", {
method: "post",
body: json,
}).then(response => response.text())
.then(t => {
if (t != "ok") {
ElementPlus.ElNotification.warning({
title: "warning",
message: t
})
return
}
})
.catch(error => {
ElementPlus.ElNotification.warning({
title: "warning",
message: JSON.stringify(error)
})
}).finally(() => {
loadingInstance.close()
});
}
},
created() {
let evtSource = new EventSource("./receive")
evtSource.onmessage = event => {
// 获取服务器发送过来的数据
let len = this.dialog.chat.length
let t = JSON.parse(event.data).content
let stream = document.getElementById('stream')
// if(!stream){
// return
// }
// stream.innerHTML = marked.parse(t);
this.dialog.chat[len - 1].content += t
};
evtSource.addEventListener("uuid", event => {
this.dialog.uuid = event.data
})
evtSource.addEventListener("eof", event => {
let len = this.dialog.chat.length
let msg = document.querySelectorAll('.dialog-msg')
this.answering = false
if (msg.length !== len || msg.length === 0){
return
}
let pre = msg[len-1].querySelectorAll('pre')
if(pre.length ===0){
return;
}
pre.forEach(el=>{
hljs.highlightElement(el);
})
//let lastMsgHtml = msg[len-1].innerHTML
// console.log(parseText(c))
// this.dialog.chat[len - 1].content = c.replace(/```(\w*)([\w\W]*?)```/g,'<pre><code lang="$1">$2</code></pre>')
})
evtSource.onerror = (error) => {
// 处理错误情况
ElementPlus.ElNotification.warning({
title: "warning",
message: JSON.stringify(error)
})
};
}
};
const app = Vue.createApp(App);
app.use(ElementPlus);
app.mount("#app");
</script>
</body>
</html>