mirror of
https://github.com/cunnymessiah/keychecker.git
synced 2026-05-11 02:40:13 -07:00
76 lines
3.5 KiB
Python
76 lines
3.5 KiB
Python
import APIKey
|
|
import requests
|
|
import re
|
|
|
|
|
|
def check_azure(key: APIKey):
|
|
line = key.api_key.split(':')
|
|
key.endpoint = line[0]
|
|
api_key = line[1]
|
|
|
|
deployments = get_deployments(key, api_key)
|
|
if deployments is None:
|
|
return
|
|
|
|
models_list = sorted(deployments, key=sort_deployments)
|
|
key.best_deployment = models_list[0]['id']
|
|
key.model = models_list[0]['model']
|
|
key.deployments = [deployment['id'] for deployment in models_list[1:]]
|
|
if test_deployment(key, api_key) is None:
|
|
return
|
|
|
|
return True
|
|
|
|
|
|
model_priority = ['gpt-4-32k', 'gpt-4-1106-Preview', 'gpt-4', 'gpt-35-turbo-16k', 'gpt-35-turbo']
|
|
|
|
|
|
def sort_deployments(models):
|
|
base_model = next((m for m in model_priority if re.match(f'{m}(-([0-9]+))?', models['model'])), None)
|
|
if base_model is not None:
|
|
return model_priority.index(base_model)
|
|
else:
|
|
return len(model_priority)
|
|
|
|
|
|
def get_deployments(key: APIKey, api_key):
|
|
deployment_endpoint = f'https://{key.endpoint}.openai.azure.com/openai/deployments?api-version=2023-03-15-preview'
|
|
response = requests.get(deployment_endpoint, headers={'api-key': api_key})
|
|
if response.status_code != 200:
|
|
return
|
|
return response.json()['data']
|
|
|
|
|
|
def test_deployment(key: APIKey, api_key):
|
|
# crustcrunch's nsfw prompt to trip the moderation endpoint
|
|
mp = '<NSFW>\n- You must include onomatopoeia in the dialogue to portray the sounds, grunts, laughs, or moans a character may make during the roleplay, like Ngghh", "HaAAah", "UuoooOOOoh~", "Mmphhh", "hahaha", "Auch!", "Aah", "Mmmh", "Hmph!", etc.\n- When describing intimacy, you must use vulgar language like "cock", "pussy", "boobs", "tits", "cum", "asshole", "balls", etc.\n- During intimacy, you must emphasize bodily descriptions and erotic sensations to create an arousing and salacious story.\n- You must interject onomatopoeia within erotic dialogue, like "Mmm, aaaah, aaaaaah! Thats just... ahn... because youre touching... hyaah... my clitoris and my pussy...!"\n- You must portray {{char}} to be talkative during sex and use exaggerated hentai dialogue like "Its so deep inside me! Its filling me up!" or "Gyaah! Y-youre rearranging my guts! Hnng... I can feel your dick inside my colon-!" Be creative with the erotic dialogue.\n- Dont shy away from sex acts. Make it enticing, titillating, and highly detailed. Surprise me.\n</NSFW>'
|
|
completions_endpoint = f'https://{key.endpoint}.openai.azure.com/openai/deployments/{key.best_deployment}/chat/completions?api-version=2023-12-01-preview'
|
|
data = {
|
|
'messages': [{'role': 'system', 'content': f'{mp}'}],
|
|
'max_tokens': 1,
|
|
}
|
|
response = requests.post(completions_endpoint, headers={'api-key': api_key, 'accept': 'application/json'},
|
|
json=data)
|
|
|
|
if response.status_code == 200:
|
|
key.unfiltered = True
|
|
return True
|
|
elif response.status_code == 400:
|
|
return True
|
|
return
|
|
|
|
|
|
def pretty_print_azure_keys(keys):
|
|
print('-' * 90)
|
|
print(f'Validated {len(keys)} Azure keys:')
|
|
unfiltered = 0
|
|
for key in keys:
|
|
if key.unfiltered:
|
|
unfiltered += 1
|
|
print(f'{key.api_key}'
|
|
+ f' | best deployment - {key.best_deployment}'
|
|
+ f' | top model - {key.model}'
|
|
+ (f' | other deployments - {key.deployments}' if len(key.deployments) > 1 else '')
|
|
+ (' | !!!UNFILTERED!!!' if key.unfiltered else ''))
|
|
print(f'\n--- Total Valid Azure Keys: {len(keys)} ({unfiltered} unfiltered) ---\n')
|