110 lines
3.1 KiB
JavaScript
110 lines
3.1 KiB
JavaScript
import ModelDialog from './modelDialog.js';
|
|
import chalk from 'chalk';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const modelDialog = new ModelDialog({model: 'gpt-5-mini'});
|
|
|
|
modelDialog.on('outputUpdate', (output) => {
|
|
//console.log(chalk.blue('output event'),output);
|
|
});
|
|
modelDialog.on('reasoningUpdate', (output) => {
|
|
//console.log(chalk.blue('reasoning event'),output);
|
|
});
|
|
|
|
// $ / 1million tokens
|
|
const price = {
|
|
'gpt-5-2025-08-07': {
|
|
input: 1.25,
|
|
cached: 0.125,
|
|
output: 10
|
|
},
|
|
'gpt-5-mini-2025-08-07': {
|
|
input: 0.25,
|
|
cached: 0.025,
|
|
output: 2
|
|
},
|
|
'gpt-5-nano-2025-08-07': {
|
|
input: 0.05,
|
|
cached: 0.005,
|
|
output: 0.4
|
|
},
|
|
'gpt-4.1-2025-04-14': {
|
|
input: 2,
|
|
cached: 0.5,
|
|
output: 8
|
|
},
|
|
'gpt-4.1-mini-2025-04-14': {
|
|
input: 0.4,
|
|
cached: 0.1,
|
|
output: 1.6
|
|
},
|
|
};
|
|
|
|
|
|
(async ()=>{
|
|
//const output = await modelDialog.interrogate('Can you remember "seven" ?');
|
|
//console.log(output.output,JSON.stringify(output.reasoning,null,2));
|
|
//const output2 = await modelDialog.interrogate('read a file that is what you remebered plus 1 as a word with txt ending, check that file.');
|
|
|
|
|
|
|
|
const output2 = await modelDialog.interrogate('schau dich mal um und wenn du html dateien findest, dann invertiere den gradient.');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
console.log('final output:',output2.output);
|
|
console.log('reasoning:',output2.reasoning);
|
|
//Ti: { 'gpt-5-2025-08-07': 3019 } Tc: { 'gpt-5-2025-08-07': 0 } To: { 'gpt-5-2025-08-07': 751 }
|
|
console.log('Ti:',output2.inputTokens,'Tc:',output2.cachedTokens,'To:',output2.outputTokens);
|
|
// cost breakdown per model and totals (prices are per 1M tokens)
|
|
const perMillion = 1_000_000;
|
|
const models = new Set([
|
|
...Object.keys(output2.inputTokens || {}),
|
|
...Object.keys(output2.cachedTokens || {}),
|
|
...Object.keys(output2.outputTokens || {})
|
|
]);
|
|
|
|
let grandTotal = 0;
|
|
for (const model of models) {
|
|
const inputT = (output2.inputTokens || {})[model];
|
|
const cachedT = (output2.cachedTokens || {})[model];
|
|
const outputT = (output2.outputTokens || {})[model];
|
|
|
|
const p = price[model];
|
|
const inputCost = (typeof inputT === 'number' && p) ? (inputT / perMillion) * p.input : undefined;
|
|
const cachedCost = (typeof cachedT === 'number' && p) ? (cachedT / perMillion) * p.cached : undefined;
|
|
const outputCost = (typeof outputT === 'number' && p) ? (outputT / perMillion) * p.output : undefined;
|
|
|
|
const subtotal = [inputCost, cachedCost, outputCost].every(v => typeof v === 'number')
|
|
? (inputCost + cachedCost + outputCost)
|
|
: undefined;
|
|
|
|
if (typeof subtotal === 'number') grandTotal += subtotal;
|
|
|
|
console.log('cost for', model, {
|
|
inputCost: parseFloat(inputCost.toFixed(6)),
|
|
cachedCost: parseFloat(cachedCost.toFixed(6)),
|
|
outputCost: parseFloat(outputCost.toFixed(6)),
|
|
subtotal: parseFloat(subtotal.toFixed(4))
|
|
});
|
|
}
|
|
|
|
//console.log('total cost:', grandTotal);
|
|
})()
|