Mon Jul 3 11:38:00 UTC 2023 inscode

上级 1d7f460a
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
}, },
"dependencies": { "dependencies": {
"@microsoft/fetch-event-source": "^2.0.1", "@microsoft/fetch-event-source": "^2.0.1",
"axios": "^1.4.0",
"guess": "^1.0.2", "guess": "^1.0.2",
"npm": "^9.7.2", "npm": "^9.7.2",
"tdesign-vue-next": "^1.3.9", "tdesign-vue-next": "^1.3.9",
......
...@@ -62,11 +62,19 @@ ...@@ -62,11 +62,19 @@
<t-image class="rounded-lg" v-if="config.robot_img" :src="config.robot_img" fit="cover" <t-image class="rounded-lg" v-if="config.robot_img" :src="config.robot_img" fit="cover"
:style="{ width: '40px', height: '40px' }"></t-image> :style="{ width: '40px', height: '40px' }"></t-image>
<div class="bg-slate-50 text-gray-700 p-4 mx-2 w-fit max-w-2xl 2xl:max-w-4xl rounded-lg text-wrapper"> <div class="bg-slate-50 text-gray-700 p-4 mx-2 w-fit max-w-2xl 2xl:max-w-4xl rounded-lg text-wrapper">
<template v-if="item?.viewMode??'chat' === 'image'">
<img v-if="item.img" :src="item.img"/>
<img v-else src="/loading.gif" class="max-w-[512px]"/>
</template>
<template>
{{ item.message ? item.message : '...' }} {{ item.message ? item.message : '...' }}
</template>
</div> </div>
</div> </div>
</div> </div>
<div class="text-center"> <div class="text-center" v-if="mode !== 'draw'">
<div v-if="loading" @click="stop" class="-mt-4 px-5 py-1 m-auto w-fit cursor-pointer hover:bg-slate-300 border-dotted border-[1px] border-slate-400 rounded-md"> <div v-if="loading" @click="stop" class="-mt-4 px-5 py-1 m-auto w-fit cursor-pointer hover:bg-slate-300 border-dotted border-[1px] border-slate-400 rounded-md">
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="animate-spin w-4 h-4 inline-block"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="animate-spin w-4 h-4 inline-block">
<path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" /> <path stroke-linecap="round" stroke-linejoin="round" d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
...@@ -229,25 +237,30 @@ export default { ...@@ -229,25 +237,30 @@ export default {
// } // }
}, },
draw () { scrollBottom () {
const _this = this
this.$nextTick(() => {
_this.$refs.messageList.scrollTop = _this.$refs.messageList.scrollHeight + 20;
})
if (this.prompt) { },
draw () {
}
const currentMsg = { const currentMsg = {
"user": "AI", "message": '', img: null, viewMode: 'image' "user": "AI", "message": '', img: null, viewMode: 'image'
} }
const query = this.prompt const query = this.prompt
const _this = this const _this = this
const messages = this.message const messages = this.message
messages.push({ "user": "User", "message": this.prompt })
messages.push(currentMsg) messages.push(currentMsg)
this.loading = true this.loading = true
this.prompt = '' this.prompt = ''
this.scrollBottom()
SDApi.draw(this.config, query).then(res => { SDApi.draw(this.config, query).then(res => {
debugger
_this.loading = false _this.loading = false
_this.saveHistory() _this.saveHistory()
console.info('close') console.info('close')
...@@ -255,6 +268,9 @@ export default { ...@@ -255,6 +268,9 @@ export default {
messages.splice(messages.length - 1, 1) messages.splice(messages.length - 1, 1)
messages.push(currentMsg) messages.push(currentMsg)
_this.scrollBottom()
}).catch(err => { }).catch(err => {
_this.loading = false _this.loading = false
}) })
...@@ -315,7 +331,7 @@ export default { ...@@ -315,7 +331,7 @@ export default {
document.title = this.name document.title = this.name
if (data.ext) { if (data.ext) {
const config = data.ext const config = data.ext
debugger
this.config = config this.config = config
if (config.default_prompt) { if (config.default_prompt) {
this.prompt = config.default_prompt this.prompt = config.default_prompt
......
...@@ -15,7 +15,7 @@ export default { ...@@ -15,7 +15,7 @@ export default {
"api_type":"openai", "api_type":"openai",
"robot_img":null, "robot_img":null,
"api_max_token":"1024", "api_max_token":"1024",
"default_prompt":"请翻译成英文:你是谁?", "default_prompt":"cat",
"max_request_len":"10000", "max_request_len":"10000",
"prompt_template":"", "prompt_template":"",
"api_prompt_prefix":"", "api_prompt_prefix":"",
......
import axios from "axios";
export default { export default {
draw (config, prompt) { draw (config, prompt) {
debugger
return new Promise(function(resolve,rejcet){ return new Promise(function(resolve,rejcet){
debugger
const data = { const data = {
prompt: prompt, prompt: prompt,
steps: config?.steps??20, steps: config?.steps??20,
negative_prompt: config?.negative_prompt??'', negative_prompt: config?.negative_prompt??'nsfw',
width: config?.width??512, width: config?.width??512,
height: config?.height??512, height: config?.height??512,
cfg_scale: config?.cfg_scale??6, cfg_scale: config?.cfg_scale??6,
...@@ -19,9 +20,8 @@ debugger ...@@ -19,9 +20,8 @@ debugger
axios.post(config?.sd_api, data, { headers }).then(response => { axios.post(config?.sd_api, data, { headers }).then(response => {
debugger if (response.status === 200 && response?.data?.images){
if (response.statusCode === 200 && response?.data?.images){ const image = response?.data?.images[0]
const image = res?.data?.images[0]
resolve('data:image/png;base64,' + image) resolve('data:image/png;base64,' + image)
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册