返回提交历史
Modified
g4f/Provider/Blackbox.py
+24
-16
XFEstudio/gpt4free
fix(g4f/Provider/Blackbox.py): update model handling and premium authentication
3f26a719
代码差异
1 个文件
+24
-16
@@ -39,13 +39,11 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
39
39
default_model = "blackboxai"
40
40
default_vision_model = default_model
41
41
default_image_model = 'ImageGeneration'
42
image_models = [default_image_model]
43
42
44
premium_models = ['claude-sonnet-3.5']
45
46
vision_models = [default_vision_model, 'gpt-4o', 'o3-mini', 'gemini-pro', 'gemini-1.5-flash', 'llama-3.1-8b', 'llama-3.1-70b', 'llama-3.1-405b', 'Gemini-Flash-2.0']
43
image_models = [default_image_model]
44
vision_models = [default_vision_model, 'GPT-4o', 'o3-mini', 'Gemini-PRO', 'gemini-1.5-flash', 'llama-3.1-8b', 'llama-3.1-70b', 'llama-3.1-405b', 'Gemini-Flash-2.0']
47
45
48
userSelectedModel = ['gpt-4o', 'o3-mini', 'gemini-pro', 'DeepSeek-V3', 'DeepSeek-R1', 'blackboxai-pro', 'Meta-Llama-3.3-70B-Instruct-Turbo', 'Mistral-Small-24B-Instruct-2501', 'DeepSeek-LLM-Chat-(67B)', 'DBRX-Instruct', 'Qwen-QwQ-32B-Preview', 'Nous-Hermes-2-Mixtral-8x7B-DPO', 'Gemini-Flash-2.0'] + premium_models
46
userSelectedModel = ['GPT-4o', 'o3-mini', 'Gemini-PRO', 'Claude-Sonnet-3.5', 'DeepSeek-V3', 'DeepSeek-R1', 'blackboxai-pro', 'Meta-Llama-3.3-70B-Instruct-Turbo', 'Mistral-Small-24B-Instruct-2501', 'DeepSeek-LLM-Chat-(67B)', 'DBRX-Instruct', 'Qwen-QwQ-32B-Preview', 'Nous-Hermes-2-Mixtral-8x7B-DPO', 'Gemini-Flash-2.0']
49
47
50
48
agentMode = {
51
49
'DeepSeek-V3': {'mode': True, 'id': "deepseek-chat", 'name': "DeepSeek-V3"},
@@ -99,13 +97,15 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
99
97
'builder Agent': {'mode': True, 'id': "builder Agent"},
100
98
}
101
99
100
premium_models = ['Claude-Sonnet-3.5']
101
102
102
models = list(dict.fromkeys([default_model, *userSelectedModel, *image_models, *list(agentMode.keys()), *list(trendingAgentMode.keys())]))
103
103
104
104
model_aliases = {
105
"gpt-4": "gpt-4o",
106
"claude-3.5-sonnet": "claude-sonnet-3.5", # Premium
105
"gpt-4": "GPT-4o",
106
"claude-3.5-sonnet": "Claude-Sonnet-3.5", # Premium
107
107
"gemini-1.5-flash": "gemini-1.5-flash",
108
"gemini-1.5-pro": "gemini-pro",
108
"gemini-1.5-pro": "Gemini-PRO",
109
109
"deepseek-v3": "DeepSeek-V3",
110
110
"deepseek-r1": "DeepSeek-R1",
111
111
"llama-3.3-70b": "Meta-Llama-3.3-70B-Instruct-Turbo",
@@ -121,19 +121,19 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
121
121
@classmethod
122
122
def get_models(cls) -> list[str]:
123
123
models = super().get_models()
124
return [f"{m} (Premium)" for m in models if m in cls.premium_models] + models
124
filtered = [m for m in models if m not in cls.premium_models]
125
filtered += [f"{m} (Premium)" for m in cls.premium_models]
126
return filtered
125
127
126
128
@classmethod
127
129
def get_model(cls, model: str, **kwargs) -> str:
128
if model.endswith(" (Premium)"):
129
raise ModelNotSupportedError(f"Model {model} is not supported")
130
130
try:
131
model = super().get_model(model, **kwargs)
132
return model.split(" (Premium)")[0]
133
except ModelNotSupportedError:
131
134
base_model = model.split(" (Premium)")[0]
132
135
if base_model in cls.premium_models:
133
136
return base_model
134
return super().get_model(base_model, **kwargs)
135
136
except ModelNotSupportedError:
137
137
raise
138
138
139
139
@classmethod
@@ -278,6 +278,14 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
278
278
"title": ""
279
279
}
280
280
281
# Calculate the value for expires + lastChecked
282
expires_iso = datetime.now(timezone.utc).isoformat(timespec='milliseconds').replace('+00:00', 'Z')
283
last_checked_millis = int(datetime.now().timestamp() * 1000)
284
285
# Fake data of a premium user (temporarily working)
286
fake_session = {"user":{"name":"John Doe","email":"john.doe@gmail.com","image":"https://lh3.googleusercontent.com/a/ACg8ocK9X7mNpQ2vR4jH3tY8wL5nB1xM6fDS9JW2kLpTn4Vy3hR2xN4m=s96-c"},"expires":expires_iso}
287
fake_subscriptionCache = {"status":"PREMIUM", "expiryTimestamp":None,"lastChecked":last_checked_millis}
288
281
289
data = {
282
290
"messages": current_messages,
283
291
"agentMode": cls.agentMode.get(model, {}) if model in cls.agentMode else {},
@@ -308,9 +316,9 @@ class Blackbox(AsyncGeneratorProvider, ProviderModelMixin):
308
316
"vscodeClient": False,
309
317
"codeInterpreterMode": False,
310
318
"customProfile": {"name": "", "occupation": "", "traits": [], "additionalInfo": "", "enableNewChats": False},
311
"session": {"user":{"name":"John Doe","email":"john.doe@gmail.com","image":"https://lh3.googleusercontent.com/a/ACg8ocK9X7mNpQ2vR4jH3tY8wL5nB1xM6fDS9JW2kLpTn4Vy3hR2xN4m=s96-c"},"expires":datetime.now(timezone.utc).isoformat(timespec='milliseconds').replace('+00:00', 'Z')},
319
"session": fake_session,
312
320
"isPremium": True,
313
"subscriptionCache": None,
321
"subscriptionCache": fake_subscriptionCache,
314
322
"webSearchMode": False
315
323
}
316
324