File size: 2,273 Bytes
d10dfb0
 
 
 
 
 
 
 
 
60724c7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests
import secrets
import random
import re
import string
import json
import urllib
from base64 import b64decode as m

class Blackbox:
    def __init__(self) -> None:
        """API Class for various purposes"""
        pass
        
    @staticmethod
    def chat(args: str) -> dict:
        url = m("aHR0cHM6Ly93d3cuYmxhY2tib3guYWkvYXBpL2NoYXQ=").decode("utf-8")

        payload = {
            "agentMode": {},
            "codeModelMode": True,
            "id": "XM7KpOE",
            "isMicMode": False,
            "maxTokens": None,
            "messages": [
                {"id": "XM7KpOE", "content": urllib.parse.unquote(args), "role": "user"}
            ],
            "previewToken": None,
            "trendingAgentMode": {},
            "userId": "87cdaa48-cdad-4dda-bef5-6087d6fc72f6",
            "userSystemPrompt": None,
        }

        headers = {
            "Content-Type": m("YXBwbGljYXRpb24vanNvbg==").decode("utf-8"),
            "Cookie": m("c2Vzc2lvbklkPWY3N2E5MWUxLWNiZTEtNDdkMC1iMTM4LWMyZTIzZWViNWRjZjtpbnRlcmNvbS1pZC1qbG1xeGljYj00Y2YwN2RkOC03NDJlLTRlM2YtODFkZS0zODY2OTgxNmQzMDA7aW50ZXJjb20tZGV2aWNlLWlkLWpsbXF4aWNiPTFlYWZhYWNiLWYxOGQtNDAyYS04MjU1LWI3NjNjZjM5MGRmNjtpbnRlcmNvbS1zZXNzaW9uLWpsbXF4aWNiPQ==").decode("utf-8"),
            "Origin": m("aHR0cHM6Ly93d3cuYmxhY2tib3guYWk=").decode("utf-8"),
            "User-Agent": m("TW96aWxsYS81LjAgKFdpbmRvd3MgTlQgMTAuMDsgV2luNjQ7IHg2NCkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCBsaWtlIEdlY2tvKUNocm9tZS8xMjEuMC4wLjAgU2FmYXJpLzUzNy4zNg==").decode("utf-8"),
        }

        try:
            response = requests.post(url, json=payload, headers=headers)
            response.raise_for_status()
            clean_text = response.text.replace("$@$v=undefined-rv1$@$", "")

            split_text = clean_text.split("\n\n", 2)

            if len(split_text) >= 3:
                content_after_second_newline = split_text[2]
            else:
                content_after_second_newline = ""

            return {"answer": content_after_second_newline, "success": True}

        except requests.exceptions.RequestException as e:
            return {"results": str(e), "success": False}

def send_blackbox_chat(query):
    response = Blackbox.chat(query)
    return response.get("answer")