@purpleschool/gptbot 0.19.15-stage-2 → 0.19.16
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/ai-studio/canvas-node/find-canvas-node-definitions-with-configs.query.d.ts +1 -0
- package/build/commands/photo-studio/get-photo-studio-config.query.d.ts +2 -0
- package/build/commands/tools/image-editor/get-image-editor-tool-config.command.d.ts +1 -0
- package/build/helpers/image-editor/calculate-image-editor-price.helper.d.ts +2 -1
- package/build/helpers/image-editor/calculate-image-editor-price.helper.js +4 -1
- package/build/helpers/image-generation/calculate-image-generation-price.helper.d.ts +4 -3
- package/build/helpers/image-generation/calculate-image-generation-price.helper.js +3 -5
- package/build/helpers/image-generation/index.d.ts +0 -1
- package/build/helpers/image-generation/index.js +0 -1
- package/build/models/canvas-node-definition.schema.d.ts +3 -0
- package/build/models/tools/image-editor/image-editor-config.schema.d.ts +1 -0
- package/build/models/tools/image-editor/image-editor-model.schema.d.ts +3 -0
- package/build/models/tools/image-editor/image-editor-model.schema.js +1 -0
- package/package.json +1 -1
- package/build/helpers/image-generation/calculate-gpt-image-2-price-with-margin.helper.d.ts +0 -62
- package/build/helpers/image-generation/calculate-gpt-image-2-price-with-margin.helper.js +0 -137
package/build/commands/ai-studio/canvas-node/find-canvas-node-definitions-with-configs.query.d.ts
CHANGED
|
@@ -229,6 +229,7 @@ export declare namespace FindCanvasNodeDefinitionsWithConfigsQuery {
|
|
|
229
229
|
condition: z.ZodObject<{
|
|
230
230
|
withoutSub: z.ZodOptional<z.ZodBoolean>;
|
|
231
231
|
resolution: z.ZodOptional<z.ZodString>;
|
|
232
|
+
perAttachedImage: z.ZodOptional<z.ZodBoolean>;
|
|
232
233
|
}, z.core.$strip>;
|
|
233
234
|
value: z.ZodNumber;
|
|
234
235
|
}, z.core.$strip>>;
|
|
@@ -100,6 +100,7 @@ export declare namespace GetPhotoStudioConfigQuery {
|
|
|
100
100
|
condition: z.ZodObject<{
|
|
101
101
|
withoutSub: z.ZodOptional<z.ZodBoolean>;
|
|
102
102
|
resolution: z.ZodOptional<z.ZodString>;
|
|
103
|
+
perAttachedImage: z.ZodOptional<z.ZodBoolean>;
|
|
103
104
|
}, z.core.$strip>;
|
|
104
105
|
value: z.ZodNumber;
|
|
105
106
|
}, z.core.$strip>>;
|
|
@@ -249,6 +250,7 @@ export declare namespace GetPhotoStudioConfigQuery {
|
|
|
249
250
|
condition: z.ZodObject<{
|
|
250
251
|
withoutSub: z.ZodOptional<z.ZodBoolean>;
|
|
251
252
|
resolution: z.ZodOptional<z.ZodString>;
|
|
253
|
+
perAttachedImage: z.ZodOptional<z.ZodBoolean>;
|
|
252
254
|
}, z.core.$strip>;
|
|
253
255
|
value: z.ZodNumber;
|
|
254
256
|
}, z.core.$strip>>;
|
|
@@ -39,6 +39,7 @@ export declare namespace GetImageEditorToolConfigCommand {
|
|
|
39
39
|
condition: z.ZodObject<{
|
|
40
40
|
withoutSub: z.ZodOptional<z.ZodBoolean>;
|
|
41
41
|
resolution: z.ZodOptional<z.ZodString>;
|
|
42
|
+
perAttachedImage: z.ZodOptional<z.ZodBoolean>;
|
|
42
43
|
}, z.core.$strip>;
|
|
43
44
|
value: z.ZodNumber;
|
|
44
45
|
}, z.core.$strip>>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ImageEditorModelPricingRules } from '../../models';
|
|
2
|
-
export declare function calculateImageEditorPrice({ basePrice, userHasActiveSubscriptionOrProduct, resolution, rules, }: {
|
|
2
|
+
export declare function calculateImageEditorPrice({ basePrice, userHasActiveSubscriptionOrProduct, resolution, attachedFilesCount, rules, }: {
|
|
3
3
|
basePrice: number;
|
|
4
4
|
userHasActiveSubscriptionOrProduct: boolean;
|
|
5
5
|
resolution?: string;
|
|
6
|
+
attachedFilesCount?: number;
|
|
6
7
|
rules: ImageEditorModelPricingRules;
|
|
7
8
|
}): number;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateImageEditorPrice = calculateImageEditorPrice;
|
|
4
|
-
function calculateImageEditorPrice({ basePrice, userHasActiveSubscriptionOrProduct, resolution, rules, }) {
|
|
4
|
+
function calculateImageEditorPrice({ basePrice, userHasActiveSubscriptionOrProduct, resolution, attachedFilesCount = 0, rules, }) {
|
|
5
5
|
let price = basePrice;
|
|
6
6
|
for (const rule of rules !== null && rules !== void 0 ? rules : []) {
|
|
7
7
|
const condition = rule.condition;
|
|
@@ -11,6 +11,9 @@ function calculateImageEditorPrice({ basePrice, userHasActiveSubscriptionOrProdu
|
|
|
11
11
|
if (condition.resolution && condition.resolution === resolution) {
|
|
12
12
|
price += rule.value;
|
|
13
13
|
}
|
|
14
|
+
if (condition.perAttachedImage) {
|
|
15
|
+
price += rule.value * attachedFilesCount;
|
|
16
|
+
}
|
|
14
17
|
}
|
|
15
18
|
return price;
|
|
16
19
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function calculateImageGenerationPrice({ basePrice,
|
|
1
|
+
import { ImageModelPricingRules } from '../../models';
|
|
2
|
+
export declare function calculateImageGenerationPrice({ basePrice, resolution, attachedFilesCount, userHasActiveSubscriptionOrProduct, rules, }: {
|
|
3
3
|
basePrice: number;
|
|
4
|
-
|
|
4
|
+
resolution?: string;
|
|
5
|
+
attachedFilesCount?: number;
|
|
5
6
|
userHasActiveSubscriptionOrProduct: boolean;
|
|
6
7
|
rules: ImageModelPricingRules;
|
|
7
8
|
}): number;
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateImageGenerationPrice = calculateImageGenerationPrice;
|
|
4
|
-
function calculateImageGenerationPrice({ basePrice,
|
|
5
|
-
var _a;
|
|
6
|
-
var _b;
|
|
4
|
+
function calculateImageGenerationPrice({ basePrice, resolution, attachedFilesCount = 0, userHasActiveSubscriptionOrProduct, rules, }) {
|
|
7
5
|
let price = basePrice;
|
|
8
6
|
for (const rule of rules !== null && rules !== void 0 ? rules : []) {
|
|
9
7
|
const condition = rule.condition;
|
|
10
|
-
if (condition.resolution && condition.resolution ===
|
|
8
|
+
if (condition.resolution && condition.resolution === resolution) {
|
|
11
9
|
price += rule.value;
|
|
12
10
|
}
|
|
13
11
|
if (condition.withoutSub && userHasActiveSubscriptionOrProduct === false) {
|
|
14
12
|
price += rule.value;
|
|
15
13
|
}
|
|
16
14
|
if (condition.perAttachedImage) {
|
|
17
|
-
price += rule.value *
|
|
15
|
+
price += rule.value * attachedFilesCount;
|
|
18
16
|
}
|
|
19
17
|
}
|
|
20
18
|
return price;
|
|
@@ -15,4 +15,3 @@ 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);
|
|
@@ -438,6 +438,7 @@ export declare const CanvasNodeDefinitionToolConfigSchema: z.ZodDiscriminatedUni
|
|
|
438
438
|
condition: z.ZodObject<{
|
|
439
439
|
withoutSub: z.ZodOptional<z.ZodBoolean>;
|
|
440
440
|
resolution: z.ZodOptional<z.ZodString>;
|
|
441
|
+
perAttachedImage: z.ZodOptional<z.ZodBoolean>;
|
|
441
442
|
}, z.core.$strip>;
|
|
442
443
|
value: z.ZodNumber;
|
|
443
444
|
}, z.core.$strip>>;
|
|
@@ -1312,6 +1313,7 @@ export declare const CanvasNodeDefinitionWithConfigSchema: z.ZodObject<{
|
|
|
1312
1313
|
condition: z.ZodObject<{
|
|
1313
1314
|
withoutSub: z.ZodOptional<z.ZodBoolean>;
|
|
1314
1315
|
resolution: z.ZodOptional<z.ZodString>;
|
|
1316
|
+
perAttachedImage: z.ZodOptional<z.ZodBoolean>;
|
|
1315
1317
|
}, z.core.$strip>;
|
|
1316
1318
|
value: z.ZodNumber;
|
|
1317
1319
|
}, z.core.$strip>>;
|
|
@@ -2144,6 +2146,7 @@ export declare const CanvasNodeDefinitionsWithConfigsSchema: z.ZodRecord<z.ZodEn
|
|
|
2144
2146
|
condition: z.ZodObject<{
|
|
2145
2147
|
withoutSub: z.ZodOptional<z.ZodBoolean>;
|
|
2146
2148
|
resolution: z.ZodOptional<z.ZodString>;
|
|
2149
|
+
perAttachedImage: z.ZodOptional<z.ZodBoolean>;
|
|
2147
2150
|
}, z.core.$strip>;
|
|
2148
2151
|
value: z.ZodNumber;
|
|
2149
2152
|
}, z.core.$strip>>;
|
|
@@ -99,6 +99,7 @@ export declare const ImageEditorConfigSchema: z.ZodObject<{
|
|
|
99
99
|
condition: z.ZodObject<{
|
|
100
100
|
withoutSub: z.ZodOptional<z.ZodBoolean>;
|
|
101
101
|
resolution: z.ZodOptional<z.ZodString>;
|
|
102
|
+
perAttachedImage: z.ZodOptional<z.ZodBoolean>;
|
|
102
103
|
}, z.core.$strip>;
|
|
103
104
|
value: z.ZodNumber;
|
|
104
105
|
}, z.core.$strip>>;
|
|
@@ -17,12 +17,14 @@ export type ImageEditorModelParams = z.infer<typeof ImageEditorModelParamsSchema
|
|
|
17
17
|
export declare const ImageEditorModelPricingRuleConditionSchema: z.ZodObject<{
|
|
18
18
|
withoutSub: z.ZodOptional<z.ZodBoolean>;
|
|
19
19
|
resolution: z.ZodOptional<z.ZodString>;
|
|
20
|
+
perAttachedImage: z.ZodOptional<z.ZodBoolean>;
|
|
20
21
|
}, z.core.$strip>;
|
|
21
22
|
export type ImageEditorModelPricingRuleCondition = z.infer<typeof ImageEditorModelPricingRuleConditionSchema>;
|
|
22
23
|
export declare const ImageEditorModelPricingRulesSchema: z.ZodArray<z.ZodObject<{
|
|
23
24
|
condition: z.ZodObject<{
|
|
24
25
|
withoutSub: z.ZodOptional<z.ZodBoolean>;
|
|
25
26
|
resolution: z.ZodOptional<z.ZodString>;
|
|
27
|
+
perAttachedImage: z.ZodOptional<z.ZodBoolean>;
|
|
26
28
|
}, z.core.$strip>;
|
|
27
29
|
value: z.ZodNumber;
|
|
28
30
|
}, z.core.$strip>>;
|
|
@@ -64,6 +66,7 @@ export declare const ImageEditorModelSchema: z.ZodObject<{
|
|
|
64
66
|
condition: z.ZodObject<{
|
|
65
67
|
withoutSub: z.ZodOptional<z.ZodBoolean>;
|
|
66
68
|
resolution: z.ZodOptional<z.ZodString>;
|
|
69
|
+
perAttachedImage: z.ZodOptional<z.ZodBoolean>;
|
|
67
70
|
}, z.core.$strip>;
|
|
68
71
|
value: z.ZodNumber;
|
|
69
72
|
}, z.core.$strip>>;
|
|
@@ -28,6 +28,7 @@ exports.ImageEditorModelParamsSchema = zod_1.z.object({
|
|
|
28
28
|
exports.ImageEditorModelPricingRuleConditionSchema = zod_1.z.object({
|
|
29
29
|
withoutSub: zod_1.z.boolean().optional(),
|
|
30
30
|
resolution: zod_1.z.string().optional(),
|
|
31
|
+
perAttachedImage: zod_1.z.boolean().optional(),
|
|
31
32
|
});
|
|
32
33
|
exports.ImageEditorModelPricingRulesSchema = zod_1.z.array(zod_1.z.object({
|
|
33
34
|
condition: exports.ImageEditorModelPricingRuleConditionSchema,
|
package/package.json
CHANGED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { ImageModelPricingRules } from '../../models';
|
|
2
|
-
export type GptImage2Quality = 'low' | 'medium' | 'high';
|
|
3
|
-
export type GptImage2AspectRatio = '1:1' | '4:3' | '5:4' | '16:9' | '21:9' | '3:4' | '4:5' | '9:16' | '9:21';
|
|
4
|
-
export type GptImage2ResolutionTier = '1K' | '2K' | '4K';
|
|
5
|
-
export type GptImage2Size = {
|
|
6
|
-
width: number;
|
|
7
|
-
height: number;
|
|
8
|
-
};
|
|
9
|
-
export declare const GPT_IMAGE_2_DEFAULT_OUTPUT_PRICE_PER_1M_USD = 30;
|
|
10
|
-
export declare const DEFAULT_STAR_PRICE_USD = 0.018;
|
|
11
|
-
export declare const DEFAULT_TARGET_MARGIN = 0.6;
|
|
12
|
-
export declare const GPT_IMAGE_2_INPUT_IMAGE_SURCHARGE_STARS = 2;
|
|
13
|
-
export declare function getGptImage2OutputTokensByTier(params: {
|
|
14
|
-
quality: GptImage2Quality;
|
|
15
|
-
aspectRatio: GptImage2AspectRatio;
|
|
16
|
-
resolutionTier: GptImage2ResolutionTier;
|
|
17
|
-
}): number;
|
|
18
|
-
export declare function normalizeGptImage2SizeToOpenAILimits(size: GptImage2Size): GptImage2Size;
|
|
19
|
-
export declare function calculateGptImage2OutputTokensFromSize(params: {
|
|
20
|
-
quality: GptImage2Quality;
|
|
21
|
-
width: number;
|
|
22
|
-
height: number;
|
|
23
|
-
}): number;
|
|
24
|
-
export declare function estimateGptImage2OutputCostUsdFromTokens(params: {
|
|
25
|
-
outputTokens: number;
|
|
26
|
-
outputPricePer1MUsd?: number;
|
|
27
|
-
}): number;
|
|
28
|
-
export declare function applyTargetMargin(params: {
|
|
29
|
-
cost: number;
|
|
30
|
-
targetMargin?: number;
|
|
31
|
-
}): number;
|
|
32
|
-
export declare function convertUsdToStarsCeil(params: {
|
|
33
|
-
usd: number;
|
|
34
|
-
starPriceUsd?: number;
|
|
35
|
-
}): number;
|
|
36
|
-
export declare function calculateGptImage2PriceInStarsFromTokens(params: {
|
|
37
|
-
outputTokens: number;
|
|
38
|
-
hasAttachedImage?: boolean;
|
|
39
|
-
outputPricePer1MUsd?: number;
|
|
40
|
-
targetMargin?: number;
|
|
41
|
-
starPriceUsd?: number;
|
|
42
|
-
}): {
|
|
43
|
-
costUsd: number;
|
|
44
|
-
sellUsd: number;
|
|
45
|
-
costStars: number;
|
|
46
|
-
sellStars: number;
|
|
47
|
-
};
|
|
48
|
-
export declare function calculateGptImage2PriceInStarsByTier(params: {
|
|
49
|
-
quality: GptImage2Quality;
|
|
50
|
-
aspectRatio: GptImage2AspectRatio;
|
|
51
|
-
resolutionTier: GptImage2ResolutionTier;
|
|
52
|
-
hasAttachedImage?: boolean;
|
|
53
|
-
outputPricePer1MUsd?: number;
|
|
54
|
-
targetMargin?: number;
|
|
55
|
-
starPriceUsd?: number;
|
|
56
|
-
}, rules: ImageModelPricingRules, userHasActiveSubscriptionOrProduct: boolean): {
|
|
57
|
-
outputTokens: number;
|
|
58
|
-
costUsd: number;
|
|
59
|
-
sellUsd: number;
|
|
60
|
-
costStars: number;
|
|
61
|
-
sellStars: number;
|
|
62
|
-
};
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GPT_IMAGE_2_INPUT_IMAGE_SURCHARGE_STARS = 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.normalizeGptImage2SizeToOpenAILimits = normalizeGptImage2SizeToOpenAILimits;
|
|
6
|
-
exports.calculateGptImage2OutputTokensFromSize = calculateGptImage2OutputTokensFromSize;
|
|
7
|
-
exports.estimateGptImage2OutputCostUsdFromTokens = estimateGptImage2OutputCostUsdFromTokens;
|
|
8
|
-
exports.applyTargetMargin = applyTargetMargin;
|
|
9
|
-
exports.convertUsdToStarsCeil = convertUsdToStarsCeil;
|
|
10
|
-
exports.calculateGptImage2PriceInStarsFromTokens = calculateGptImage2PriceInStarsFromTokens;
|
|
11
|
-
exports.calculateGptImage2PriceInStarsByTier = calculateGptImage2PriceInStarsByTier;
|
|
12
|
-
exports.GPT_IMAGE_2_DEFAULT_OUTPUT_PRICE_PER_1M_USD = 30;
|
|
13
|
-
exports.DEFAULT_STAR_PRICE_USD = 0.018;
|
|
14
|
-
exports.DEFAULT_TARGET_MARGIN = 0.6;
|
|
15
|
-
exports.GPT_IMAGE_2_INPUT_IMAGE_SURCHARGE_STARS = 2;
|
|
16
|
-
const GPT_IMAGE_2_BASE_SIZE_BY_ASPECT_RATIO = {
|
|
17
|
-
'1:1': { width: 1024, height: 1024 },
|
|
18
|
-
'4:3': { width: 1344, height: 1024 },
|
|
19
|
-
'5:4': { width: 1280, height: 1024 },
|
|
20
|
-
'16:9': { width: 1280, height: 720 },
|
|
21
|
-
'21:9': { width: 1680, height: 720 },
|
|
22
|
-
'3:4': { width: 1024, height: 1344 },
|
|
23
|
-
'4:5': { width: 1024, height: 1280 },
|
|
24
|
-
'9:16': { width: 720, height: 1280 },
|
|
25
|
-
'9:21': { width: 720, height: 1680 },
|
|
26
|
-
};
|
|
27
|
-
const GPT_IMAGE_2_QUALITY_BASE_TOKENS = {
|
|
28
|
-
low: 16,
|
|
29
|
-
medium: 48,
|
|
30
|
-
high: 96,
|
|
31
|
-
};
|
|
32
|
-
const GPT_IMAGE_2_RESOLUTION_MULTIPLIER = {
|
|
33
|
-
'1K': 1,
|
|
34
|
-
'2K': 2,
|
|
35
|
-
'4K': 4,
|
|
36
|
-
};
|
|
37
|
-
const GPT_IMAGE_2_MAX_EDGE = 3840;
|
|
38
|
-
const GPT_IMAGE_2_MAX_PIXEL_BUDGET = 8294400;
|
|
39
|
-
const GPT_IMAGE_2_SIZE_STEP = 16;
|
|
40
|
-
function getGptImage2OutputTokensByTier(params) {
|
|
41
|
-
const { quality, aspectRatio, resolutionTier } = params;
|
|
42
|
-
const baseSize = GPT_IMAGE_2_BASE_SIZE_BY_ASPECT_RATIO[aspectRatio];
|
|
43
|
-
const multiplier = GPT_IMAGE_2_RESOLUTION_MULTIPLIER[resolutionTier];
|
|
44
|
-
const normalizedSize = normalizeGptImage2SizeToOpenAILimits({
|
|
45
|
-
width: Math.round(baseSize.width * multiplier),
|
|
46
|
-
height: Math.round(baseSize.height * multiplier),
|
|
47
|
-
});
|
|
48
|
-
return calculateGptImage2OutputTokensFromSize(Object.assign({ quality }, normalizedSize));
|
|
49
|
-
}
|
|
50
|
-
function normalizeGptImage2SizeToOpenAILimits(size) {
|
|
51
|
-
let scale = 1;
|
|
52
|
-
const longestEdge = Math.max(size.width, size.height);
|
|
53
|
-
if (longestEdge > GPT_IMAGE_2_MAX_EDGE) {
|
|
54
|
-
scale = Math.min(scale, GPT_IMAGE_2_MAX_EDGE / longestEdge);
|
|
55
|
-
}
|
|
56
|
-
const pixelCount = size.width * size.height;
|
|
57
|
-
if (pixelCount > GPT_IMAGE_2_MAX_PIXEL_BUDGET) {
|
|
58
|
-
scale = Math.min(scale, Math.sqrt(GPT_IMAGE_2_MAX_PIXEL_BUDGET / pixelCount));
|
|
59
|
-
}
|
|
60
|
-
const normalizedWidth = Math.floor((size.width * scale) / GPT_IMAGE_2_SIZE_STEP) * GPT_IMAGE_2_SIZE_STEP;
|
|
61
|
-
const normalizedHeight = Math.floor((size.height * scale) / GPT_IMAGE_2_SIZE_STEP) * GPT_IMAGE_2_SIZE_STEP;
|
|
62
|
-
return {
|
|
63
|
-
width: Math.max(GPT_IMAGE_2_SIZE_STEP, normalizedWidth),
|
|
64
|
-
height: Math.max(GPT_IMAGE_2_SIZE_STEP, normalizedHeight),
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
function calculateGptImage2OutputTokensFromSize(params) {
|
|
68
|
-
const { quality, width, height } = params;
|
|
69
|
-
const longestEdge = Math.max(width, height);
|
|
70
|
-
const shortestEdge = Math.min(width, height);
|
|
71
|
-
const qualityBaseTokens = GPT_IMAGE_2_QUALITY_BASE_TOKENS[quality];
|
|
72
|
-
const scaledShortEdgeTokens = Math.round((qualityBaseTokens * shortestEdge) / longestEdge);
|
|
73
|
-
const widthTokens = width >= height ? qualityBaseTokens : scaledShortEdgeTokens;
|
|
74
|
-
const heightTokens = width >= height ? scaledShortEdgeTokens : qualityBaseTokens;
|
|
75
|
-
return Math.ceil((widthTokens * heightTokens * (2000000 + width * height)) / 4000000);
|
|
76
|
-
}
|
|
77
|
-
function estimateGptImage2OutputCostUsdFromTokens(params) {
|
|
78
|
-
const { outputTokens, outputPricePer1MUsd = exports.GPT_IMAGE_2_DEFAULT_OUTPUT_PRICE_PER_1M_USD } = params;
|
|
79
|
-
return (outputTokens / 1000000) * outputPricePer1MUsd;
|
|
80
|
-
}
|
|
81
|
-
function applyTargetMargin(params) {
|
|
82
|
-
const { cost, targetMargin = exports.DEFAULT_TARGET_MARGIN } = params;
|
|
83
|
-
if (targetMargin < 0 || targetMargin >= 1) {
|
|
84
|
-
throw new Error(`targetMargin must be in [0, 1), got ${targetMargin}`);
|
|
85
|
-
}
|
|
86
|
-
return cost / (1 - targetMargin);
|
|
87
|
-
}
|
|
88
|
-
function convertUsdToStarsCeil(params) {
|
|
89
|
-
const { usd, starPriceUsd = exports.DEFAULT_STAR_PRICE_USD } = params;
|
|
90
|
-
if (starPriceUsd <= 0) {
|
|
91
|
-
throw new Error(`starPriceUsd must be > 0, got ${starPriceUsd}`);
|
|
92
|
-
}
|
|
93
|
-
return Math.max(1, Math.ceil(usd / starPriceUsd));
|
|
94
|
-
}
|
|
95
|
-
function calculateGptImage2PriceInStarsFromTokens(params) {
|
|
96
|
-
const costUsd = estimateGptImage2OutputCostUsdFromTokens({
|
|
97
|
-
outputTokens: params.outputTokens,
|
|
98
|
-
outputPricePer1MUsd: params.outputPricePer1MUsd,
|
|
99
|
-
});
|
|
100
|
-
const sellUsd = applyTargetMargin({
|
|
101
|
-
cost: costUsd,
|
|
102
|
-
targetMargin: params.targetMargin,
|
|
103
|
-
});
|
|
104
|
-
const sellStars = convertUsdToStarsCeil({ usd: sellUsd, starPriceUsd: params.starPriceUsd });
|
|
105
|
-
const finalSellStars = sellStars + (params.hasAttachedImage ? exports.GPT_IMAGE_2_INPUT_IMAGE_SURCHARGE_STARS : 0);
|
|
106
|
-
return {
|
|
107
|
-
costUsd,
|
|
108
|
-
sellUsd,
|
|
109
|
-
costStars: convertUsdToStarsCeil({ usd: costUsd, starPriceUsd: params.starPriceUsd }),
|
|
110
|
-
sellStars: finalSellStars,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
function calculateGptImage2PriceInStarsByTier(params, rules, userHasActiveSubscriptionOrProduct) {
|
|
114
|
-
const outputTokens = getGptImage2OutputTokensByTier({
|
|
115
|
-
quality: params.quality,
|
|
116
|
-
aspectRatio: params.aspectRatio,
|
|
117
|
-
resolutionTier: params.resolutionTier,
|
|
118
|
-
});
|
|
119
|
-
const priced = calculateGptImage2PriceInStarsFromTokens({
|
|
120
|
-
outputTokens,
|
|
121
|
-
hasAttachedImage: params.hasAttachedImage,
|
|
122
|
-
outputPricePer1MUsd: params.outputPricePer1MUsd,
|
|
123
|
-
targetMargin: params.targetMargin,
|
|
124
|
-
starPriceUsd: params.starPriceUsd,
|
|
125
|
-
});
|
|
126
|
-
let finalSellStars = priced.sellStars;
|
|
127
|
-
for (const rule of rules !== null && rules !== void 0 ? rules : []) {
|
|
128
|
-
const condition = rule.condition;
|
|
129
|
-
if (condition.withoutSub && userHasActiveSubscriptionOrProduct === false) {
|
|
130
|
-
finalSellStars += rule.value;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (params.quality === 'low') {
|
|
134
|
-
finalSellStars += 2;
|
|
135
|
-
}
|
|
136
|
-
return Object.assign(Object.assign({ outputTokens }, priced), { sellStars: finalSellStars });
|
|
137
|
-
}
|