summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Blackbox.py
diff options
context:
space:
mode:
authorkqlio67 <kqlio67@users.noreply.github.com>2024-09-24 12:23:53 +0200
committerkqlio67 <kqlio67@users.noreply.github.com>2024-09-24 12:23:53 +0200
commitf8e403a745c5caff31d7edb854dcba40eba3166d (patch)
treea75c6030a8054c56201fa2d41306a51b9052545c /g4f/Provider/Blackbox.py
parentAdded gpt-4o provider (diff)
downloadgpt4free-f8e403a745c5caff31d7edb854dcba40eba3166d.tar
gpt4free-f8e403a745c5caff31d7edb854dcba40eba3166d.tar.gz
gpt4free-f8e403a745c5caff31d7edb854dcba40eba3166d.tar.bz2
gpt4free-f8e403a745c5caff31d7edb854dcba40eba3166d.tar.lz
gpt4free-f8e403a745c5caff31d7edb854dcba40eba3166d.tar.xz
gpt4free-f8e403a745c5caff31d7edb854dcba40eba3166d.tar.zst
gpt4free-f8e403a745c5caff31d7edb854dcba40eba3166d.zip
Diffstat (limited to 'g4f/Provider/Blackbox.py')
-rw-r--r--g4f/Provider/Blackbox.py61
1 files changed, 47 insertions, 14 deletions
diff --git a/g4f/Provider/Blackbox.py b/g4f/Provider/Blackbox.py
index e607a43c..40696c82 100644
--- a/g4f/Provider/Blackbox.py
+++ b/g4f/Provider/Blackbox.py
@@ -1,7 +1,6 @@
from __future__ import annotations
import re
-import json
import random
import string
from aiohttp import ClientSession
@@ -25,22 +24,44 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
"llama-3.1-8b",
'llama-3.1-70b',
'llama-3.1-405b',
- 'ImageGenerationLV45LJp'
+ 'ImageGenerationLV45LJp',
+ 'GPT-4o',
+ 'Gemini-PRO',
+ 'Claude-Sonnet-3.5',
]
+
+ model_aliases = {
+ "gemini-flash": "gemini-1.5-flash",
+ "flux": "ImageGenerationLV45LJp",
+ "gpt-4o": "GPT-4o",
+ "gemini-pro": "Gemini-PRO",
+ "claude-3.5-sonnet": "Claude-Sonnet-3.5",
+ }
+
+ agentMode = {
+ 'ImageGenerationLV45LJp': {'mode': True, 'id': "ImageGenerationLV45LJp", 'name': "Image Generation"},
+ }
- model_config = {
+ trendingAgentMode = {
"blackbox": {},
"gemini-1.5-flash": {'mode': True, 'id': 'Gemini'},
"llama-3.1-8b": {'mode': True, 'id': "llama-3.1-8b"},
'llama-3.1-70b': {'mode': True, 'id': "llama-3.1-70b"},
'llama-3.1-405b': {'mode': True, 'id': "llama-3.1-405b"},
- 'ImageGenerationLV45LJp': {'mode': True, 'id': "ImageGenerationLV45LJp", 'name': "Image Generation"},
+ }
+
+ userSelectedModel = {
+ "GPT-4o": "GPT-4o",
+ "Gemini-PRO": "Gemini-PRO",
+ 'Claude-Sonnet-3.5': "Claude-Sonnet-3.5",
}
@classmethod
def get_model(cls, model: str) -> str:
if model in cls.models:
return model
+ elif model in cls.userSelectedModel:
+ return model
elif model in cls.model_aliases:
return cls.model_aliases[model]
else:
@@ -74,6 +95,11 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
"sec-fetch-site": "same-origin",
"user-agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36"
}
+
+ if model in cls.userSelectedModel:
+ prefix = f"@{cls.userSelectedModel[model]}"
+ if not messages[0]['content'].startswith(prefix):
+ messages[0]['content'] = f"{prefix} {messages[0]['content']}"
async with ClientSession(headers=headers) as session:
if image is not None:
@@ -92,21 +118,27 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
"codeModelMode": True,
"agentMode": {},
"trendingAgentMode": {},
+ "userSelectedModel": None,
"isMicMode": False,
- "maxTokens": None,
+ "maxTokens": 99999999,
+ "playgroundTopP": 0.9,
+ "playgroundTemperature": 0.5,
"isChromeExt": False,
"githubToken": None,
"clickedAnswer2": False,
"clickedAnswer3": False,
"clickedForceWebSearch": False,
"visitFromDelta": False,
- "mobileClient": False
+ "mobileClient": False,
+ "webSearchMode": False,
}
- if model == 'ImageGenerationLV45LJp':
- data["agentMode"] = cls.model_config[model]
- else:
- data["trendingAgentMode"] = cls.model_config[model]
+ if model in cls.agentMode:
+ data["agentMode"] = cls.agentMode[model]
+ elif model in cls.trendingAgentMode:
+ data["trendingAgentMode"] = cls.trendingAgentMode[model]
+ elif model in cls.userSelectedModel:
+ data["userSelectedModel"] = cls.userSelectedModel[model]
async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response:
response.raise_for_status()
@@ -119,9 +151,10 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
else:
raise Exception("Image URL not found in the response")
else:
- async for chunk in response.content:
+ async for chunk in response.content.iter_any():
if chunk:
decoded_chunk = chunk.decode()
- if decoded_chunk.startswith('$@$v=undefined-rv1$@$'):
- decoded_chunk = decoded_chunk[len('$@$v=undefined-rv1$@$'):]
- yield decoded_chunk
+ # Видаляємо префікс $@$v=v1.10-rv1$@$ та інші подібні
+ decoded_chunk = re.sub(r'\$@\$v=[^$]+\$@\$', '', decoded_chunk)
+ if decoded_chunk.strip(): # Перевіряємо, чи залишився якийсь текст після видалення префікса
+ yield decoded_chunk