@common_ch/common 1.0.292 → 1.0.294
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.
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { AiOptionNamesEnum } from "../../enums/ai";
|
|
2
|
-
|
|
2
|
+
import { ToolName } from "./pricingTable";
|
|
3
|
+
export declare function calculateCostChat(model: AiOptionNamesEnum, promptTokens: number, cacheToken: number, completionTokens: number, toolsUsed?: ToolName[]): number;
|
|
@@ -2,12 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.calculateCostChat = calculateCostChat;
|
|
4
4
|
const pricingTable_1 = require("./pricingTable");
|
|
5
|
-
function calculateCostChat(model, promptTokens, cacheToken, completionTokens) {
|
|
5
|
+
function calculateCostChat(model, promptTokens, cacheToken, completionTokens, toolsUsed = []) {
|
|
6
6
|
const pricing = pricingTable_1.pricingTableChat[model];
|
|
7
7
|
if (!pricing)
|
|
8
8
|
throw new Error(`No pricing found for model: ${model}`);
|
|
9
|
-
|
|
9
|
+
let cost = (promptTokens / 1000000) * pricing.prompt +
|
|
10
10
|
(cacheToken / 1000000) * pricing.cache +
|
|
11
11
|
(completionTokens / 1000000) * pricing.completion;
|
|
12
|
-
|
|
12
|
+
let multiplier = 1;
|
|
13
|
+
for (const tool of toolsUsed) {
|
|
14
|
+
if (pricingTable_1.toolOverhead[tool]) {
|
|
15
|
+
multiplier *= pricingTable_1.toolOverhead[tool];
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const finalCost = cost * multiplier;
|
|
19
|
+
return parseFloat(finalCost.toFixed(6));
|
|
13
20
|
}
|
|
@@ -16,4 +16,6 @@ export declare const pricingTableChat: Record<string, ModelPricingChat>;
|
|
|
16
16
|
export declare const pricingTableImage: Record<string, ModelPricingImage>;
|
|
17
17
|
export declare const pricingTableAudio: Record<string, ModelPricingAudio>;
|
|
18
18
|
export declare const pricingTableTTS: Record<string, ModelPricingTTS>;
|
|
19
|
+
export type ToolName = "web_search" | "code_interpreter" | "file_search" | "image_generation" | "speech_to_text" | "text_to_speech" | string;
|
|
20
|
+
export declare const toolOverhead: Record<ToolName, number>;
|
|
19
21
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pricingTableTTS = exports.pricingTableAudio = exports.pricingTableImage = exports.pricingTableChat = void 0;
|
|
3
|
+
exports.toolOverhead = exports.pricingTableTTS = exports.pricingTableAudio = exports.pricingTableImage = exports.pricingTableChat = void 0;
|
|
4
4
|
exports.pricingTableChat = {
|
|
5
5
|
// --- GPT-5 family ---
|
|
6
6
|
'gpt-5-mini': { prompt: 0.25, cache: 0.025, completion: 2.0 },
|
|
@@ -29,3 +29,11 @@ exports.pricingTableTTS = {
|
|
|
29
29
|
// --- Text-to-Speech ---
|
|
30
30
|
'tts-1': { audioOut: 0.015 }, // $0.015 / minute
|
|
31
31
|
};
|
|
32
|
+
exports.toolOverhead = {
|
|
33
|
+
web_search: 1.1,
|
|
34
|
+
code_interpreter: 1.25,
|
|
35
|
+
file_search: 1.15,
|
|
36
|
+
image_generation: 1.0,
|
|
37
|
+
speech_to_text: 1.0,
|
|
38
|
+
text_to_speech: 1.0,
|
|
39
|
+
};
|