Created
September 17, 2023 06:24
-
-
Save physics1514/1f4b0b74e32c5378b8e8901fd95b3947 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import string | |
import requests | |
import openai | |
openai.api_key = '' | |
def generate_random_key(): | |
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=44)) | |
return f"sk-{random_string}" | |
def test_openai_key(api_key): | |
try: | |
openai.api_key = api_key | |
response = openai.Completion.create( | |
engine="davinci", | |
prompt="This is a test.", | |
max_tokens=5 | |
) | |
except: | |
return False | |
else: | |
return True | |
while True: | |
generated_key = generate_random_key() | |
if test_openai_key(generated_key): | |
print(f"[SUCCESS] Valid OpenAI Key: {generated_key}") | |
break | |
else: | |
print(f"[FAILED] Invalid Key: {generated_key}") |
Yep sorry it's not very practical, and i've only generated one key which was later invalidated after a few days. I'm trying to rework the script so maybe it could run faster.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
always failed