@@ -62,7 +84,6 @@
- {{ item.img }}
@@ -96,12 +117,12 @@
-
+ -->
-
@@ -169,6 +187,12 @@ export default {
prompt: '',
config: {
},
+ sdServerType: 'common',
+ sdServerTypeOptions: [
+ { label: '公共服务器', value: 'common' },
+ { label: '私有服务器', value: 'private' },
+ ],
+ sdServerUrl: 'https://gpu-pod64a4ff02b54fe048c07abc40-6006.node.inscode.run/sdapi/v1/txt2img',
loading: false,
maxHistory: 200,
speaking: false, // 是否正在输出语音
@@ -301,17 +325,19 @@ export default {
config.height = this.height
config.steps = this.steps
config.sampler = this.sampler
+ config.sd_api = this.sdServerUrl
SDApi.draw(config, query, negative_prompt).then(res => {
_this.loading = false
- _this.saveHistory()
+
console.info('close')
currentMsg.img = res
messages.splice(messages.length - 1, 1)
messages.push(currentMsg)
_this.scrollBottom()
+ _this.saveHistory()
}).catch(err => {
@@ -396,17 +422,14 @@ export default {
}
},
recoveryHistory() {
- const cacheKey = this.history.key
- StorageApi.get(this.history.name, cacheKey).then(data => {
- debugger
+ StorageApi.get(this.history.name).then(data => {
if (data && data.data) {
this.message = JSON.parse(data.data)
}
})
},
saveHistory() {
- const cacheKey = this.history.key
if (this.message.length > this.maxHistory) {
const tmpHistory = []
const start = this.message.length - this.maxHistory
@@ -414,9 +437,9 @@ export default {
for (let id = start; id < end; id++) {
tmpHistory.push(this.message[id])
}
- StorageApi.put(this.history.name, cacheKey, JSON.stringify(tmpHistory))
+ StorageApi.put(this.history.name, JSON.stringify(tmpHistory))
} else {
- StorageApi.put(this.history.name, cacheKey, JSON.stringify(this.message))
+ StorageApi.put(this.history.name, JSON.stringify(this.message))
}
},
@@ -449,6 +472,35 @@ export default {
},
copyAsPrompt (message) {
this.prompt = message
+ },
+ handleServerTypeChange (type) {
+
+ if (type === 'common') {
+ this.sdServerUrl = this.config.common_sd_api
+ }
+
+ console.info(123)
+ },
+ recoverConfig () {
+ const config = localStorage.getItem('ai-config')
+ if (config) {
+ const configJSON = JSON.parse(config)
+ this.config = configJSON
+ this.sdServerType = configJSON.sdServerType
+ this.sdServerUrl = configJSON.sdServerUrl
+ } else {
+
+ this.getAppInfo()
+ this.sdServerUrl = this.config.common_sd_api
+
+ }
+ },
+ saveConfig () {
+
+ const config = JSON.parse(JSON.stringify(this.config))
+ config.sdServerType = this.sdServerType
+ config.sdServerUrl = this.sdServerUrl
+ localStorage.setItem('ai-config', JSON.stringify(config))
}
},
mounted() {
@@ -456,7 +508,7 @@ export default {
StorageApi.init(this.history.name).then(res => {
this.recoveryHistory()
})
- this.getAppInfo()
+ this.recoverConfig()
// this.getAvatar()
if (this.mode === 'draw') {
this.prompt = this.default_prompt
diff --git a/src/js/config.js b/src/js/config.js
index a60f19dfdfbe38a0439c5a1e4989ccc9182dc194..0127adb0814d6fc7b2c1c25cbd5cb7a9d7d55d03 100644
--- a/src/js/config.js
+++ b/src/js/config.js
@@ -11,7 +11,7 @@ export default {
"ext": {
"mode":"chat",
"model":"vicuna-7b-all-v1.1",
- "api_url":"https://gpu-pod647d498393e106496a046e94-8000.node.inscode.run/v1",
+ "api_url":"",
"api_type":"openai",
"robot_img":null,
"api_max_token":"1024",
@@ -20,7 +20,7 @@ export default {
"prompt_template":"",
"api_prompt_prefix":"",
"show_profile_setting":false,
- "sd_api": 'https://api.quickapi.cloud/sd/',
+ "common_sd_api": "https://api.quickapi.cloud/test/common/sd/",
},
diff --git a/src/js/sd.js b/src/js/sd.js
index 64e4fa0e696db933d6cae2560087983ffbda5912..a09591147aef48ef4cd2d400b708228c9d8f5c63 100644
--- a/src/js/sd.js
+++ b/src/js/sd.js
@@ -18,7 +18,11 @@ export default {
'content-type': 'application/json'
};
- axios.post(config?.sd_api, data, { headers }).then(response => {
+ let api = config?.sd_api
+ if (api.indexOf('/sd') === -1) {
+ api += '/sdapi/v1/txt2img'
+ }
+ axios.post(api, data, { headers }).then(response => {
if (response.status === 200 && response?.data?.images){
const image = response?.data?.images[0]
diff --git a/src/js/storage.js b/src/js/storage.js
index 9c81ffb870bb67f534cd15dd9fc0a69966317e35..38c1ac448a9c09c6fed852a9434962381c313565 100644
--- a/src/js/storage.js
+++ b/src/js/storage.js
@@ -2,7 +2,7 @@ let db = null
const defaultTableName = 'history'
export default {
init(tableName = defaultTableName) {
- let request = window.indexedDB.open('ai-draw', '1')
+ let request = window.indexedDB.open('ai-draw', 1)
return new Promise((resolve, reject) => {
// 数据库操作过程中出错,则错误回调被触发
@@ -21,7 +21,7 @@ export default {
db = event.target.result
let objectStore = db.createObjectStore(tableName, { keyPath: 'id' })
- objectStore.createIndex('key', 'key', { unique: true })
+ // objectStore.createIndex('key', 'key', { unique: true })
console.log("db onupgradeneeded 成功")
resolve()
}
@@ -30,12 +30,11 @@ export default {
isConnected(tableName = defaultTableName){
return db != null
},
- set(tableName = defaultTableName, key, val, id = 100){
+ set(tableName = defaultTableName, val, id = 100){
let request = db.transaction(tableName, 'readwrite')
.objectStore(tableName)
.add({
id: id,
- key: key,
data: val
})
return new Promise((resolve, reject) => {
@@ -49,12 +48,11 @@ export default {
}
})
},
- put(tableName = defaultTableName, key, val, id = 100){
+ put(tableName = defaultTableName, val, id = 100){
let request = db.transaction(tableName, 'readwrite')
.objectStore(tableName)
.put({
id: id,
- key: key,
data: val
})
return new Promise((resolve, reject) => {
@@ -87,11 +85,9 @@ export default {
}
})
},
- get(tableName = defaultTableName, key){
+ get(tableName = defaultTableName, id = 100){
let request = db.transaction(tableName, 'readwrite')
- .objectStore(tableName)
- .index('key')
- .get(key)
+ .objectStore(tableName).get(id)
console.info("获取")