@purpleschool/gptbot 0.12.99-stage → 0.13.1-stage

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.
@@ -71,7 +71,7 @@ function calculateGptImage2PriceInStarsFromTokens(params) {
71
71
  sellStars: finalSellStars,
72
72
  };
73
73
  }
74
- function calculateGptImage2PriceInStarsByTier(params) {
74
+ function calculateGptImage2PriceInStarsByTier(params, rules, userHasActiveSubscriptionOrProduct) {
75
75
  const outputTokens = getGptImage2OutputTokensByTier({
76
76
  quality: params.quality,
77
77
  aspectRatio: params.aspectRatio,
@@ -84,5 +84,15 @@ function calculateGptImage2PriceInStarsByTier(params) {
84
84
  targetMargin: params.targetMargin,
85
85
  starPriceUsd: params.starPriceUsd,
86
86
  });
87
- return Object.assign({ outputTokens }, priced);
87
+ let finalSellStars = priced.sellStars;
88
+ for (const rule of rules !== null && rules !== void 0 ? rules : []) {
89
+ const condition = rule.condition;
90
+ if (condition.withoutSub && userHasActiveSubscriptionOrProduct === false) {
91
+ finalSellStars += rule.value;
92
+ }
93
+ }
94
+ if (params.quality === 'low') {
95
+ finalSellStars += 2;
96
+ }
97
+ return Object.assign(Object.assign({ outputTokens }, priced), { sellStars: finalSellStars });
88
98
  }
@@ -1,3 +1,5 @@
1
+ import { ImageModelPricingRules } from '../../models';
2
+
1
3
  export type GptImage2Quality = 'low' | 'medium' | 'high';
2
4
  export type GptImage2AspectRatio = '1:1' | '16:9' | '9:16' | '21:9';
3
5
  export type GptImage2ResolutionTier = '1K' | '2K' | '4K';
@@ -111,7 +113,7 @@ export function calculateGptImage2PriceInStarsByTier(params: {
111
113
  outputPricePer1MUsd?: number;
112
114
  targetMargin?: number;
113
115
  starPriceUsd?: number;
114
- }): {
116
+ }, rules: ImageModelPricingRules, userHasActiveSubscriptionOrProduct: boolean): {
115
117
  outputTokens: number;
116
118
  costUsd: number;
117
119
  sellUsd: number;
@@ -131,8 +133,22 @@ export function calculateGptImage2PriceInStarsByTier(params: {
131
133
  starPriceUsd: params.starPriceUsd,
132
134
  });
133
135
 
136
+ let finalSellStars = priced.sellStars;
137
+
138
+ for (const rule of rules ?? []) {
139
+ const condition = rule.condition;
140
+ if (condition.withoutSub && userHasActiveSubscriptionOrProduct === false) {
141
+ finalSellStars += rule.value;
142
+ }
143
+ }
144
+
145
+ if (params.quality === 'low') {
146
+ finalSellStars += 2;
147
+ }
148
+
134
149
  return {
135
150
  outputTokens,
136
151
  ...priced,
152
+ sellStars: finalSellStars,
137
153
  };
138
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purpleschool/gptbot",
3
- "version": "0.12.99-stage",
3
+ "version": "0.13.1-stage",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",