Coverage for auth/lib_cost.py: 67%

15 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2026-02-06 02:54 +0100

1 

2 

3 

4class CostEstimation(): 

5 def __init__(self): 

6 

7 # https://openai.com/pricing#language-models As of 2023-11-06 

8 self.map_api_costs = {"text-embedding-ada-002-v2" : 0.0001, #0.0004, => ils ont bien divisé par 4 ! 

9 "gpt-3.5-turbo" : 0.0015, # 4K context input X2 output and 16K context # baisse au 13-6-23 prix avant 0.002, 

10 "gpt-4" : 0.06, # in fact 0.03 for 8k context input X2 for output and 32K context 

11 "gpt-4-0314" : 0.06, 

12 "gpt-4-0613" : 0.06, # c'est gpt qui change 

13 "gpt-4-1106-preview" : 0.03, 

14 "Babbage" : 0.0005, 

15 "Curie" : 0.0020, 

16 "Davinci" : 0.0200, 

17 "whisper-1" : 0.0001, # per second 

18 "google_ocr" : 0} # per image 

19 

20 self.cost = 0 

21 

22 def get_cost_per_model(self, model): 

23 if model in self.map_api_costs: 

24 return self.map_api_costs[model] 

25 else : 

26 return 0 

27 

28 def compute_cost_search(self, model : str, nb_token : int) -> float: 

29 if model not in self.map_api_costs: 

30 print("Unexpected model : " + str(model)) 

31 return -1 

32 cost = nb_token / 1000. * self.map_api_costs[model] 

33 self.cost += cost 

34 return cost 

35 

36