Skip to content

Commit 2ef484e

Browse files
committed
【代码重构】AI:“聊天模型”重构为“模型”,支持 type 模型类型
1 parent ae632ac commit 2ef484e

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

src/views/ai/image/index/components/midjourney/index.vue

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,13 @@
9595
</el-space>
9696
</div>
9797
<div class="btns">
98-
<el-button type="primary" size="large" round @click="handleGenerateImage">
98+
<el-button
99+
type="primary"
100+
size="large"
101+
round
102+
:disabled="prompt.length === 0"
103+
@click="handleGenerateImage"
104+
>
99105
{{ drawIn ? '生成中' : '生成内容' }}
100106
</el-button>
101107
</div>
@@ -112,9 +118,19 @@ import {
112118
MidjourneyVersions,
113119
NijiVersionList
114120
} from '@/views/ai/utils/constants'
121+
import { ModelVO } from '@/api/ai/model/model'
115122
116123
const message = useMessage() // 消息弹窗
117124
125+
// 接收父组件传入的模型列表
126+
const props = defineProps({
127+
models: {
128+
type: Array<ModelVO>,
129+
default: () => [] as ModelVO[]
130+
}
131+
})
132+
const emits = defineEmits(['onDrawStart', 'onDrawComplete']) // 定义 emits
133+
118134
// 定义属性
119135
const drawIn = ref<boolean>(false) // 生成中
120136
const selectHotWord = ref<string>('') // 选中的热词
@@ -125,7 +141,6 @@ const selectModel = ref<string>('midjourney') // 选中的模型
125141
const selectSize = ref<string>('1:1') // 选中 size
126142
const selectVersion = ref<any>('6.0') // 选中的 version
127143
const versionList = ref<any>(MidjourneyVersions) // version 列表
128-
const emits = defineEmits(['onDrawStart', 'onDrawComplete']) // 定义 emits
129144
130145
/** 选择热词 */
131146
const handleHotWordClick = async (hotWord: string) => {
@@ -158,6 +173,15 @@ const handleModelClick = async (model: ImageModelVO) => {
158173
159174
/** 图片生成 */
160175
const handleGenerateImage = async () => {
176+
// 从 models 中查找匹配的模型
177+
const matchedModel = props.models.find(
178+
(item) => item.model === selectModel.value && item.platform === AiPlatformEnum.MIDJOURNEY
179+
)
180+
if (!matchedModel) {
181+
message.error('该模型不可用,请选择其它模型')
182+
return
183+
}
184+
161185
// 二次确认
162186
await message.confirm(`确认生成内容?`)
163187
try {
@@ -171,7 +195,7 @@ const handleGenerateImage = async () => {
171195
) as ImageSizeVO
172196
const req = {
173197
prompt: prompt.value,
174-
model: selectModel.value,
198+
modelId: matchedModel.id,
175199
width: imageSize.width,
176200
height: imageSize.height,
177201
version: selectVersion.value,

src/views/ai/image/index/components/stableDiffusion/index.vue

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<template>
33
<div class="prompt">
44
<el-text tag="b">画面描述</el-text>
5-
<el-text tag="p">建议使用“形容词+动词+风格”的格式,使用“,”隔开</el-text>
5+
<el-text tag="p">建议使用“形容词 + 动词 + 风格”的格式,使用“,”隔开</el-text>
66
<el-input
77
v-model="prompt"
88
maxlength="1024"
9-
rows="5"
9+
:rows="5"
1010
class="w-100% mt-15px"
1111
input-style="border-radius: 7px;"
1212
placeholder="例如:童话里的小屋应该是什么样子?"
@@ -128,7 +128,14 @@
128128
</el-space>
129129
</div>
130130
<div class="btns">
131-
<el-button type="primary" size="large" round :loading="drawIn" @click="handleGenerateImage">
131+
<el-button
132+
type="primary"
133+
size="large"
134+
round
135+
:loading="drawIn"
136+
:disabled="prompt.length === 0"
137+
@click="handleGenerateImage"
138+
>
132139
{{ drawIn ? '生成中' : '生成内容' }}
133140
</el-button>
134141
</div>
@@ -143,9 +150,19 @@ import {
143150
StableDiffusionSamplers,
144151
StableDiffusionStylePresets
145152
} from '@/views/ai/utils/constants'
153+
import { ModelVO } from '@/api/ai/model/model'
146154
147155
const message = useMessage() // 消息弹窗
148156
157+
// 接收父组件传入的模型列表
158+
const props = defineProps({
159+
models: {
160+
type: Array<ModelVO>,
161+
default: () => [] as ModelVO[]
162+
}
163+
})
164+
const emits = defineEmits(['onDrawStart', 'onDrawComplete']) // 定义 emits
165+
149166
// 定义属性
150167
const drawIn = ref<boolean>(false) // 生成中
151168
const selectHotWord = ref<string>('') // 选中的热词
@@ -160,8 +177,6 @@ const scale = ref<number>(7.5) // 引导系数
160177
const clipGuidancePreset = ref<string>('NONE') // 文本提示相匹配的图像(clip_guidance_preset) 简称 CLIP
161178
const stylePreset = ref<string>('3d-model') // 风格
162179
163-
const emits = defineEmits(['onDrawStart', 'onDrawComplete']) // 定义 emits
164-
165180
/** 选择热词 */
166181
const handleHotWordClick = async (hotWord: string) => {
167182
// 情况一:取消选中
@@ -177,6 +192,16 @@ const handleHotWordClick = async (hotWord: string) => {
177192
178193
/** 图片生成 */
179194
const handleGenerateImage = async () => {
195+
// 从 models 中查找匹配的模型
196+
const selectModel = 'stable-diffusion-v1-6'
197+
const matchedModel = props.models.find(
198+
(item) => item.model === selectModel && item.platform === AiPlatformEnum.STABLE_DIFFUSION
199+
)
200+
if (!matchedModel) {
201+
message.error('该模型不可用,请选择其它模型')
202+
return
203+
}
204+
180205
// 二次确认
181206
if (hasChinese(prompt.value)) {
182207
message.alert('暂不支持中文!')
@@ -191,8 +216,7 @@ const handleGenerateImage = async () => {
191216
emits('onDrawStart', AiPlatformEnum.STABLE_DIFFUSION)
192217
// 发送请求
193218
const form = {
194-
platform: AiPlatformEnum.STABLE_DIFFUSION,
195-
model: 'stable-diffusion-v1-6',
219+
modelId: matchedModel.id,
196220
prompt: prompt.value, // 提示词
197221
width: width.value, // 图片宽度
198222
height: height.value, // 图片高度

0 commit comments

Comments
 (0)