From c405a67c7924dbc9afc01d14e6baac08851715be Mon Sep 17 00:00:00 2001 From: based Date: Mon, 20 Jan 2025 05:21:53 +1000 Subject: [PATCH] deepseek update --- APIKey.py | 3 ++- Deepseek.py | 44 +++++++++++++++++++++++++++++--------------- main.py | 19 ++++++++++++++++--- 3 files changed, 47 insertions(+), 19 deletions(-) diff --git a/APIKey.py b/APIKey.py index 3fc0ff1..fde6ec2 100644 --- a/APIKey.py +++ b/APIKey.py @@ -74,8 +74,9 @@ class APIKey: self.pro_voice_limit = 0 elif provider == Provider.DEEPSEEK: - self.balance = "" + self.balance = "$0.0 USD" self.available = False + self.rate_limited = False def clone(self): cloned_key = APIKey(self.provider, self.api_key) diff --git a/Deepseek.py b/Deepseek.py index 15b004c..83434d7 100644 --- a/Deepseek.py +++ b/Deepseek.py @@ -1,33 +1,47 @@ import APIKey - async def check_whale(key: APIKey, session): - async with session.get(f'https://api.deepseek.com/models', headers={'Authorization': f'Bearer {key.api_key}'}) as response: - if response.status != 200: - return - if not await check_balance(key, session): - return - return True + valid = await check_balance(key, session) + return valid async def check_balance(key: APIKey, session): async with session.get(f'https://api.deepseek.com/user/balance', headers={'Authorization': f'Bearer {key.api_key}'}) as response: - if response.status != 200: - return + if response.status == 429: + return False + elif response.status != 200: + return None + data = await response.json() key.available = data.get('is_available', False) balance_infos = data.get('balance_infos', []) - if balance_infos: - key.balance = float(balance_infos[0].get('total_balance', '0.0')) + total_usd = 0.0 + for balance in balance_infos: + amount = float(balance.get('total_balance', '0.0')) + currency = balance.get('currency', 'USD') + if currency == 'CNY': + amount *= 0.14 + total_usd += amount + + key.balance = f'${total_usd:.1f} USD' return True def pretty_print_deepseek_keys(keys): - keys = sorted(keys, key=lambda x: x.balance, reverse=True) + def get_balance_value(key): + return float(key.balance.split()[0].replace('$', '')) + + keys = sorted(keys, key=lambda x: ( + x.rate_limited, + get_balance_value(x) == 0, + -get_balance_value(x) + )) + print('-' * 90) available = sum(1 for key in keys if key.available) print(f'Validated {len(keys)} Deepseek keys:') for key in keys: - balance_str = f'| ${key.balance}' if key.available else '' - print(f'{key.api_key} {balance_str}') - print(f'\n--- Total Valid Deepseek Keys: {len(keys)} ({available} with sufficient usage balance) ---\n') + balance_str = f' | {key.balance}' if key.available else '' + ratelimit_str = f' | rate-limited' if key.rate_limited else '' + print(f'{key.api_key}{balance_str}{ratelimit_str}') + print(f'\n--- Total Valid Deepseek Keys: {len(keys)} ({available} with sufficient usage balance) ---\n') \ No newline at end of file diff --git a/main.py b/main.py index 3a6fa7d..0197d2a 100644 --- a/main.py +++ b/main.py @@ -183,12 +183,25 @@ async def validate_vertexai(key: APIKey, sem): async def validate_whale(key: APIKey, sem): - async with sem, aiohttp.ClientSession() as session: + retry_count = 4 + async with sem, deepseek_semaphore, aiohttp.ClientSession() as session: IO.conditional_print(f"Checking Deepseek key: {key.api_key}", args.verbose) - if await check_whale(key, session) is None: + key_status = await check_whale(key, session) + if key_status is None: IO.conditional_print(f"Invalid Deepseek key: {key.api_key}", args.verbose) return + elif key_status is False: + i = 0 + while await check_whale(key, session) is False and i < retry_count: + i += 1 + await asyncio.sleep(2) + print(f"Stuck determining status of rate limited Deepseek key '{key.api_key[-8:]}' - attempt {i} of {retry_count}") + key.rate_limited = True + else: + if i < retry_count: + key.rate_limited = False IO.conditional_print(f"Deepseek key '{key.api_key}' is valid", args.verbose) + # await asyncio.sleep(5) api_keys.add(key) @@ -226,7 +239,7 @@ deepseek_regex = re.compile(r'sk-[a-f0-9]{32}') executor = ThreadPoolExecutor(max_workers=100) concurrent_connections = asyncio.Semaphore(1500) makersuite_semaphore = asyncio.Semaphore(50) # when did google become such a pussy - +deepseek_semaphore = asyncio.Semaphore(50) async def validate_keys(): tasks = []