diff options
author | kqlio67 <kqlio67@users.noreply.github.com> | 2024-11-12 09:31:28 +0100 |
---|---|---|
committer | kqlio67 <kqlio67@users.noreply.github.com> | 2024-11-12 09:31:28 +0100 |
commit | 18be49027d7321b493f95152efbe2ae6e61b9d06 (patch) | |
tree | 06514f5d293c5eea800063f156342db932fe4f42 /g4f/Provider/Blackbox.py | |
parent | feat(g4f/Provider/HuggingChat.py: Enhance HuggingChat provider functionality (diff) | |
download | gpt4free-18be49027d7321b493f95152efbe2ae6e61b9d06.tar gpt4free-18be49027d7321b493f95152efbe2ae6e61b9d06.tar.gz gpt4free-18be49027d7321b493f95152efbe2ae6e61b9d06.tar.bz2 gpt4free-18be49027d7321b493f95152efbe2ae6e61b9d06.tar.lz gpt4free-18be49027d7321b493f95152efbe2ae6e61b9d06.tar.xz gpt4free-18be49027d7321b493f95152efbe2ae6e61b9d06.tar.zst gpt4free-18be49027d7321b493f95152efbe2ae6e61b9d06.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/Provider/Blackbox.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/g4f/Provider/Blackbox.py b/g4f/Provider/Blackbox.py index 998ec593..f93b0718 100644 --- a/g4f/Provider/Blackbox.py +++ b/g4f/Provider/Blackbox.py @@ -5,6 +5,7 @@ import random import string import json import re +import aiohttp from ..typing import AsyncResult, Messages, ImageType from .base_provider import AsyncGeneratorProvider, ProviderModelMixin @@ -18,6 +19,7 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin): supports_stream = True supports_system_message = True supports_message_history = True + _last_validated_value = None default_model = 'blackboxai' @@ -82,6 +84,23 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin): "flux": "Image Generation", } + @classmethod + async def fetch_validated(cls): + async with aiohttp.ClientSession() as session: + try: + async with session.get('https://www.blackbox.ai/_next/static/chunks/2052-0407a0af8bffe0a9.js') as response: + page_content = await response.text() + validated_match = re.search(r'w="([0-9a-fA-F-]{36})"', page_content) + + if validated_match: + validated_value = validated_match.group(1) + cls._last_validated_value = validated_value + return validated_value + except Exception as e: + pass + + return cls._last_validated_value + @staticmethod def generate_id(length=7): characters = string.ascii_letters + string.digits @@ -125,6 +144,7 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin): model = cls.get_model(model) message_id = cls.generate_id() messages_with_prefix = cls.add_prefix_to_messages(messages, model) + validated_value = await cls.fetch_validated() if image is not None: messages_with_prefix[-1]['data'] = { @@ -173,7 +193,7 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin): "mobileClient": False, "userSelectedModel": model if model in cls.userSelectedModel else None, "webSearchMode": web_search, - "validated": "00f37b34-a166-4efb-bce5-1312d87f2f94" + "validated": validated_value, } async with ClientSession(headers=headers) as session: |