Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"New version of g4f" and "BlackBox.ai" message #2326

Open
Shwumper opened this issue Nov 2, 2024 · 14 comments
Open

"New version of g4f" and "BlackBox.ai" message #2326

Shwumper opened this issue Nov 2, 2024 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@Shwumper
Copy link

Shwumper commented Nov 2, 2024

image
image
Python version: 3.11.1

image
image

@Shwumper Shwumper added the bug Something isn't working label Nov 2, 2024
@testrustic
Copy link

I have the same problem, it is the best AI and it has never given me problems until today.

@hqnicolas
Copy link

image

@DinacoStudio
Copy link

whats you discord @Mishel-Tg

@Mishel-Tg
Copy link

lexica.dev/docs

@terapevt1981
Copy link

I got a premium subscription in Blackbox AI (4 invitations to the email). However, I can't figure out how and where to get the API key.
I have their userID.
Maybe can it be used to gain access to this provider in g4f?

@Badim41
Copy link

Badim41 commented Nov 5, 2024

Add "validation" header.

image
image

I don't know if the same "validated" header "69783381-2ce4-4dbd-ac78-35e9063feabc" will work in all cases, but it worked several times for me even from different IP addresses and messages.

@newsister
Copy link

How can I remove that message?

@Linden10
Copy link

Linden10 commented Nov 7, 2024

Add "validation" header.

image image

I don't know if the same "validated" header "69783381-2ce4-4dbd-ac78-35e9063feabc" will work in all cases, but it worked several times for me even from different IP addresses and messages.

Thank you! This fixed the issue of the api constantly not returning the full messaging and cutting off when using blackbox through the interference api!

Basically I had to open up blackbox.py (normally located in your python site-packages g4f folder) and add this line:
"validated": "69783381-2ce4-4dbd-ac78-35e9063feabc"

within the payload_api_chat headers function, right below "userSelectedModel".

Again thank you!
Hope this is incorporated into g4f if no problems arise form using it!

EDIT: Ah actually for some reason I'm still getting that message despite putting it in the payload api section...
I'm not sure how to get rid of it unfortunately...

@DinacoStudio
Copy link

this id generated dynamic

function uuidv4() {
    return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, e => (Number(e) ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> Number(e) / 4).toString(16))
}

@Linden10
Copy link

Linden10 commented Nov 7, 2024

this id generated dynamic

function uuidv4() {
    return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, e => (Number(e) ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> Number(e) / 4).toString(16))
}

Very interesting! How would you integrate this with the blackbox.py script?
Can you explain where to put this? I love to use it when using g4f api alright, Thank you!

@DinacoStudio
Copy link

DinacoStudio commented Nov 7, 2024

this id generated dynamic

function uuidv4() {
    return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, e => (Number(e) ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> Number(e) / 4).toString(16))
}

Very interesting! How would you integrate this with the blackbox.py script? Can you explain where to put this? I love to use it when using g4f api alright, Thank you!

I made fix using nodejs to find key in js using headless browser

async function getKey() {
  const browser = await puppeteer.launch({
    headless: true,
    args: ["--no-sandbox"],
  });
  const page = await browser.newPage();
  const regexp = /,w="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})"/;
  let k = "";
  page.on("response", async (response) => {
    if (response.request().resourceType() === "script") {
      try {
        let j = await response.text();
        if (j.match(regexp) !== null) {
          k = j.match(regexp)[1];
        }
      } catch {}
    }
  });

  await page.goto("https://www.blackbox.ai");
  await browser.close();
  return k;
}

@Linden10
Copy link

Linden10 commented Nov 7, 2024

this id generated dynamic

function uuidv4() {
    return "10000000-1000-4000-8000-100000000000".replace(/[018]/g, e => (Number(e) ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> Number(e) / 4).toString(16))
}

Very interesting! How would you integrate this with the blackbox.py script? Can you explain where to put this? I love to use it when using g4f api alright, Thank you!

I made fix using nodejs to find key in js using headless browser

async function getKey() {
  const browser = await puppeteer.launch({
    headless: true,
    args: ["--no-sandbox"],
  });
  const page = await browser.newPage();
  const regexp = /,w="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})"/;
  let k = "";
  page.on("response", async (response) => {
    if (response.request().resourceType() === "script") {
      try {
        let j = await response.text();
        if (j.match(regexp) !== null) {
          k = j.match(regexp)[1];
        }
      } catch {}
    }
  });

  await page.goto("https://www.blackbox.ai");
  await browser.close();
  return k;
}

That's very nice! I tried integrating it into blackbox.py but I wasn't working for me heh...still thanks for sharing!
I will say, that regex code...I used it to find the script containing that string on the website and used what was found in blackbox.py with the validated header!

I think it's working...thanks again!

@kqlio67
Copy link
Contributor

kqlio67 commented Nov 13, 2024

Hey everyone! 👋

I wanted to share a useful Python script I've been working with. It's designed to extract the Validated Key from Blackbox.ai's JavaScript files. While this functionality is already integrated into the Blackbox.py provider, I thought this standalone script might be helpful for those who want to understand how it works or need a similar solution for their projects.

To run the script:

  1. Install the required library with: pip install requests
  2. Create a .py file and paste the code below
  3. Run and test!
import requests
import re

def get_key_from_js():
    base_url = "https://www.blackbox.ai"
    response = requests.get(base_url)

    if response.status_code != 200:
        print("Failed to load the page.")
        return None

    # Get the HTML of the page
    js_files = re.findall(r'static/chunks/\d{4}-[a-fA-F0-9]+\.js', response.text)
    
    # Pattern to match UUID format in JavaScript files
    key_pattern = re.compile(r'w="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})"')

    for js_file in js_files:
        js_url = f"{base_url}/_next/{js_file}"
        js_response = requests.get(js_url)

        if js_response.status_code == 200:
            # Find all JavaScript file links
            match = key_pattern.search(js_response.text)
            if match:
                return {"key": match.group(1), "source": js_url}

    print("Key not found")
    return None

result = get_key_from_js()
if result:
    print("Validated Key:", result["key"])
    print("Source file:", result["source"])
else:
    print("Key not found")

Example output:

Key: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Source file: https://www.blackbox.ai/_next/static/chunks/xxxx-xxxxxxxxxx.js

Note: This script is for educational purposes. Please ensure you comply with Blackbox.ai's terms of service when using it.

This script navigates through Blackbox.ai's JavaScript files to find and extract the key. It's a neat example of web scraping and pattern matching in Python.

Feel free to use or modify this code for your needs. If you have any questions or suggestions for improvements, don't hesitate to ask. Happy coding! 🐍✨

@DinacoStudio
Copy link

I am very glad that my script will be useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests