importrequestsimportjsonimportrandomimportstringfromnltk.corpusimportbrownfromrichimportprintimporttimeimportthreading# Set up variablesurl="https://cncanon-locusts.hf.space/proxy/openai/v1/chat/completions"key="kane_lives!"# Change this in case of a password changerepeat_line="Repeat the following back to me, word for word:"garbage_size=350num_threads=400# Set up NLTKnltk_words=brown.words()nltk_words=[word.lower()forwordinnltk_wordsifword.isalpha()]# Function to generate random wordsdefgenerate_garbage(num_words,thread_num):garbage=" ".join(random.choices(nltk_words,k=num_words))print(f"[bold green]Thread {thread_num} generated garbage:[/bold green] {garbage[:20]}...\n[bold green]Garbage length: {len(garbage)}[/bold green]")returngarbage# Function to send requestdefsend_request(thread_num):garbage=repeat_line+" "+generate_garbage(garbage_size,thread_num)print(f"[bold]Thread {thread_num} sending request...[/bold]")payload={"model":"gpt-4","messages":[{"role":"user","content":garbage}],"temperature":1.0}headers={"Content-Type":"application/json","Authorization":f"Bearer {key}"}data=json.dumps(payload)response=requests.post(url,headers=headers,data=data)try:content=json.loads(response.text)["choices"][0]["message"]["content"]print(f"[bold red]Thread {thread_num} response content:[/bold red] {content[:20]}...\n[bold red]Response length: {len(content)}[/bold red]")except:print(f"[bold red]ERROR: {response.text}[/bold red]")# Create and start threadsthreads=[]foriinrange(num_threads):thread=threading.Thread(target=send_request,args=(i+1,))thread.start()threads.append(thread)time.sleep(61)print("Sleeping one minute due to rate limits")# Wait for threads to finishforthreadinthreads:thread.join()