import { EventEmitter } from "events"; import { OpenAICallTrackerCallback } from "../../openai_call_tracker"; export type OpenAICostTrackerJsonEntry = { totalCost: number; }; export type OpenAICostTrackerJsonStorage = { spent: Record; saved: Record; }; export type OpenAICostTrackerJsonBucketWrittenPayload = { dateIso: string; bucketId: string; modelName: string; costSpent: number; costSaved: number; }; /** * Example of a simple database to store tracked costs from the OpenAICallTracker. It is designed to be used in the openai_cost_tracker_example.ts * example, but it can be adapted to be used in other contexts as well. It provides a simple interface to get a tracker callback function * that can be passed to the OpenAICallTracker, and it handles the storage of tracked costs in memory and optionally saving/loading them from a file. */ export declare class OpenAICostTrackerJson extends EventEmitter { static EVENT: { BUCKET_WRITTEN: string; }; private _sampleStorage; private _filePath?; /** * Constructor for the OpenAICostTrackerJson class. * @param filePath - Optional file path to load/save the tracked costs. If provided, the tracked costs will be loaded from this file * on initialization and saved to this file on exit. If not provided, the tracked costs will only be stored in memory and will * not persist across sessions. */ constructor(filePath?: string); /** * async initialisation function * - it load the tracked db from the file if the file path is provided * - to set up an exit listener to save the tracked db to the file on exit */ init(): Promise; close(): Promise; saveToFile(): Promise; getStorage(): Promise; getTrackerCallback(): Promise; /** * This is an example of a tracker callback function that can be passed to the OpenAICostTracker to track * costs in a custom way (e.g. save to a database, send to an analytics service, etc) * * @param bucketId - an identifier for the tracker, used to group usage information * @param response - the response from the OpenAI API, which contains the usage information in the body */ private _trackerCallback; }