增加即梦图片5.0和视频2.5的能力
This commit is contained in:
1 parent
542246e4ce
commit
88a4268d40
55 files changed
+1412
-200
No files matched your search
@@ -15,6 +15,8 @@ import {
|
||||
seedanceTokenPriceFenPerMillion
|
||||
} from "@/lib/server/seedance-billing";
|
||||
import { getGenerationJob, updateGenerationJob } from "@/lib/server/data-store";
|
||||
import { SEEDANCE_20_MODEL, SEEDANCE_25_MODEL } from "@/lib/video-settings";
|
||||
import { calculateSeedreamAmountFen, SEEDREAM_50_PRO_MODEL } from "@/lib/server/seedream-billing";
|
||||
import type {
|
||||
BillingAccountConfig,
|
||||
BillingConditionValue,
|
||||
@@ -81,17 +83,34 @@ export async function quoteGenerationCharge(input: BillingGenerationInput): Prom
|
||||
status: "pending",
|
||||
quotaExempt: quotaExempt || undefined
|
||||
};
|
||||
if (input.provider !== "seedance" || input.reqKey !== "doubao-seedance-2-0-260128") {
|
||||
if (input.provider === "seedream" && input.reqKey === SEEDREAM_50_PRO_MODEL) {
|
||||
const referenceImageCount = Math.ceil(Number(parameters.referenceImageCount) || 0);
|
||||
return {
|
||||
...quote,
|
||||
amountFen: calculateSeedreamAmountFen({
|
||||
outputPriceFen: quote.standardUnitPriceFen,
|
||||
referenceImageCount,
|
||||
markupMultiplier: quote.markupMultiplier
|
||||
}),
|
||||
parameters: {
|
||||
...quote.parameters,
|
||||
referenceImageCount,
|
||||
inputReferencePriceFen: Math.max(0, referenceImageCount - 1) * 2
|
||||
}
|
||||
};
|
||||
}
|
||||
if (input.provider !== "seedance" || !isSeedanceBillingModel(input.reqKey)) {
|
||||
return quote;
|
||||
}
|
||||
|
||||
const inputVideo = requestHasInputVideo(input.requestPayload);
|
||||
const estimatedAmountFen = estimateSeedanceAmountFen({
|
||||
model: input.reqKey,
|
||||
resolution: parameters.resolution,
|
||||
aspectRatio: parameters.aspectRatio,
|
||||
outputDurationSeconds: quantity,
|
||||
inputVideo,
|
||||
inputVideoDurationSeconds: requestInputVideoDurationSeconds(input.requestPayload),
|
||||
inputVideoDurationSeconds: requestInputVideoDurationSeconds(input.requestPayload, input.reqKey),
|
||||
markupMultiplier: quote.markupMultiplier
|
||||
});
|
||||
const reservedAmountFen = Math.max(quote.amountFen, estimatedAmountFen);
|
||||
@@ -202,6 +221,7 @@ export async function settleSeedanceGenerationCharge(
|
||||
const inputVideo = requestHasInputVideo(job.requestPayload);
|
||||
const resolution = billing.parameters?.resolution;
|
||||
const actualAmountFen = calculateSeedanceActualAmountFen({
|
||||
model: job.reqKey,
|
||||
resolution,
|
||||
inputVideo,
|
||||
completionTokens: Number(completionTokens),
|
||||
@@ -226,7 +246,8 @@ export async function settleSeedanceGenerationCharge(
|
||||
actualAmountFen,
|
||||
completionTokens: Math.floor(Number(completionTokens)),
|
||||
inputVideo,
|
||||
resolution: String(resolution || "720p")
|
||||
resolution: String(resolution || "720p"),
|
||||
model: job.reqKey
|
||||
}
|
||||
});
|
||||
settlementLedgerEntryId = settlement.entry.id;
|
||||
@@ -244,12 +265,17 @@ export async function settleSeedanceGenerationCharge(
|
||||
completionTokens: Math.floor(Number(completionTokens)),
|
||||
resolution: String(resolution || "720p"),
|
||||
inputVideo,
|
||||
tokenPriceFenPerMillion: seedanceTokenPriceFenPerMillion(resolution, inputVideo)
|
||||
model: job.reqKey,
|
||||
tokenPriceFenPerMillion: seedanceTokenPriceFenPerMillion(job.reqKey, resolution, inputVideo)
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function isSeedanceBillingModel(model: string) {
|
||||
return model === SEEDANCE_20_MODEL || model === SEEDANCE_25_MODEL;
|
||||
}
|
||||
|
||||
export async function getOrganizationBillingSnapshot(organizationId: string) {
|
||||
const wallet = await getOrganizationWallet(organizationId);
|
||||
return {
|
||||
@@ -385,6 +411,7 @@ export function normalizeBillingParameters(requestPayload: Record<string, unknow
|
||||
input?.resolution
|
||||
), normalizeTextParameter);
|
||||
setParameter(parameters, "size", firstValue(
|
||||
settings?.size,
|
||||
providerPayload?.size,
|
||||
providerParameters?.size,
|
||||
inputSettings?.size,
|
||||
@@ -423,6 +450,7 @@ export function normalizeBillingParameters(requestPayload: Record<string, unknow
|
||||
), numberParameter);
|
||||
|
||||
const imageCount = numberParameter(firstValue(
|
||||
settings?.imageCount,
|
||||
providerPayload?.n,
|
||||
providerParameters?.n,
|
||||
input?.n,
|
||||
@@ -526,11 +554,14 @@ function countReferenceImages(input: {
|
||||
assembled?: Record<string, unknown>;
|
||||
}): number {
|
||||
const urls = [
|
||||
...stringArray(input.requestPayload.imageUrls),
|
||||
...stringArray(input.requestPayload.inputUrls),
|
||||
...stringArray(input.input?.imageUrls),
|
||||
...stringArray(input.providerPayload?.image_urls),
|
||||
...stringArray(input.providerPayload?.imageUrls)
|
||||
];
|
||||
const materials = [
|
||||
...(Array.isArray(input.requestPayload.materials) ? input.requestPayload.materials : []),
|
||||
...(Array.isArray(input.input?.materials) ? input.input.materials : []),
|
||||
...(Array.isArray(input.assembled?.materials) ? input.assembled.materials : [])
|
||||
];
|
||||
|
||||
Reference in new issue
Block a user