Add sora duration support (#282)
This commit is contained in:
1 parent
c371ea794c
commit
fee415e490
5 files changed
+40
-65
No files matched your search
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"type": "patch",
|
||||||
|
"comment": "change duration limit",
|
||||||
|
"packageName": "@acedatacloud/nexior",
|
||||||
|
"email": "cqc@cuiqingcai.com",
|
||||||
|
"dependentChangeType": "patch"
|
||||||
|
}
|
||||||
@@ -2,18 +2,17 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<h2 class="title font-bold">{{ $t('sora.name.duration') }}</h2>
|
<h2 class="title font-bold">{{ $t('sora.name.duration') }}</h2>
|
||||||
<el-select v-model="value" class="value" :placeholder="$t('sora.placeholder.select')" :disabled="isLocked">
|
<el-select v-model="value" class="value" :placeholder="$t('sora.placeholder.select')">
|
||||||
<el-option v-for="item in optionsForModel" :key="item.value" :label="item.label" :value="item.value" />
|
<el-option v-for="item in optionsForModel" :key="item.value" :label="item.label" :value="item.value" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="isLocked" class="hint">{{ $t('sora.tip.proOnly') }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { ElSelect, ElOption } from 'element-plus';
|
import { ElSelect, ElOption } from 'element-plus';
|
||||||
import { SORA_ALLOWED_DURATIONS, SORA_DEFAULT_DURATION, SORA_DEFAULT_MODEL, SORA_MODEL_PRO } from '@/constants';
|
import { SORA_ALLOWED_DURATIONS_BY_MODEL, SORA_DEFAULT_DURATION, SORA_DEFAULT_MODEL } from '@/constants';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'DurationSelector',
|
name: 'DurationSelector',
|
||||||
@@ -21,26 +20,18 @@ export default defineComponent({
|
|||||||
ElSelect,
|
ElSelect,
|
||||||
ElOption
|
ElOption
|
||||||
},
|
},
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
options: SORA_ALLOWED_DURATIONS.map((duration) => ({
|
|
||||||
value: duration,
|
|
||||||
label: `${duration}s`
|
|
||||||
}))
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
model(): string {
|
model(): string {
|
||||||
return this.$store.state.sora?.config?.model || SORA_DEFAULT_MODEL;
|
return this.$store.state.sora?.config?.model || SORA_DEFAULT_MODEL;
|
||||||
},
|
},
|
||||||
isLocked(): boolean {
|
allowedDurations(): number[] {
|
||||||
return this.model !== SORA_MODEL_PRO;
|
return SORA_ALLOWED_DURATIONS_BY_MODEL[this.model] || [SORA_DEFAULT_DURATION];
|
||||||
},
|
},
|
||||||
optionsForModel(): Array<{ value: number; label: string }> {
|
optionsForModel(): Array<{ value: number; label: string }> {
|
||||||
if (this.isLocked) {
|
return this.allowedDurations.map((duration) => ({
|
||||||
return this.options.filter((option) => option.value === SORA_DEFAULT_DURATION);
|
value: duration,
|
||||||
}
|
label: `${duration}s`
|
||||||
return this.options;
|
}));
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
get(): number | undefined {
|
get(): number | undefined {
|
||||||
@@ -56,9 +47,11 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
isLocked(newValue: boolean) {
|
allowedDurations() {
|
||||||
if (newValue && this.value !== SORA_DEFAULT_DURATION) {
|
const durations = this.allowedDurations;
|
||||||
this.value = SORA_DEFAULT_DURATION;
|
if (!durations.includes(this.value as number)) {
|
||||||
|
const fallback = durations.includes(SORA_DEFAULT_DURATION) ? SORA_DEFAULT_DURATION : durations[0];
|
||||||
|
this.value = fallback;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -92,10 +85,4 @@ export default defineComponent({
|
|||||||
.value {
|
.value {
|
||||||
width: 120px;
|
width: 120px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hint {
|
|
||||||
margin-top: 4px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--el-text-color-secondary);
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
@@ -11,6 +11,7 @@
|
|||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { ElSelect, ElOption } from 'element-plus';
|
import { ElSelect, ElOption } from 'element-plus';
|
||||||
import {
|
import {
|
||||||
|
SORA_ALLOWED_DURATIONS_BY_MODEL,
|
||||||
SORA_DEFAULT_DURATION,
|
SORA_DEFAULT_DURATION,
|
||||||
SORA_DEFAULT_MODEL,
|
SORA_DEFAULT_MODEL,
|
||||||
SORA_DEFAULT_SIZE,
|
SORA_DEFAULT_SIZE,
|
||||||
@@ -52,19 +53,21 @@ export default defineComponent({
|
|||||||
},
|
},
|
||||||
set(val: string) {
|
set(val: string) {
|
||||||
const currentConfig = this.$store.state.sora?.config || {};
|
const currentConfig = this.$store.state.sora?.config || {};
|
||||||
|
const allowedDurations = SORA_ALLOWED_DURATIONS_BY_MODEL[val] || [SORA_DEFAULT_DURATION];
|
||||||
|
const currentDuration = currentConfig.duration as number | undefined;
|
||||||
|
const resolvedDuration =
|
||||||
|
currentDuration && allowedDurations.includes(currentDuration)
|
||||||
|
? currentDuration
|
||||||
|
: allowedDurations.includes(SORA_DEFAULT_DURATION)
|
||||||
|
? SORA_DEFAULT_DURATION
|
||||||
|
: allowedDurations[0];
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
...currentConfig,
|
...currentConfig,
|
||||||
model: val
|
model: val,
|
||||||
|
duration: resolvedDuration,
|
||||||
|
size: currentConfig.size || SORA_DEFAULT_SIZE
|
||||||
} as Record<string, any>;
|
} as Record<string, any>;
|
||||||
|
|
||||||
if (val === SORA_MODEL_STANDARD) {
|
|
||||||
nextConfig.duration = SORA_DEFAULT_DURATION;
|
|
||||||
nextConfig.size = SORA_DEFAULT_SIZE;
|
|
||||||
} else if (val === SORA_MODEL_PRO) {
|
|
||||||
nextConfig.duration = nextConfig.duration || SORA_DEFAULT_DURATION;
|
|
||||||
nextConfig.size = nextConfig.size || SORA_DEFAULT_SIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.$store.commit('sora/setConfig', nextConfig);
|
this.$store.commit('sora/setConfig', nextConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,18 +2,17 @@
|
|||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="control">
|
<div class="control">
|
||||||
<h2 class="title font-bold">{{ $t('sora.name.size') }}</h2>
|
<h2 class="title font-bold">{{ $t('sora.name.size') }}</h2>
|
||||||
<el-select v-model="value" class="value" :placeholder="$t('sora.placeholder.select')" :disabled="isLocked">
|
<el-select v-model="value" class="value" :placeholder="$t('sora.placeholder.select')">
|
||||||
<el-option v-for="item in optionsForModel" :key="item.value" :label="item.label" :value="item.value" />
|
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
|
||||||
</el-select>
|
</el-select>
|
||||||
</div>
|
</div>
|
||||||
<p v-if="isLocked" class="hint">{{ $t('sora.tip.proOnly') }}</p>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { ElSelect, ElOption } from 'element-plus';
|
import { ElSelect, ElOption } from 'element-plus';
|
||||||
import { SORA_ALLOWED_SIZES, SORA_DEFAULT_MODEL, SORA_DEFAULT_SIZE, SORA_MODEL_PRO } from '@/constants';
|
import { SORA_ALLOWED_SIZES, SORA_DEFAULT_SIZE } from '@/constants';
|
||||||
|
|
||||||
const formatSizeLabel = (value: string): string => {
|
const formatSizeLabel = (value: string): string => {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
@@ -37,18 +36,6 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
model(): string {
|
|
||||||
return this.$store.state.sora?.config?.model || SORA_DEFAULT_MODEL;
|
|
||||||
},
|
|
||||||
isLocked(): boolean {
|
|
||||||
return this.model !== SORA_MODEL_PRO;
|
|
||||||
},
|
|
||||||
optionsForModel(): Array<{ value: string; label: string }> {
|
|
||||||
if (this.isLocked) {
|
|
||||||
return this.options.filter((option) => option.value === SORA_DEFAULT_SIZE);
|
|
||||||
}
|
|
||||||
return this.options;
|
|
||||||
},
|
|
||||||
value: {
|
value: {
|
||||||
get(): string | undefined {
|
get(): string | undefined {
|
||||||
return this.$store.state.sora?.config?.size;
|
return this.$store.state.sora?.config?.size;
|
||||||
@@ -62,13 +49,6 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
|
||||||
isLocked(newValue: boolean) {
|
|
||||||
if (newValue && this.value !== SORA_DEFAULT_SIZE) {
|
|
||||||
this.value = SORA_DEFAULT_SIZE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
mounted() {
|
mounted() {
|
||||||
if (!this.value) {
|
if (!this.value) {
|
||||||
this.value = SORA_DEFAULT_SIZE;
|
this.value = SORA_DEFAULT_SIZE;
|
||||||
@@ -99,10 +79,4 @@ export default defineComponent({
|
|||||||
.value {
|
.value {
|
||||||
width: 120px;
|
width: 120px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.hint {
|
|
||||||
margin-top: 4px;
|
|
||||||
font-size: 12px;
|
|
||||||
color: var(--el-text-color-secondary);
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
@@ -5,10 +5,14 @@ export const SORA_MODEL_PRO = 'sora-2-pro';
|
|||||||
|
|
||||||
export const SORA_DEFAULT_MODEL = SORA_MODEL_STANDARD;
|
export const SORA_DEFAULT_MODEL = SORA_MODEL_STANDARD;
|
||||||
export const SORA_DEFAULT_DURATION = 10;
|
export const SORA_DEFAULT_DURATION = 10;
|
||||||
export const SORA_ALLOWED_DURATIONS = [10, 15];
|
|
||||||
export const SORA_DEFAULT_SIZE = 'small';
|
export const SORA_DEFAULT_SIZE = 'small';
|
||||||
export const SORA_ALLOWED_SIZES = ['small', 'large'];
|
export const SORA_ALLOWED_SIZES = ['small', 'large'];
|
||||||
export const SORA_DEFAULT_ACTION = 'text2video';
|
export const SORA_DEFAULT_ACTION = 'text2video';
|
||||||
export const SORA_DEFAULT_ORIENTATION = 'landscape';
|
export const SORA_DEFAULT_ORIENTATION = 'landscape';
|
||||||
export const SORA_DEFAULT_TRANSLATION = false;
|
export const SORA_DEFAULT_TRANSLATION = false;
|
||||||
export const SORA_DEFAULT_EXTEND_IMG = false;
|
export const SORA_DEFAULT_EXTEND_IMG = false;
|
||||||
|
|
||||||
|
export const SORA_ALLOWED_DURATIONS_BY_MODEL: Record<string, number[]> = {
|
||||||
|
[SORA_MODEL_STANDARD]: [10, 15],
|
||||||
|
[SORA_MODEL_PRO]: [10, 15, 25]
|
||||||
|
};
|
||||||
Reference in new issue
Block a user