fix(world): align vip98k world task mode support
This commit is contained in:
parent
a9a9f8e138
commit
fd49843c5a
@ -142,14 +142,14 @@ function shouldUseExternalTaskCreateApi(
|
|||||||
config: Awaited<ReturnType<typeof getWorldLabsProviderConfig>>,
|
config: Awaited<ReturnType<typeof getWorldLabsProviderConfig>>,
|
||||||
mode: WorldTaskMode
|
mode: WorldTaskMode
|
||||||
) {
|
) {
|
||||||
return isWorldLabsExternalTaskApi(config.baseUrl) && mode === "text";
|
return isWorldLabsExternalTaskApi(config.baseUrl) && mode === "image";
|
||||||
}
|
}
|
||||||
|
|
||||||
function isWorldLabsModeUnsupportedByExternalProvider(
|
function isWorldLabsModeUnsupportedByExternalProvider(
|
||||||
config: Awaited<ReturnType<typeof getWorldLabsProviderConfig>>,
|
config: Awaited<ReturnType<typeof getWorldLabsProviderConfig>>,
|
||||||
mode: WorldTaskMode
|
mode: WorldTaskMode
|
||||||
) {
|
) {
|
||||||
return isWorldLabsExternalTaskApi(config.baseUrl) && mode !== "text";
|
return isWorldLabsExternalTaskApi(config.baseUrl) && mode !== "image";
|
||||||
}
|
}
|
||||||
|
|
||||||
function assertWorldModeSupportedByCandidate(
|
function assertWorldModeSupportedByCandidate(
|
||||||
@ -160,7 +160,7 @@ function assertWorldModeSupportedByCandidate(
|
|||||||
const normalizedBaseUrl = String(config.baseUrl || "").trim() || "未知服务地址";
|
const normalizedBaseUrl = String(config.baseUrl || "").trim() || "未知服务地址";
|
||||||
const normalizedMode = String(mode || "").trim() || "未知模式";
|
const normalizedMode = String(mode || "").trim() || "未知模式";
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`${normalizedBaseUrl} 的 world-generation 当前仅支持文生世界(text)。当前提交的是 ${normalizedMode},请先切换供应商或使用文生世界。`
|
`${normalizedBaseUrl} 的 world-generation 当前仅支持图生世界(image)。当前提交的是 ${normalizedMode},请先切换供应商或使用图生世界。`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,6 +173,33 @@ function resolveOfficialMarbleModel(model?: string | null) {
|
|||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildExternalWorldTaskPayload(
|
||||||
|
mode: WorldTaskMode,
|
||||||
|
worldPrompt: Record<string, unknown>,
|
||||||
|
prompt: string | null,
|
||||||
|
displayName: string,
|
||||||
|
) {
|
||||||
|
const normalizedPrompt = readOptionalTrimmedText(prompt);
|
||||||
|
if (!normalizedPrompt && mode === "text") {
|
||||||
|
throw new Error("请输入世界描述");
|
||||||
|
}
|
||||||
|
const payload: Record<string, unknown> = {
|
||||||
|
model: WORLDLABS_EXTERNAL_TASK_MODEL,
|
||||||
|
displayName,
|
||||||
|
};
|
||||||
|
if (normalizedPrompt) {
|
||||||
|
payload.prompt = normalizedPrompt;
|
||||||
|
} else if (mode !== "text") {
|
||||||
|
payload.prompt = "图生世界";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode === "image" || mode === "multi-image") {
|
||||||
|
payload.world_prompt = worldPrompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
function buildWorldPrompt(body: CreateWorldTaskRequest, mode: WorldTaskMode) {
|
function buildWorldPrompt(body: CreateWorldTaskRequest, mode: WorldTaskMode) {
|
||||||
const textPrompt = readOptionalTrimmedText(body.prompt);
|
const textPrompt = readOptionalTrimmedText(body.prompt);
|
||||||
|
|
||||||
@ -378,21 +405,19 @@ export async function POST(request: Request) {
|
|||||||
const useExternalTaskApi = shouldUseExternalTaskCreateApi(candidate, mode);
|
const useExternalTaskApi = shouldUseExternalTaskCreateApi(candidate, mode);
|
||||||
assertWorldModeSupportedByCandidate(candidate, mode);
|
assertWorldModeSupportedByCandidate(candidate, mode);
|
||||||
if (useExternalTaskApi) {
|
if (useExternalTaskApi) {
|
||||||
const prompt = readOptionalTrimmedText(body.prompt);
|
const payload = buildExternalWorldTaskPayload(
|
||||||
if (!prompt) {
|
mode,
|
||||||
throw new Error("请输入世界描述");
|
worldPrompt,
|
||||||
}
|
readOptionalTrimmedText(body.prompt),
|
||||||
|
displayName,
|
||||||
|
);
|
||||||
const externalResult = await worldLabsRequest<
|
const externalResult = await worldLabsRequest<
|
||||||
WorldLabsExternalTaskResponse<WorldLabsExternalTaskCreateData>
|
WorldLabsExternalTaskResponse<WorldLabsExternalTaskCreateData>
|
||||||
>(candidate, {
|
>(candidate, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
path: "/api/external/task/generate",
|
path: "/api/external/task/generate",
|
||||||
timeoutMs: resolveWorldLabsCreateTimeoutMs(),
|
timeoutMs: resolveWorldLabsCreateTimeoutMs(),
|
||||||
json: {
|
json: payload,
|
||||||
model: WORLDLABS_EXTERNAL_TASK_MODEL,
|
|
||||||
displayName,
|
|
||||||
prompt,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
result = normalizeExternalTaskCreateOperation(externalResult);
|
result = normalizeExternalTaskCreateOperation(externalResult);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user