diff --git a/package.json b/package.json index 0da4bda44a61169007c72bf67e114eb0f326fe29..d2697d122867329907836d05afb4186890ae7587 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "dependencies": { "@microsoft/fetch-event-source": "^2.0.1", + "axios": "^1.4.0", "guess": "^1.0.2", "npm": "^9.7.2", "tdesign-vue-next": "^1.3.9", diff --git a/public/loading.gif b/public/loading.gif new file mode 100644 index 0000000000000000000000000000000000000000..d5c3c392e6883c4d18a6f1ffc564610d9a1e5714 Binary files /dev/null and b/public/loading.gif differ diff --git a/src/App.vue b/src/App.vue index a7b090a53af18a444796f0e0f063f02b8143016b..bf8f2ab89d85e3fdcc4c7c69bf3a1218a6080816 100644 --- a/src/App.vue +++ b/src/App.vue @@ -62,11 +62,19 @@
- {{ item.message ? item.message : '...' }} + + +
-
+
@@ -228,26 +236,31 @@ export default { // this.getAnswer() // } + }, + scrollBottom () { + const _this = this + this.$nextTick(() => { + _this.$refs.messageList.scrollTop = _this.$refs.messageList.scrollHeight + 20; + }) + }, draw () { - if (this.prompt) { - - } const currentMsg = { "user": "AI", "message": '', img: null, viewMode: 'image' } const query = this.prompt const _this = this const messages = this.message + messages.push({ "user": "User", "message": this.prompt }) messages.push(currentMsg) this.loading = true this.prompt = '' + this.scrollBottom() SDApi.draw(this.config, query).then(res => { - debugger _this.loading = false _this.saveHistory() console.info('close') @@ -255,6 +268,9 @@ export default { messages.splice(messages.length - 1, 1) messages.push(currentMsg) + _this.scrollBottom() + + }).catch(err => { _this.loading = false }) @@ -315,7 +331,7 @@ export default { document.title = this.name if (data.ext) { const config = data.ext - debugger + this.config = config if (config.default_prompt) { this.prompt = config.default_prompt diff --git a/src/js/config.js b/src/js/config.js index 90adc27cc5e0f70849fd4623156da8bbeeda337c..a60f19dfdfbe38a0439c5a1e4989ccc9182dc194 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -15,7 +15,7 @@ export default { "api_type":"openai", "robot_img":null, "api_max_token":"1024", - "default_prompt":"请翻译成英文:你是谁?", + "default_prompt":"cat", "max_request_len":"10000", "prompt_template":"", "api_prompt_prefix":"", diff --git a/src/js/sd.js b/src/js/sd.js index 87b39abcb9c76f55f384a6f6b2faaf234df86b0d..45c9e7d2416994969f15ecf6f7c8b6e2a7998f47 100644 --- a/src/js/sd.js +++ b/src/js/sd.js @@ -1,12 +1,13 @@ +import axios from "axios"; + export default { draw (config, prompt) { -debugger return new Promise(function(resolve,rejcet){ - debugger + const data = { prompt: prompt, steps: config?.steps??20, - negative_prompt: config?.negative_prompt??'', + negative_prompt: config?.negative_prompt??'nsfw', width: config?.width??512, height: config?.height??512, cfg_scale: config?.cfg_scale??6, @@ -19,9 +20,8 @@ debugger axios.post(config?.sd_api, data, { headers }).then(response => { - debugger - if (response.statusCode === 200 && response?.data?.images){ - const image = res?.data?.images[0] + if (response.status === 200 && response?.data?.images){ + const image = response?.data?.images[0] resolve('data:image/png;base64,' + image) }