Skip to content

Commit c76b622

Browse files
committed
【增加】ai image 对接通义参数
1 parent 51c6bfe commit c76b622

File tree

2 files changed

+17
-101
lines changed

2 files changed

+17
-101
lines changed

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

Lines changed: 14 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -61,79 +61,13 @@
6161
</el-select>
6262
</el-space>
6363
</div>
64-
65-
<div class="group-item">
66-
<div>
67-
<el-text tag="b">风格</el-text>
68-
</div>
69-
<el-space wrap class="group-item-body">
70-
<el-select v-model="stylePreset" placeholder="Select" size="large" class="!w-350px">
71-
<el-option
72-
v-for="item in stylePresetList"
73-
:key="item.key"
74-
:label="item.name"
75-
:value="item.key"
76-
/>
77-
</el-select>
78-
</el-space>
79-
</div>
8064
<div class="group-item">
8165
<div>
8266
<el-text tag="b">图片尺寸</el-text>
8367
</div>
8468
<el-space wrap class="group-item-body">
85-
<el-input v-model="width" class="w-170px" placeholder="图片宽度" />
86-
<el-input v-model="height" class="w-170px" placeholder="图片高度" />
87-
</el-space>
88-
</div>
89-
<div class="group-item">
90-
<div>
91-
<el-text tag="b">迭代步数</el-text>
92-
</div>
93-
<el-space wrap class="group-item-body">
94-
<el-input
95-
v-model="steps"
96-
type="number"
97-
size="large"
98-
class="!w-350px"
99-
placeholder="Please input"
100-
/>
101-
</el-space>
102-
</div>
103-
<div class="group-item">
104-
<div>
105-
<el-text tag="b">引导系数</el-text>
106-
</div>
107-
<el-space wrap class="group-item-body">
108-
<el-input
109-
v-model="scale"
110-
type="number"
111-
size="large"
112-
class="!w-350px"
113-
placeholder="Please input"
114-
/>
115-
</el-space>
116-
</div>
117-
<div class="group-item">
118-
<div>
119-
<el-text tag="b">随机因子</el-text>
120-
</div>
121-
<el-space wrap class="group-item-body">
122-
<el-input
123-
v-model="seed"
124-
type="number"
125-
size="large"
126-
class="!w-350px"
127-
placeholder="Please input"
128-
/>
129-
</el-space>
130-
</div>
131-
<div class="group-item">
132-
<div>
133-
<el-text tag="b">参考图</el-text>
134-
</div>
135-
<el-space wrap class="group-item-body">
136-
<UploadImg v-model="referImageUrl" height="120px" width="120px" />
69+
<el-input v-model="width" type="number" class="w-170px" placeholder="图片宽度" />
70+
<el-input v-model="height" type="number" class="w-170px" placeholder="图片高度" />
13771
</el-space>
13872
</div>
13973
<div class="btns">
@@ -144,11 +78,12 @@
14478
</template>
14579
<script setup lang="ts">
14680
import {ImageApi, ImageDrawReqVO, ImageVO} from '@/api/ai/image'
147-
import {hasChinese} from '@/views/ai/utils/utils'
14881
import {
14982
AiPlatformEnum,
150-
ImageHotWords, ImageModelVO, OtherPlatformEnum, TongYiWanXiangModels,
151-
TongYiWanXiangStylePresets
83+
ImageHotWords,
84+
ImageModelVO,
85+
OtherPlatformEnum,
86+
TongYiWanXiangModels
15287
} from '@/views/ai/utils/constants'
15388
15489
const message = useMessage() // 消息弹窗
@@ -160,13 +95,7 @@ const selectHotWord = ref<string>('') // 选中的热词
16095
const prompt = ref<string>('') // 提示词
16196
const width = ref<number>(512) // 图片宽度
16297
const height = ref<number>(512) // 图片高度
163-
const steps = ref<number>(20) // 迭代步数
164-
const seed = ref<number>(42) // 控制生成图像的随机性
165-
const scale = ref<number>(7.5) // 引导系数
166-
const referImageUrl = ref<any>() // 参考图
167-
const stylePreset = ref<string>('-1') // 风格
168-
const stylePresetList = ref<ImageModelVO[]>(TongYiWanXiangStylePresets) // 风格列表
169-
const otherPlatform = ref<string>(AiPlatformEnum.TONG_YI_WAN_XIANG) // 平台
98+
const otherPlatform = ref<string>(AiPlatformEnum.TONG_YI) // 平台
17099
const models = ref<ImageModelVO[]>(TongYiWanXiangModels) // 模型
171100
const model = ref<string>(models.value[0].key) // 模型
172101
@@ -198,16 +127,11 @@ const handleGenerateImage = async () => {
198127
// 发送请求
199128
const form = {
200129
platform: otherPlatform.value,
201-
model: '---', // 1
202-
prompt: prompt.value, // 提示词 1
203-
width: width.value, // 图片宽度 1
204-
height: height.value, // 图片高度 1
130+
model: model.value, // 模型
131+
prompt: prompt.value, // 提示词
132+
width: width.value, // 图片宽度
133+
height: height.value, // 图片高度
205134
options: {
206-
seed: seed.value, // 随机种子 1
207-
steps: steps.value, // 图片生成步数 1
208-
scale: scale.value, // 引导系数 1
209-
stylePreset: stylePreset.value, // 风格
210-
referImage: referImageUrl.value // 参考图
211135
}
212136
} as ImageDrawReqVO
213137
await ImageApi.drawImage(form)
@@ -224,29 +148,22 @@ const settingValues = async (detail: ImageVO) => {
224148
prompt.value = detail.prompt
225149
width.value = detail.width
226150
height.value = detail.height
227-
seed.value = detail.options?.seed
228-
steps.value = detail.options?.steps
229-
scale.value = detail.options?.scale
230-
stylePreset.value = detail.options?.stylePreset
151+
231152
}
232153
233154
/** 平台切换 */
234155
const handlerPlatformChange = async (platform) => {
235156
// 切换平台,切换模型、风格
236-
if (AiPlatformEnum.TONG_YI_WAN_XIANG === platform) {
157+
if (AiPlatformEnum.YI_YAN === platform) {
237158
models.value = TongYiWanXiangModels
238-
stylePresetList.value = TongYiWanXiangStylePresets
239159
} else {
240160
models.value = []
241-
stylePresetList.value = []
242161
}
243162
// 切换平台,默认选择一个风格
244-
if (stylePresetList.value.length > 0) {
163+
if (models.value.length > 0) {
245164
model.value = models.value[0].key
246-
stylePreset.value = stylePresetList.value[0].key
247165
} else {
248166
model.value = ''
249-
stylePreset.value = ''
250167
}
251168
}
252169

src/views/ai/utils/constants.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@ export const AiPlatformEnum = {
2121
STABLE_DIFFUSION: 'StableDiffusion', // Stability AI
2222
MIDJOURNEY: 'Midjourney', // Midjourney
2323
SUNO: 'Suno', // Suno AI
24-
TONG_YI_WAN_XIANG: 'TongYiWanXiang', //// 通义万相
25-
YI_YAN_IMAGE: 'YiYanImage' //// 百度 image
2624
}
2725

2826
export const OtherPlatformEnum:ImageModelVO [] = [
2927
{
30-
key: AiPlatformEnum.TONG_YI_WAN_XIANG,
28+
key: AiPlatformEnum.TONG_YI,
3129
name: '通义万相'
3230
},
3331
{
34-
key: AiPlatformEnum.YI_YAN_IMAGE,
32+
key: AiPlatformEnum.YI_YAN,
3533
name: '百度图片'
3634
}
3735
]
@@ -203,6 +201,7 @@ export const StableDiffusionStylePresets: ImageModelVO[] = [
203201
}
204202
]
205203

204+
// todo @芋艿 这些是通义的风格,看要不要删除
206205
export const TongYiWanXiangStylePresets: ImageModelVO[] = [
207206
{
208207
key: '-1',

0 commit comments

Comments
 (0)