From 1d7f460a8d367ab31f538fb9654b2f0e408ff87c Mon Sep 17 00:00:00 2001 From: 622aa39c1f9b166ab1a38c05 <622aa39c1f9b166ab1a38c05@devide> Date: Mon, 3 Jul 2023 10:36:00 +0000 Subject: [PATCH] Mon Jul 3 10:36:00 UTC 2023 inscode --- src/App.vue | 49 ++++++++++++++++++++++++++++++++++++++++++------ src/js/config.js | 7 +++++-- src/js/sd.js | 49 ++++++++++++++++++++++++++++++------------------ 3 files changed, 79 insertions(+), 26 deletions(-) diff --git a/src/App.vue b/src/App.vue index 46b7bc9..a7b090a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -98,6 +98,7 @@ // import { Configuration, OpenAIApi } from "openai" import OpenAI from './js/openai.js' import Config from './js/config.js' +import SDApi from './js/sd.js' // import MarkdownItVue from 'markdown-it-vue' // import 'markdown-it-vue/dist/markdown-it-vue.css' @@ -116,6 +117,7 @@ export default { name: '加载中...', userAvatarList: [], robotAvatarList: [], + mode: 'draw', message: [ // {"user": "User", "message": "创建一个用户表,要求分区"}, // {"user": "AI", "message": "在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:在GaussDB数据库中创建一个带有分区的用户表可以使用以下语句:"}, @@ -211,16 +213,51 @@ export default { return } - if (this.indexClient) { - this.indexClient.query(this.prompt).then(res => { - this.getAnswer(res) - }).catch((err) => { - this.getAnswer() - }) + if (this.mode === 'draw') { + this.draw() } else { this.getAnswer() } + // if (this.indexClient) { + // this.indexClient.query(this.prompt).then(res => { + // this.getAnswer(res) + // }).catch((err) => { + // this.getAnswer() + // }) + // } else { + // this.getAnswer() + // } + + }, + 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(currentMsg) + this.loading = true + this.prompt = '' + SDApi.draw(this.config, query).then(res => { + + debugger + _this.loading = false + _this.saveHistory() + console.info('close') + currentMsg.img = res + + messages.splice(messages.length - 1, 1) + messages.push(currentMsg) + }).catch(err => { + _this.loading = false + }) }, getAnswer(context) { this.loading = true diff --git a/src/js/config.js b/src/js/config.js index 1e27129..90adc27 100644 --- a/src/js/config.js +++ b/src/js/config.js @@ -19,8 +19,11 @@ export default { "max_request_len":"10000", "prompt_template":"", "api_prompt_prefix":"", - "show_profile_setting":false - } + "show_profile_setting":false, + "sd_api": 'https://api.quickapi.cloud/sd/', + }, + + }, "message": "success" } diff --git a/src/js/sd.js b/src/js/sd.js index 4aad810..87b39ab 100644 --- a/src/js/sd.js +++ b/src/js/sd.js @@ -1,24 +1,37 @@ export default { - draw (url, config) { + draw (config, prompt) { +debugger + return new Promise(function(resolve,rejcet){ + debugger + const data = { + prompt: prompt, + steps: config?.steps??20, + negative_prompt: config?.negative_prompt??'', + width: config?.width??512, + height: config?.height??512, + cfg_scale: config?.cfg_scale??6, + seed : config?.seed??-1, + sampler_name: config?.sampler_name??"DPM++ SDE Karras" + } + const headers = { + 'content-type': 'application/json' + }; + + axios.post(config?.sd_api, data, { headers }).then(response => { + + debugger + if (response.statusCode === 200 && response?.data?.images){ + const image = res?.data?.images[0] + resolve('data:image/png;base64,' + image) + } + + }).catch(err => { + rejcet(err) + }); + }) - const data = { - prompt: config.prompt, - steps: config?.steps??20, - negative_prompt: config?.negative_prompt??'', - width: config?.width??512, - height: config?.height??512, - cfg_scale: config?.cfg_scale??6, - seed : config?.seed??-1, - sampler_name: config?.sampler_name??"DPM++ SDE Karras" - } - const headers = { - 'content-type': 'application/json' - }; - - axios.post(url, data, { headers }).then(response => { - - }); + } -- GitLab