diff --git a/src/App.vue b/src/App.vue index 46b7bc994ae5882e2164b749f0fa6e0f32210a97..a7b090a53af18a444796f0e0f063f02b8143016b 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 1e271297eb18ebad2988ce341cde2d07ff07150b..90adc27cc5e0f70849fd4623156da8bbeeda337c 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 4aad8107f34b1f5a3cc1fcd4d8f66c80521ca31a..87b39abcb9c76f55f384a6f6b2faaf234df86b0d 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 => { - - }); + }