feat(g4f/Provider/Blackbox.py): enhance vision image handling

This commit is contained in:
kqlio67 2024-10-12 22:56:06 +03:00
parent 3119b8e37e
commit 9c3190d11c

View File

@ -17,23 +17,23 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
supports_stream = True supports_stream = True
supports_system_message = True supports_system_message = True
supports_message_history = True supports_message_history = True
default_model = 'blackboxai' default_model = 'blackboxai'
models = [ models = [
default_model, default_model,
'blackboxai-pro', 'blackboxai-pro',
"llama-3.1-8b", "llama-3.1-8b",
'llama-3.1-70b', 'llama-3.1-70b',
'llama-3.1-405b', 'llama-3.1-405b',
'gpt-4o', 'gpt-4o',
'gemini-pro', 'gemini-pro',
'gemini-1.5-flash', 'gemini-1.5-flash',
'claude-sonnet-3.5', 'claude-sonnet-3.5',
'PythonAgent', 'PythonAgent',
'JavaAgent', 'JavaAgent',
'JavaScriptAgent', 'JavaScriptAgent',
@ -89,7 +89,7 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
'PythonAgent': '@Python Agent', 'PythonAgent': '@Python Agent',
'JavaAgent': '@Java Agent', 'JavaAgent': '@Java Agent',
'JavaScriptAgent': '@Java Agent', 'JavaScriptAgent': '@JavaScript Agent',
'HTMLAgent': '@HTML Agent', 'HTMLAgent': '@HTML Agent',
'GoogleCloudAgent': '@Google Cloud Agent', 'GoogleCloudAgent': '@Google Cloud Agent',
'AndroidDeveloper': '@Android Developer', 'AndroidDeveloper': '@Android Developer',
@ -163,46 +163,50 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
if not messages[0]['content'].startswith(prefix): if not messages[0]['content'].startswith(prefix):
messages[0]['content'] = f"{prefix} {messages[0]['content']}" messages[0]['content'] = f"{prefix} {messages[0]['content']}"
async with ClientSession(headers=headers) as session: random_id = ''.join(random.choices(string.ascii_letters + string.digits, k=7))
if image is not None: messages[-1]['id'] = random_id
messages[-1]["data"] = { messages[-1]['role'] = 'user'
"fileText": image_name,
"imageBase64": to_data_uri(image)
}
random_id = ''.join(random.choices(string.ascii_letters + string.digits, k=7))
data = { if image is not None:
"messages": messages, messages[-1]['data'] = {
"id": random_id, 'fileText': '',
"previewToken": None, 'imageBase64': to_data_uri(image),
"userId": None, 'title': image_name
"codeModelMode": True,
"agentMode": {},
"trendingAgentMode": {},
"isMicMode": False,
"userSystemPrompt": None,
"maxTokens": 1024,
"playgroundTopP": 0.9,
"playgroundTemperature": 0.5,
"isChromeExt": False,
"githubToken": None,
"clickedAnswer2": False,
"clickedAnswer3": False,
"clickedForceWebSearch": False,
"visitFromDelta": False,
"mobileClient": False,
"userSelectedModel": None,
"webSearchMode": webSearchMode,
} }
messages[-1]['content'] = 'FILE:BB\n$#$\n\n$#$\n' + messages[-1]['content']
data = {
"messages": messages,
"id": random_id,
"previewToken": None,
"userId": None,
"codeModelMode": True,
"agentMode": {},
"trendingAgentMode": {},
"isMicMode": False,
"userSystemPrompt": None,
"maxTokens": 1024,
"playgroundTopP": 0.9,
"playgroundTemperature": 0.5,
"isChromeExt": False,
"githubToken": None,
"clickedAnswer2": False,
"clickedAnswer3": False,
"clickedForceWebSearch": False,
"visitFromDelta": False,
"mobileClient": False,
"userSelectedModel": None,
"webSearchMode": webSearchMode,
}
if model in cls.agentMode: if model in cls.agentMode:
data["agentMode"] = cls.agentMode[model] data["agentMode"] = cls.agentMode[model]
elif model in cls.trendingAgentMode: elif model in cls.trendingAgentMode:
data["trendingAgentMode"] = cls.trendingAgentMode[model] data["trendingAgentMode"] = cls.trendingAgentMode[model]
elif model in cls.userSelectedModel: elif model in cls.userSelectedModel:
data["userSelectedModel"] = cls.userSelectedModel[model] data["userSelectedModel"] = cls.userSelectedModel[model]
async with ClientSession(headers=headers) as session:
async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response: async with session.post(cls.api_endpoint, json=data, proxy=proxy) as response:
response.raise_for_status() response.raise_for_status()
if model == 'ImageGeneration': if model == 'ImageGeneration':