Commit
·
0360007
1
Parent(s):
4f7bd94
Update api_usage.py
Browse files- api_usage.py +19 -0
api_usage.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import requests
|
| 2 |
import os
|
| 3 |
import openai
|
|
|
|
| 4 |
|
| 5 |
BASE_URL = 'https://api.openai.com/v1'
|
| 6 |
GPT_TYPES = ["gpt-3.5-turbo", "gpt-4", "gpt-4-32k"]
|
|
@@ -87,6 +88,24 @@ def check_key_availability():
|
|
| 87 |
except:
|
| 88 |
return False
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
if __name__ == "__main__":
|
| 91 |
key = os.getenv("OPENAI_API_KEY")
|
|
|
|
| 92 |
results = get_subscription(key)
|
|
|
|
| 1 |
import requests
|
| 2 |
import os
|
| 3 |
import openai
|
| 4 |
+
import anthropic
|
| 5 |
|
| 6 |
BASE_URL = 'https://api.openai.com/v1'
|
| 7 |
GPT_TYPES = ["gpt-3.5-turbo", "gpt-4", "gpt-4-32k"]
|
|
|
|
| 88 |
except:
|
| 89 |
return False
|
| 90 |
|
| 91 |
+
def check_key_ant_availability(ant):
|
| 92 |
+
try:
|
| 93 |
+
ant.completions.create(
|
| 94 |
+
prompt=f"{anthropic.HUMAN_PROMPT}Hi{anthropic.AI_PROMPT}",
|
| 95 |
+
max_tokens_to_sample=1,
|
| 96 |
+
model="claude-instant-v1",
|
| 97 |
+
)
|
| 98 |
+
return True, "Working"
|
| 99 |
+
except anthropic.APIConnectionError as e:
|
| 100 |
+
print(e.__cause__) # an underlying Exception, likely raised within httpx.
|
| 101 |
+
return False, "Error: The server could not be reached"
|
| 102 |
+
except anthropic.RateLimitError as e:
|
| 103 |
+
return True, "Error: 429, rate limited; we should back off a bit."
|
| 104 |
+
except anthropic.APIStatusError as e:
|
| 105 |
+
err_msg = e.body.get('error', {}).get('message', '')
|
| 106 |
+
return False, f"Error: {e.status_code}, {err_msg}"
|
| 107 |
+
|
| 108 |
if __name__ == "__main__":
|
| 109 |
key = os.getenv("OPENAI_API_KEY")
|
| 110 |
+
key_ant = os.getenv("ANTHROPIC_API_KEY")
|
| 111 |
results = get_subscription(key)
|