feat: 集成智谱 CogView-3-Flash 文生图 + CogVideoX-Flash 文生视频

This commit is contained in:
api-gateway committed 2026-09-16 10:11:20 +08:00
1 parent c58b29a06f
commit 403676619e
13 files changed
+278 -49

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@ export function findVideoUrl(obj: any): string {
return ''
}
if (typeof obj === 'object') {
for (const k of ['video_url', 'play_url', 'url', 'html_url', 'video', 'media_url', 'result', 'data', 'mp4']) {
for (const k of ['video_result', 'video_url', 'play_url', 'url', 'html_url', 'video', 'media_url', 'result', 'data', 'mp4']) {
if (k in obj) { const u = findVideoUrl(obj[k]); if (u) return u }
}
for (const v of Object.values(obj)) { const u = findVideoUrl(v); if (u) return u }
+7
View File
@@ -303,6 +303,13 @@ export default {
videos: {
taskTitle: 'Tasks',
fixed: 'Fixed',
zSize: 'Resolution',
zQuality: 'Quality',
zSpeed: 'Speed first',
zQualityHigh: 'Quality first',
zFps: 'FPS',
zAudio: 'Audio',
zTip: 'Zhipu CogVideoX supports text-to-video only (text mode); generation takes a while, please wait.',
title: 'Video generation',
model: 'Video model',
mode: 'Scenario',
+7
View File
@@ -303,6 +303,13 @@ export default {
videos: {
taskTitle: '任务列表',
fixed: '固定',
zSize: '分辨率',
zQuality: '质量',
zSpeed: '速度优先',
zQualityHigh: '质量优先',
zFps: '帧率',
zAudio: '配音',
zTip: '智谱 CogVideoX 仅支持文生视频(text 模式);生成耗时较长,请耐心等待。',
title: '视频生成',
model: '视频模型',
mode: '场景',
+19 -5
View File
@@ -14,10 +14,10 @@
<div class="field">
<label>{{ t('images.size') }}</label>
<el-select v-model="size" class="fill">
<el-option v-for="s in sizes" :key="s" :value="s" :label="s" />
<el-option v-for="s in displaySizes" :key="s" :value="s" :label="s" />
</el-select>
</div>
<div class="field">
<div v-if="!isZhipu" class="field">
<label>{{ t('images.ratio') }}</label>
<el-select v-model="ratio" class="fill">
<el-option v-for="r in ratios" :key="r" :value="r" :label="r" />
@@ -44,7 +44,7 @@
/>
</div>
<div class="field mb-field">
<div v-if="!isZhipu" class="field mb-field">
<label>{{ t('images.refsLabel') }}</label>
<!-- 第十三轮:图生图 / 多图合成 —— 支持直接上传(浏览器内压成 data URI),也支持粘 URL -->
<div class="ref-btns">
@@ -166,8 +166,22 @@ const models = ref<any[]>([])
const model = ref('')
const sizes = ['1K', '2K', '3K', '4K']
const ratios = ['1:1', '3:4', '4:3', '16:9', '9:16', '2:3', '3:2', '21:9']
// 智谱 CogView-3-Flash:文生图,size 用像素档、天然无 ratio、不支持参考图(图生图)
const zhipuSizes = ['1024x1024', '768x1344', '864x1152', '1344x768', '1152x864', '1440x720', '720x1440']
const isZhipu = computed(() => models.value.find((m: any) => m.id === model.value)?.provider === 'bigmodel')
const displaySizes = computed(() => (isZhipu.value ? zhipuSizes : sizes))
const size = ref('1K')
const ratio = ref('1:1')
watch(model, (m) => {
const mo = models.value.find((x: any) => x.id === m)
const z = mo?.provider === 'bigmodel'
if (z) {
if (!zhipuSizes.includes(size.value)) size.value = '1024x1024'
ratio.value = '' // cogview 的宽高由 size 像素档决定,无 ratio
} else if (ratio.value === '') {
ratio.value = '1:1'
}
})
const count = ref(1) // 逐张生成:每张一次请求(上游 n 必须为 1)
const prompt = ref('')
// 参考图(图生图 / 多图合成):上传的走 data URI,URL 的直接透传,两类可混用
@@ -274,8 +288,8 @@ async function generate() {
progress.value = i
const t0 = performance.now()
// 上游图像接口的 n 必须为 1:多张就在这里逐张调用,每张出来就上屏(进度可见)
const body: any = { model: model.value, prompt: prompt.value, size: size.value, ratio: ratio.value, n: 1 }
if (list.length) body.image = list // 图生图 / 多图合成(网关转成上游的 extra_body.image)
const body: any = { model: model.value, prompt: prompt.value, size: size.value, ratio: isZhipu.value ? '' : ratio.value, n: 1 }
if (list.length && !isZhipu.value) body.image = list // 图生图 / 多图合成(网关转成上游的 extra_body.image)
const j = await api('/v1/images/generations', { method: 'POST', body: JSON.stringify(body) })
const ms = (performance.now() - t0) | 0
providerName.value = j.provider_name || j.provider || ''
+69 -17
View File
@@ -10,7 +10,9 @@
</el-select>
</div>
<!-- 第十一轮 #3:场景模式(对齐 Agnes Video 契约 text/keyframe/reference) -->
<!-- 智谱 CogVideoX-Flash / Agnes 两种视频契约:Agnes 用模式+时长+720P;智谱用 quality/fps/audio/像素 size -->
<template v-if="!isZhipu">
<!-- 第十一轮 #3:场景模式(对齐 Agnes Video 契约 text/keyframe/reference) -->
<div class="field mb-field">
<label>{{ t('videos.mode') }}</label>
<div class="modes">
@@ -54,6 +56,39 @@
:placeholder="t('videos.seedPH')" class="fill" />
</div>
</div>
</template>
<!-- 智谱 CogVideoX-Flash:文生视频专用(quality/fps/with_audio/像素 size,固定 text 模式) -->
<template v-else>
<div class="form-row mb-field">
<div class="field">
<label>{{ t('videos.zSize') }}</label>
<el-select v-model="zsize" class="fill">
<el-option v-for="s in zhipuSizes" :key="s" :value="s" :label="s" />
</el-select>
</div>
<div class="field">
<label>{{ t('videos.zQuality') }}</label>
<el-select v-model="zquality" class="fill">
<el-option value="speed" :label="t('videos.zSpeed')" />
<el-option value="quality" :label="t('videos.zQualityHigh')" />
</el-select>
</div>
</div>
<div class="form-row mb-field">
<div class="field">
<label>{{ t('videos.zFps') }}</label>
<el-select v-model="zfps" class="fill">
<el-option :value="30" label="30fps" />
<el-option :value="60" label="60fps" />
</el-select>
</div>
<div class="field">
<label>{{ t('videos.zAudio') }}</label>
<el-switch v-model="zaudio" />
</div>
</div>
<div class="hint tip">{{ t('videos.zTip') }}</div>
</template>
<div class="field mb-field">
<label>{{ t('videos.promptRow') }}</label>
@@ -220,7 +255,7 @@
</template>
<script setup lang="ts">
import { computed, onMounted, onUnmounted, ref } from 'vue'
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'
import { ElMessage, ElMessageBox } from 'element-plus'
@@ -256,6 +291,13 @@ const router = useRouter()
const { t } = useI18n()
const models = ref<any[]>([])
const model = ref('')
// 所选视频模型是否智谱 CogVideoX(文生视频专用表单)
const isZhipu = computed(() => models.value.find((m: any) => m.id === model.value)?.provider === 'bigmodel')
// 切到智谱视频模型时强制 text 文生视频模式(智谱无 keyframe/reference)
watch(model, (m) => {
const mo = models.value.find((x: any) => x.id === m)
if (mo?.provider === 'bigmodel') mode.value = 'text'
})
const prompt = ref('')
const seconds = ref('5')
const aspect = ref('16:9')
@@ -263,6 +305,12 @@ const quality = ref('720P')
const seed = ref<number | null>(null)
// 第十一轮 #3:场景模式与对应素材
const mode = ref<'text' | 'keyframe' | 'reference'>('text')
// 智谱 CogVideoX-Flash:text 文生视频专用参数(quality/fps/with_audio/像素 size)
const zhipuSizes = ['720x480', '1024x1024', '1280x960', '960x1280', '1920x1080', '1080x1920', '2048x1080']
const zsize = ref('1920x1080')
const zquality = ref<'speed' | 'quality'>('speed')
const zfps = ref(30)
const zaudio = ref(true)
const frameEl = ref<HTMLInputElement | null>(null)
const refImgEl = ref<HTMLInputElement | null>(null)
const refAudEl = ref<HTMLInputElement | null>(null)
@@ -466,21 +514,25 @@ async function create() {
const t0 = Date.now()
const summary = mediaSummary()
try {
const body: any = {
model: model.value,
prompt: prompt.value,
seconds: seconds.value,
size: quality.value,
aspect_ratio: aspect.value,
mode: mode.value,
}
if (seed.value != null) body.seed = seed.value
if (mode.value === 'keyframe') {
if (firstFrame.value) body.first_frame = firstFrame.value
if (lastFrame.value) body.last_frame = lastFrame.value
} else if (mode.value === 'reference') {
if (imageList.value.length) body.images = imageList.value
if (audioList.value.length) body.audios = audioList.value
const body: any = { model: model.value, prompt: prompt.value }
if (isZhipu.value) {
// 智谱 CogVideoX-Flash:text 文生视频;quality/fps/with_audio 走 extra(后端透传给上游)
body.size = zsize.value
body.mode = 'text'
body.extra = { quality: zquality.value, fps: zfps.value, with_audio: zaudio.value }
} else {
body.seconds = seconds.value
body.size = quality.value
body.aspect_ratio = aspect.value
body.mode = mode.value
if (seed.value != null) body.seed = seed.value
if (mode.value === 'keyframe') {
if (firstFrame.value) body.first_frame = firstFrame.value
if (lastFrame.value) body.last_frame = lastFrame.value
} else if (mode.value === 'reference') {
if (imageList.value.length) body.images = imageList.value
if (audioList.value.length) body.audios = audioList.value
}
}
if (!stream.value) body.wait = true // 同步等结果
const j = await api('/v1/videos', { method: 'POST', body: JSON.stringify(body) })