From 70c53b87e946b5173c2ada3e60a1edb53f140a4f Mon Sep 17 00:00:00 2001 From: user Date: Sat, 27 Jul 2024 11:32:00 +0000 Subject: [PATCH] Fix Mistral key checking --- Mistral.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Mistral.py b/Mistral.py index bf97fee..428623f 100644 --- a/Mistral.py +++ b/Mistral.py @@ -13,15 +13,15 @@ async def check_sub_status(key: APIKey, session): data = { 'model': 'open-mistral-7b', 'messages': [{'role': 'user', 'content': ''}], - 'max_tokens': 1 + 'max_tokens': -1 } async with session.post(f'https://api.mistral.ai/v1/chat/completions', headers={'Authorization': f'Bearer {key.api_key}'}, json=data) as response: - if response.status == 401 or response.status == 429: - return False - return True + # Since we do an invalid request, if the key is active and has quota, the API returns 422 Unprocessable Entity + return response.status == 422 def pretty_print_mistral_keys(keys): + keys = sorted(keys, key=lambda x: x.subbed, reverse=True) print('-' * 90) subbed = 0 print(f'Validated {len(keys)} Mistral keys:')