"""Проба ВСЕХ моделей modeloc на живых ключах.""" import json, sys, time, threading import requests HERE = r'C:/Users/User/tmp/modeloc-autoreg' URL = 'https://modeloc.com/pool/v1/chat/completions' def load_keys(n=4): keys = [] for f in ('bank_c.jsonl', 'bank_d.jsonl', 'bank_a.jsonl', 'bank_b.jsonl'): try: for line in open(HERE + '/' + f, encoding='utf-8'): try: b = json.loads(line) except Exception: continue if b.get('key') and str(b.get('credits', '')).startswith('1000') and b['key'] not in keys: keys.append(b['key']) except FileNotFoundError: pass return keys[:n] def probe(key, model): t0 = time.time() try: r = requests.post(URL, headers={'Authorization': 'Bearer ' + key, 'Content-Type': 'application/json'}, json={'model': model, 'messages': [{'role': 'user', 'content': 'say ok'}], 'max_tokens': 30}, timeout=70) code = r.status_code txt = '' if code == 200: try: txt = (r.json()['choices'][0]['message'].get('content') or '')[:40] except Exception: txt = 'parse' except Exception as e: code, txt = 0, type(e).__name__ return code, txt, round(time.time() - t0, 1) def main(): models = json.load(open(HERE + '/mc_all_models.json', encoding='utf-8')) keys = load_keys(4) jobs = [(i % len(keys), m) for i, m in enumerate(models * len(keys))] jobs = [(keys[ki], m) for ki, m in jobs] results = {} lock = threading.Lock() out = open(HERE + '/probe_all.log', 'w', encoding='utf-8') def work(chunk): for key, m in chunk: code, txt, el = probe(key, m) with lock: results.setdefault(m, []).append(code) out.write('%s\t%d\t%s\t%s\n' % (m, code, el, txt.replace('\n', ' '))) out.flush() print('%s %d %s' % (m, code, el), flush=True) nw = 12 chunks = [jobs[i::nw] for i in range(nw)] th = [threading.Thread(target=work, args=(c,)) for c in chunks] for t in th: t.start() for t in th: t.join() good = [] for m, codes in results.items(): ok = sum(1 for c in codes if c == 200) if ok >= 2: good.append((m, ok, len(codes))) good.sort(key=lambda x: -x[1]) json.dump([g[0] for g in good], open(HERE + '/mc_good_models.json', 'w'), ensure_ascii=False, indent=0) print('\n=== GOOD (200 on >=2 keys): %d' % len(good)) for m, ok, tot in good: print('%2d/%d %s' % (ok, tot, m)) if __name__ == '__main__': main()