feat: midjourney image variation function is ready

This commit is contained in:
RockYang
2023-08-15 17:31:02 +08:00
parent 113769791f
commit e65c32c4c7
7 changed files with 95 additions and 26 deletions

View File

@@ -92,14 +92,23 @@ watch(() => props.content, (newVal) => {
});
const emits = defineEmits(['disable-input', 'disable-input']);
const upscale = (index) => {
send('/api/mj/upscale', index)
}
const variation = (index) => {
send('/api/mj/variation', index)
}
const send = (url, index) => {
loading.value = true
emits('disable-input')
httpPost("/api/mj/upscale", {
httpPost(url, {
index: index,
message_id: data.value?.["message_id"],
message_hash: data.value?.["image"]?.hash,
session_id: getSessionId(),
key: data.value?.["key"]
key: data.value?.["key"],
prompt: data.value?.["prompt"],
}).then(() => {
ElMessage.success("任务推送成功,请耐心等待任务执行...")
loading.value = false
@@ -108,10 +117,6 @@ const upscale = (index) => {
emits('disable-input')
})
}
const variation = (index) => {
ElMessage.warning("当前版本暂未实现 Variation 功能!")
}
</script>
<style lang="stylus">

View File

@@ -554,6 +554,12 @@ const connect = function (chat_id, role_id) {
const content = data.content;
const md = require('markdown-it')({breaks: true});
content.content = md.render(content.content)
let key = content.key
// fixed bug: 执行 Upscale 和 Variation 操作的时候覆盖之前的绘画
if (content.status === "Finished") {
key = randString(32)
enableInput()
}
// console.log(content)
// check if the message is in chatData
let flag = false
@@ -562,21 +568,19 @@ const connect = function (chat_id, role_id) {
console.log(chatData.value[i])
flag = true
chatData.value[i].content = content
chatData.value[i].id = key
break
}
}
if (flag === false) {
chatData.value.push({
type: "mj",
id: content["message_id"],
id: key,
icon: "/images/avatar/mid_journey.png",
content: content
});
}
if (content.status === "Finished") {
enableInput()
}
} else if (data.type === 'end') { // 消息接收完毕
// 追加当前会话到会话列表
if (isNewChat && newChatItem.value !== null) {
@@ -589,7 +593,7 @@ const connect = function (chat_id, role_id) {
enableInput()
lineBuffer.value = ''; // 清空缓冲
// 获取 token
const reply = chatData.value[chatData.value.length - 1]
httpGet(`/api/chat/tokens?text=${reply.orgContent}&model=${model.value}`).then(res => {

View File

@@ -44,7 +44,6 @@ import {onMounted, ref} from "vue";
import {Lock, UserFilled} from "@element-plus/icons-vue";
import {httpPost} from "@/utils/http";
import {ElMessage} from "element-plus";
import {setSession} from "@/store/session";
import {useRouter} from "vue-router";
import FooterBar from "@/components/FooterBar.vue";