File size: 2,052 Bytes
b293d47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Module: Tracking

## Goal
The `tracking` module is responsible for tracking and analyzing the usage and cost of various APIs used in the project. It includes two files: `api_tracking.py` and `cost_analytics.py`.

## File: api_tracking.py

### Class: APITracker
This class is responsible for tracking the usage of APIs and saving the data to a content manager.

#### Method: `__init__()`
- Initializes the APITracker object.
- Calls the `initiateAPITracking()` method.

#### Method: `setDataManager(contentManager: ContentDataManager)`
- Sets the content manager for storing the API usage data.
- Raises an exception if the content manager is null.

#### Method: `openAIWrapper(gptFunc)`
- Wrapper function for OpenAI API calls.
- Saves the API usage data to the content manager.
- Returns the result of the API call.

#### Method: `elevenWrapper(audioFunc)`
- Wrapper function for Eleven API calls.
- Saves the API usage data to the content manager.
- Returns the result of the API call.

#### Method: `wrap_turbo()`
- Wraps the `gpt3Turbo_completion` function from the `gpt_utils` module using the `openAIWrapper` method.
- Replaces the original function with the wrapped function.

#### Method: `wrap_eleven()`
- Wraps the `generateVoice` function from the `audio_generation` module using the `elevenWrapper` method.
- Replaces the original function with the wrapped function.

#### Method: `initiateAPITracking()`
- Initiates the tracking of APIs by wrapping the necessary functions using the `wrap_turbo` and `wrap_eleven` methods.


## File: cost_analytics.py

### Function: calculateCostAnalytics()
This function calculates the average usage and cost of OpenAI and Eleven APIs based on the data stored in the content database.

- Initializes the content database.
- Retrieves the API usage data from the database.
- Calculates the average usage and cost for OpenAI and Eleven APIs.
- Prints the results.

### Usage example:
```python
calculateCostAnalytics()
```

Note: The commented code at the end of the file is unrelated and can be ignored.