This repository has been archived on 2023-10-20. You can view files and clone it, but cannot push or open issues or pull requests.
hf-key-scraper/huggingface/check-keys.py

82 lines
2.1 KiB
Python

import argparse
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
from tqdm import tqdm
from keychecker.check import check_key
def process_key(key):
result = check_key(key)
if not len(result['errors']):
if result['has_gpt_4'] or result['has_only_turbo'] or result['has_gpt_4_32k']:
print(result)
return result
return None
def main():
parser = argparse.ArgumentParser(description='Scrape data from chub.ai.')
parser.add_argument('input_file', nargs='*', help='Path to the file containing the keys.')
args = parser.parse_args()
keys = set()
for file in args.input_file:
input_file = Path(file).resolve().expanduser().absolute()
if not input_file.exists():
print('Input file does not exist:', input_file)
quit(1)
data = set(input_file.read_text().splitlines())
keys = keys | data
# content = ['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']
print('Checking', len(keys), 'keys...')
gpt_4 = set()
gpt_4_32k = set()
gpt_3 = set()
pbar = tqdm(total=len(keys))
with ThreadPoolExecutor(max_workers=50) as executor:
results = executor.map(process_key, keys)
for result in results:
if result is not None:
if result['has_gpt_4']:
gpt_4.add(result['api_key'])
if result['has_gpt_4_32k']:
gpt_4_32k.add(result['api_key'])
if result['has_only_turbo']:
gpt_3.add(result['api_key'])
pbar.update(1)
pbar.close()
print('')
print('GPT4 KEYS:')
if not len(gpt_4):
print('none')
else:
for key in gpt_4:
print(key)
print('')
print('GPT4-32k KEYS:')
if not len(gpt_4_32k):
print('none')
else:
for key in gpt_4_32k:
print(key)
print('')
print('GPT3 KEYS:')
if not len(gpt_3):
print('none')
else:
for key in gpt_3:
print(key)
if __name__ == "__main__":
main()