86 lines
3.7 KiB
Vue
86 lines
3.7 KiB
Vue
<script setup lang="ts">
|
||
import { onScopeDispose, ref, watch } from 'vue'
|
||
import { NAlert, NButton } from 'naive-ui'
|
||
import { qualityApi } from '../quality-api'
|
||
import type { ImageProviderCapability, ShotProviderCapability } from '../quality.types'
|
||
import { errorMessage } from '../../../lib/http'
|
||
|
||
/** 只读查询指定镜头及本次选择模型的公开能力。 */
|
||
const props = defineProps<{
|
||
/** 当前正式镜头 ID。 */
|
||
shotId?: string
|
||
/** 本次选择的图片模型,未提供时读取后端默认。 */
|
||
provider?: string
|
||
}>()
|
||
const providers = ref<ImageProviderCapability[] | null>(null)
|
||
const capability = ref<ShotProviderCapability | null>(null)
|
||
const error = ref('')
|
||
const loading = ref(false)
|
||
let revision = 0
|
||
onScopeDispose(() => {
|
||
revision++
|
||
})
|
||
/** 切换镜头或本次模型后清除旧能力记录,迟到响应不能覆盖新目标。 */
|
||
watch([() => props.shotId, () => props.provider], () => {
|
||
revision++
|
||
providers.value = null
|
||
capability.value = null
|
||
error.value = ''
|
||
loading.value = false
|
||
})
|
||
/** 按需检查当前模型,不自动生成图片;空上限表示未声明,不冒充无限制。 */
|
||
async function inspect() {
|
||
if (loading.value) return
|
||
const version = ++revision
|
||
const shotId = props.shotId
|
||
const provider = props.provider
|
||
loading.value = true
|
||
error.value = ''
|
||
try {
|
||
const list = await qualityApi.providers()
|
||
if (version !== revision) return
|
||
const result = shotId ? await qualityApi.capability(shotId, undefined, provider) : null
|
||
if (version !== revision) return
|
||
if (!Array.isArray(list) || list.some(item => !item.capabilities?.references))
|
||
throw new Error('模型能力接口返回不完整。')
|
||
providers.value = list
|
||
capability.value = result
|
||
} catch (cause) {
|
||
if (version === revision) error.value = errorMessage(cause)
|
||
} finally {
|
||
if (version === revision) loading.value = false
|
||
}
|
||
}
|
||
</script>
|
||
<template>
|
||
<section class="mt-4 text-xs">
|
||
<NButton size="small" :loading="loading" :disabled="loading" @click="inspect">查看模型限制</NButton>
|
||
<NAlert v-if="error" type="error" :show-icon="false" class="mt-3">{{ error }}</NAlert>
|
||
<template v-if="providers">
|
||
<p v-if="!providers.some(item => item.active)" class="mt-2 text-danger">
|
||
没有匹配的启用图片模型,请检查后端配置。
|
||
</p>
|
||
<p v-for="item in providers" :key="item.provider" class="mt-2">
|
||
{{ item.provider }} · {{ item.active ? '当前启用' : '已注册' }} ·
|
||
{{
|
||
!item.capabilities.references.supported
|
||
? '不支持参考图'
|
||
: item.capabilities.references.maxReferenceImages === null
|
||
? '参考图上限未声明'
|
||
: `最多 ${item.capabilities.references.maxReferenceImages} 张参考图`
|
||
}}
|
||
</p>
|
||
</template>
|
||
<NAlert v-if="capability" :type="capability.valid ? 'info' : 'error'" :show-icon="false" class="mt-3">{{
|
||
capability.valid
|
||
? capability.message ||
|
||
`当前镜头共有 ${capability.referenceCount} 张业务参考图,后端已判定本次规划符合 ${capability.provider} 能力。`
|
||
: capability.message || '当前镜头不满足模型能力限制。'
|
||
}}</NAlert>
|
||
<p v-if="capability?.valid && capability.plannedReferenceCount !== undefined" class="mt-2 text-muted">
|
||
本次计划输入 {{ capability.plannedReferenceCount }} 张 · 转为文字约束
|
||
{{ capability.omittedReferenceCount ?? 0 }} 张
|
||
</p>
|
||
</section>
|
||
</template>
|