@purpleschool/gptbot 0.12.55 → 0.12.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/commands/canvas/create-canvas.command.js +1 -1
- package/build/helpers/image-generation/calculate-gpt-image-2-price-with-margin.helper.js +84 -0
- package/build/helpers/image-generation/index.js +1 -0
- package/build/models/tools/video/video-job.schema.js +8 -3
- package/commands/canvas/create-canvas.command.ts +1 -1
- package/helpers/image-generation/calculate-gpt-image-2-price-with-margin.helper.ts +136 -0
- package/helpers/image-generation/index.ts +1 -0
- package/models/tools/video/video-job.schema.ts +8 -3
- package/package.json +1 -1
|
@@ -6,7 +6,7 @@ const models_1 = require("../../models");
|
|
|
6
6
|
var CreateCanvasCommand;
|
|
7
7
|
(function (CreateCanvasCommand) {
|
|
8
8
|
CreateCanvasCommand.RequestSchema = zod_1.z.object({
|
|
9
|
-
name: zod_1.z.string().trim().min(1).optional()
|
|
9
|
+
name: zod_1.z.string().trim().min(1).optional(),
|
|
10
10
|
});
|
|
11
11
|
CreateCanvasCommand.ResponseSchema = zod_1.z.object({
|
|
12
12
|
data: models_1.CanvasSchema,
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_TARGET_MARGIN = exports.DEFAULT_STAR_PRICE_USD = exports.GPT_IMAGE_2_DEFAULT_OUTPUT_PRICE_PER_1M_USD = void 0;
|
|
4
|
+
exports.getGptImage2OutputTokensByTier = getGptImage2OutputTokensByTier;
|
|
5
|
+
exports.estimateGptImage2OutputCostUsdFromTokens = estimateGptImage2OutputCostUsdFromTokens;
|
|
6
|
+
exports.applyTargetMargin = applyTargetMargin;
|
|
7
|
+
exports.convertUsdToStarsCeil = convertUsdToStarsCeil;
|
|
8
|
+
exports.calculateGptImage2PriceInStarsFromTokens = calculateGptImage2PriceInStarsFromTokens;
|
|
9
|
+
exports.calculateGptImage2PriceInStarsByTier = calculateGptImage2PriceInStarsByTier;
|
|
10
|
+
exports.GPT_IMAGE_2_DEFAULT_OUTPUT_PRICE_PER_1M_USD = 30;
|
|
11
|
+
exports.DEFAULT_STAR_PRICE_USD = 0.018;
|
|
12
|
+
exports.DEFAULT_TARGET_MARGIN = 0.6;
|
|
13
|
+
const GPT_IMAGE_2_OUTPUT_TOKENS_BY_QUALITY_RATIO_AND_TIER = {
|
|
14
|
+
low: {
|
|
15
|
+
'1:1': { '1K': 196, '2K': 397, '4K': 659 },
|
|
16
|
+
'16:9': { '1K': 106, '2K': 205, '4K': 371 },
|
|
17
|
+
'9:16': { '1K': 106, '2K': 205, '4K': 371 },
|
|
18
|
+
'21:9': { '1K': 90, '2K': 192, '4K': 234 },
|
|
19
|
+
},
|
|
20
|
+
medium: {
|
|
21
|
+
'1:1': { '1K': 1756, '2K': 3568, '4K': 5930 },
|
|
22
|
+
'16:9': { '1K': 947, '2K': 1843, '4K': 3336 },
|
|
23
|
+
'9:16': { '1K': 947, '2K': 1843, '4K': 3336 },
|
|
24
|
+
'21:9': { '1K': 809, '2K': 1724, '4K': 2099 },
|
|
25
|
+
},
|
|
26
|
+
high: {
|
|
27
|
+
'1:1': { '1K': 7024, '2K': 14272, '4K': 23719 },
|
|
28
|
+
'16:9': { '1K': 3787, '2K': 7370, '4K': 13342 },
|
|
29
|
+
'9:16': { '1K': 3787, '2K': 7370, '4K': 13342 },
|
|
30
|
+
'21:9': { '1K': 3159, '2K': 6729, '4K': 8196 },
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
function getGptImage2OutputTokensByTier(params) {
|
|
34
|
+
const { quality, aspectRatio, resolutionTier } = params;
|
|
35
|
+
return GPT_IMAGE_2_OUTPUT_TOKENS_BY_QUALITY_RATIO_AND_TIER[quality][aspectRatio][resolutionTier];
|
|
36
|
+
}
|
|
37
|
+
function estimateGptImage2OutputCostUsdFromTokens(params) {
|
|
38
|
+
const { outputTokens, outputPricePer1MUsd = exports.GPT_IMAGE_2_DEFAULT_OUTPUT_PRICE_PER_1M_USD } = params;
|
|
39
|
+
return (outputTokens / 1000000) * outputPricePer1MUsd;
|
|
40
|
+
}
|
|
41
|
+
function applyTargetMargin(params) {
|
|
42
|
+
const { cost, targetMargin = exports.DEFAULT_TARGET_MARGIN } = params;
|
|
43
|
+
if (targetMargin < 0 || targetMargin >= 1) {
|
|
44
|
+
throw new Error(`targetMargin must be in [0, 1), got ${targetMargin}`);
|
|
45
|
+
}
|
|
46
|
+
return cost / (1 - targetMargin);
|
|
47
|
+
}
|
|
48
|
+
function convertUsdToStarsCeil(params) {
|
|
49
|
+
const { usd, starPriceUsd = exports.DEFAULT_STAR_PRICE_USD } = params;
|
|
50
|
+
if (starPriceUsd <= 0) {
|
|
51
|
+
throw new Error(`starPriceUsd must be > 0, got ${starPriceUsd}`);
|
|
52
|
+
}
|
|
53
|
+
return Math.max(1, Math.ceil(usd / starPriceUsd));
|
|
54
|
+
}
|
|
55
|
+
function calculateGptImage2PriceInStarsFromTokens(params) {
|
|
56
|
+
const costUsd = estimateGptImage2OutputCostUsdFromTokens({
|
|
57
|
+
outputTokens: params.outputTokens,
|
|
58
|
+
outputPricePer1MUsd: params.outputPricePer1MUsd,
|
|
59
|
+
});
|
|
60
|
+
const sellUsd = applyTargetMargin({
|
|
61
|
+
cost: costUsd,
|
|
62
|
+
targetMargin: params.targetMargin,
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
costUsd,
|
|
66
|
+
sellUsd,
|
|
67
|
+
costStars: convertUsdToStarsCeil({ usd: costUsd, starPriceUsd: params.starPriceUsd }),
|
|
68
|
+
sellStars: convertUsdToStarsCeil({ usd: sellUsd, starPriceUsd: params.starPriceUsd }),
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function calculateGptImage2PriceInStarsByTier(params) {
|
|
72
|
+
const outputTokens = getGptImage2OutputTokensByTier({
|
|
73
|
+
quality: params.quality,
|
|
74
|
+
aspectRatio: params.aspectRatio,
|
|
75
|
+
resolutionTier: params.resolutionTier,
|
|
76
|
+
});
|
|
77
|
+
const priced = calculateGptImage2PriceInStarsFromTokens({
|
|
78
|
+
outputTokens,
|
|
79
|
+
outputPricePer1MUsd: params.outputPricePer1MUsd,
|
|
80
|
+
targetMargin: params.targetMargin,
|
|
81
|
+
starPriceUsd: params.starPriceUsd,
|
|
82
|
+
});
|
|
83
|
+
return Object.assign({ outputTokens }, priced);
|
|
84
|
+
}
|
|
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./calculate-image-generation-price.helper"), exports);
|
|
18
|
+
__exportStar(require("./calculate-gpt-image-2-price-with-margin.helper"), exports);
|
|
@@ -6,12 +6,17 @@ const constants_1 = require("../../../constants");
|
|
|
6
6
|
const tool_job_schema_1 = require("../../tool-job.schema");
|
|
7
7
|
exports.VideoJobParamsSchema = zod_1.z.object({
|
|
8
8
|
imageUrls: zod_1.z.string().array().optional(),
|
|
9
|
+
imageIds: zod_1.z.array(zod_1.z.string()).optional(),
|
|
10
|
+
firstFrameUrl: zod_1.z.string().optional(),
|
|
11
|
+
lastFrameUrl: zod_1.z.string().optional(),
|
|
12
|
+
firstFrameId: zod_1.z.string().optional(),
|
|
13
|
+
lastFrameId: zod_1.z.string().optional(),
|
|
9
14
|
duration: zod_1.z.number().optional(),
|
|
10
15
|
aspectRatio: zod_1.z.string().optional(),
|
|
11
|
-
|
|
12
|
-
firstFrameImageId: zod_1.z.string().uuid().optional(),
|
|
13
|
-
lastFrameImageId: zod_1.z.string().uuid().optional(),
|
|
16
|
+
quality: zod_1.z.string().optional(),
|
|
14
17
|
resolution: zod_1.z.string().optional(),
|
|
18
|
+
sound: zod_1.z.boolean().optional(),
|
|
19
|
+
multiShots: zod_1.z.boolean().optional(),
|
|
15
20
|
});
|
|
16
21
|
exports.VideoJobSchema = tool_job_schema_1.ToolJobSchema.extend({
|
|
17
22
|
title: zod_1.z.string(),
|
|
@@ -3,7 +3,7 @@ import { CanvasSchema } from '../../models';
|
|
|
3
3
|
|
|
4
4
|
export namespace CreateCanvasCommand {
|
|
5
5
|
export const RequestSchema = z.object({
|
|
6
|
-
name: z.string().trim().min(1).optional()
|
|
6
|
+
name: z.string().trim().min(1).optional(),
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
export type Request = z.infer<typeof RequestSchema>;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
export type GptImage2Quality = 'low' | 'medium' | 'high';
|
|
2
|
+
export type GptImage2AspectRatio = '1:1' | '16:9' | '9:16' | '21:9';
|
|
3
|
+
export type GptImage2ResolutionTier = '1K' | '2K' | '4K';
|
|
4
|
+
|
|
5
|
+
export const GPT_IMAGE_2_DEFAULT_OUTPUT_PRICE_PER_1M_USD = 30;
|
|
6
|
+
export const DEFAULT_STAR_PRICE_USD = 0.018;
|
|
7
|
+
export const DEFAULT_TARGET_MARGIN = 0.6;
|
|
8
|
+
|
|
9
|
+
const GPT_IMAGE_2_OUTPUT_TOKENS_BY_QUALITY_RATIO_AND_TIER: Record<
|
|
10
|
+
GptImage2Quality,
|
|
11
|
+
Record<GptImage2AspectRatio, Record<GptImage2ResolutionTier, number>>
|
|
12
|
+
> = {
|
|
13
|
+
low: {
|
|
14
|
+
'1:1': { '1K': 196, '2K': 397, '4K': 659 },
|
|
15
|
+
'16:9': { '1K': 106, '2K': 205, '4K': 371 },
|
|
16
|
+
'9:16': { '1K': 106, '2K': 205, '4K': 371 },
|
|
17
|
+
'21:9': { '1K': 90, '2K': 192, '4K': 234 },
|
|
18
|
+
},
|
|
19
|
+
medium: {
|
|
20
|
+
'1:1': { '1K': 1756, '2K': 3568, '4K': 5930 },
|
|
21
|
+
'16:9': { '1K': 947, '2K': 1843, '4K': 3336 },
|
|
22
|
+
'9:16': { '1K': 947, '2K': 1843, '4K': 3336 },
|
|
23
|
+
'21:9': { '1K': 809, '2K': 1724, '4K': 2099 },
|
|
24
|
+
},
|
|
25
|
+
high: {
|
|
26
|
+
'1:1': { '1K': 7024, '2K': 14272, '4K': 23719 },
|
|
27
|
+
'16:9': { '1K': 3787, '2K': 7370, '4K': 13342 },
|
|
28
|
+
'9:16': { '1K': 3787, '2K': 7370, '4K': 13342 },
|
|
29
|
+
'21:9': { '1K': 3159, '2K': 6729, '4K': 8196 },
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export function getGptImage2OutputTokensByTier(params: {
|
|
34
|
+
quality: GptImage2Quality;
|
|
35
|
+
aspectRatio: GptImage2AspectRatio;
|
|
36
|
+
resolutionTier: GptImage2ResolutionTier;
|
|
37
|
+
}): number {
|
|
38
|
+
const { quality, aspectRatio, resolutionTier } = params;
|
|
39
|
+
return GPT_IMAGE_2_OUTPUT_TOKENS_BY_QUALITY_RATIO_AND_TIER[quality][aspectRatio][
|
|
40
|
+
resolutionTier
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function estimateGptImage2OutputCostUsdFromTokens(params: {
|
|
45
|
+
outputTokens: number;
|
|
46
|
+
outputPricePer1MUsd?: number;
|
|
47
|
+
}): number {
|
|
48
|
+
const { outputTokens, outputPricePer1MUsd = GPT_IMAGE_2_DEFAULT_OUTPUT_PRICE_PER_1M_USD } =
|
|
49
|
+
params;
|
|
50
|
+
|
|
51
|
+
return (outputTokens / 1_000_000) * outputPricePer1MUsd;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function applyTargetMargin(params: {
|
|
55
|
+
cost: number;
|
|
56
|
+
targetMargin?: number;
|
|
57
|
+
}): number {
|
|
58
|
+
const { cost, targetMargin = DEFAULT_TARGET_MARGIN } = params;
|
|
59
|
+
if (targetMargin < 0 || targetMargin >= 1) {
|
|
60
|
+
throw new Error(`targetMargin must be in [0, 1), got ${targetMargin}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return cost / (1 - targetMargin);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function convertUsdToStarsCeil(params: {
|
|
67
|
+
usd: number;
|
|
68
|
+
starPriceUsd?: number;
|
|
69
|
+
}): number {
|
|
70
|
+
const { usd, starPriceUsd = DEFAULT_STAR_PRICE_USD } = params;
|
|
71
|
+
if (starPriceUsd <= 0) {
|
|
72
|
+
throw new Error(`starPriceUsd must be > 0, got ${starPriceUsd}`);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return Math.max(1, Math.ceil(usd / starPriceUsd));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export function calculateGptImage2PriceInStarsFromTokens(params: {
|
|
79
|
+
outputTokens: number;
|
|
80
|
+
outputPricePer1MUsd?: number;
|
|
81
|
+
targetMargin?: number;
|
|
82
|
+
starPriceUsd?: number;
|
|
83
|
+
}): {
|
|
84
|
+
costUsd: number;
|
|
85
|
+
sellUsd: number;
|
|
86
|
+
costStars: number;
|
|
87
|
+
sellStars: number;
|
|
88
|
+
} {
|
|
89
|
+
const costUsd = estimateGptImage2OutputCostUsdFromTokens({
|
|
90
|
+
outputTokens: params.outputTokens,
|
|
91
|
+
outputPricePer1MUsd: params.outputPricePer1MUsd,
|
|
92
|
+
});
|
|
93
|
+
const sellUsd = applyTargetMargin({
|
|
94
|
+
cost: costUsd,
|
|
95
|
+
targetMargin: params.targetMargin,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
costUsd,
|
|
100
|
+
sellUsd,
|
|
101
|
+
costStars: convertUsdToStarsCeil({ usd: costUsd, starPriceUsd: params.starPriceUsd }),
|
|
102
|
+
sellStars: convertUsdToStarsCeil({ usd: sellUsd, starPriceUsd: params.starPriceUsd }),
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function calculateGptImage2PriceInStarsByTier(params: {
|
|
107
|
+
quality: GptImage2Quality;
|
|
108
|
+
aspectRatio: GptImage2AspectRatio;
|
|
109
|
+
resolutionTier: GptImage2ResolutionTier;
|
|
110
|
+
outputPricePer1MUsd?: number;
|
|
111
|
+
targetMargin?: number;
|
|
112
|
+
starPriceUsd?: number;
|
|
113
|
+
}): {
|
|
114
|
+
outputTokens: number;
|
|
115
|
+
costUsd: number;
|
|
116
|
+
sellUsd: number;
|
|
117
|
+
costStars: number;
|
|
118
|
+
sellStars: number;
|
|
119
|
+
} {
|
|
120
|
+
const outputTokens = getGptImage2OutputTokensByTier({
|
|
121
|
+
quality: params.quality,
|
|
122
|
+
aspectRatio: params.aspectRatio,
|
|
123
|
+
resolutionTier: params.resolutionTier,
|
|
124
|
+
});
|
|
125
|
+
const priced = calculateGptImage2PriceInStarsFromTokens({
|
|
126
|
+
outputTokens,
|
|
127
|
+
outputPricePer1MUsd: params.outputPricePer1MUsd,
|
|
128
|
+
targetMargin: params.targetMargin,
|
|
129
|
+
starPriceUsd: params.starPriceUsd,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
outputTokens,
|
|
134
|
+
...priced,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
@@ -4,12 +4,17 @@ import { ToolJobSchema } from '../../tool-job.schema';
|
|
|
4
4
|
|
|
5
5
|
export const VideoJobParamsSchema = z.object({
|
|
6
6
|
imageUrls: z.string().array().optional(),
|
|
7
|
+
imageIds: z.array(z.string()).optional(),
|
|
8
|
+
firstFrameUrl: z.string().optional(),
|
|
9
|
+
lastFrameUrl: z.string().optional(),
|
|
10
|
+
firstFrameId: z.string().optional(),
|
|
11
|
+
lastFrameId: z.string().optional(),
|
|
7
12
|
duration: z.number().optional(),
|
|
8
13
|
aspectRatio: z.string().optional(),
|
|
9
|
-
|
|
10
|
-
firstFrameImageId: z.string().uuid().optional(),
|
|
11
|
-
lastFrameImageId: z.string().uuid().optional(),
|
|
14
|
+
quality: z.string().optional(),
|
|
12
15
|
resolution: z.string().optional(),
|
|
16
|
+
sound: z.boolean().optional(),
|
|
17
|
+
multiShots: z.boolean().optional(),
|
|
13
18
|
});
|
|
14
19
|
|
|
15
20
|
export type VideoJobParams = z.infer<typeof VideoJobParamsSchema>;
|