superdup95 commited on
Commit
59475cd
1 Parent(s): 550dfd0

Update api_usage.py

Browse files
Files changed (1) hide show
  1. api_usage.py +6 -9
api_usage.py CHANGED
@@ -9,11 +9,6 @@ RATE_LIMIT_PER_MODEL = {
9
  "gpt-4": 200,
10
  "gpt-4-32k": 1000
11
  }
12
- BODY_GPT = {
13
- "gpt-3.5-turbo": {"model": "gpt-3.5-turbo", "max_tokens": 1, "messages": [{'role':'user', 'content': ''}]},
14
- "gpt-4": {"model": "gpt-4", "max_tokens": 1, "messages": [{'role':'user', 'content': ''}]},
15
- "gpt-4-32k": {"model": "gpt-4-32k", "max_tokens": 1, "messages": [{'role':'user', 'content': ''}]}
16
- }
17
 
18
  def get_headers(key):
19
  headers = {'Authorization': f'Bearer {key}'}
@@ -23,6 +18,7 @@ def get_subscription(key, available_models):
23
  headers = get_headers(key)
24
  rpm = "0"
25
  tpm = "0"
 
26
  org = ""
27
  quota = ""
28
  key_highest_model = ""
@@ -46,6 +42,7 @@ def get_subscription(key, available_models):
46
  if "id" in result:
47
  rpm = r.headers.get("x-ratelimit-limit-requests", "0")
48
  tpm = r.headers.get("x-ratelimit-limit-tokens", "0")
 
49
  org = r.headers.get('openai-organization', "")
50
  quota = check_key_type(key_highest_model, int(rpm))
51
  else:
@@ -57,7 +54,7 @@ def get_subscription(key, available_models):
57
  "has_gpt4": has_gpt4,
58
  "organization": org,
59
  "rpm": f"{rpm} ({key_highest_model})",
60
- "tpm": f"{tpm}",
61
  "quota": quota}
62
 
63
  def get_org_name(key):
@@ -66,10 +63,10 @@ def get_org_name(key):
66
  return r.headers['openai-organization']
67
 
68
  def check_key_type(model, rpm):
69
- if rpm >= RATE_LIMIT_PER_MODEL[model]:
70
- return "yes | pay"
71
- else:
72
  return "yes | trial"
 
 
73
 
74
  def check_gpt4_availability(available_models):
75
  if 'gpt-4' in available_models:
 
9
  "gpt-4": 200,
10
  "gpt-4-32k": 1000
11
  }
 
 
 
 
 
12
 
13
  def get_headers(key):
14
  headers = {'Authorization': f'Bearer {key}'}
 
18
  headers = get_headers(key)
19
  rpm = "0"
20
  tpm = "0"
21
+ tpm_left = "0"
22
  org = ""
23
  quota = ""
24
  key_highest_model = ""
 
42
  if "id" in result:
43
  rpm = r.headers.get("x-ratelimit-limit-requests", "0")
44
  tpm = r.headers.get("x-ratelimit-limit-tokens", "0")
45
+ tpm_left = r.headers.get("x-ratelimit-remaining-tokens", "0")
46
  org = r.headers.get('openai-organization', "")
47
  quota = check_key_type(key_highest_model, int(rpm))
48
  else:
 
54
  "has_gpt4": has_gpt4,
55
  "organization": org,
56
  "rpm": f"{rpm} ({key_highest_model})",
57
+ "tpm": f"{tpm} ({tpm_left} left)",
58
  "quota": quota}
59
 
60
  def get_org_name(key):
 
63
  return r.headers['openai-organization']
64
 
65
  def check_key_type(model, rpm):
66
+ if rpm < RATE_LIMIT_PER_MODEL[model]:
 
 
67
  return "yes | trial"
68
+ else:
69
+ return "yes | pay"
70
 
71
  def check_gpt4_availability(available_models):
72
  if 'gpt-4' in available_models: