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