XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Fix special models in PuterJS

7178ff92
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +16 -13
Modified g4f/Provider/needs_auth/PuterJS.py +16 -13
@@ -28,8 +28,6 @@ class PuterJS(AsyncGeneratorProvider, ProviderModelMixin):
28 28 claude_models = ["claude-3-7-sonnet-20250219", "claude-3-7-sonnet-latest", "claude-3-5-sonnet-20241022", "claude-3-5-sonnet-latest", "claude-3-5-sonnet-20240620", "claude-3-haiku-20240307"]
29 29 mistral_models = ["ministral-3b-2410","ministral-3b-latest","ministral-8b-2410","ministral-8b-latest","open-mistral-7b","mistral-tiny","mistral-tiny-2312","open-mixtral-8x7b","mistral-small","mistral-small-2312","open-mixtral-8x22b","open-mixtral-8x22b-2404","mistral-large-2411","mistral-large-latest","pixtral-large-2411","pixtral-large-latest","mistral-large-pixtral-2411","codestral-2501","codestral-latest","codestral-2412","codestral-2411-rc5","pixtral-12b-2409","pixtral-12b","pixtral-12b-latest","mistral-small-2503","mistral-small-latest"]
30 30 xai_models = ["grok-beta", "grok-vision-beta"]
31 deepseek_models = ["deepseek-chat","deepseek-reasoner"]
32 gemini_models = ["gemini-1.5-flash","gemini-2.0-flash"]
33 31 model_aliases = {
34 32 ### mistral_models ###
35 33 "mixtral-8x22b": ["open-mixtral-8x22b", "open-mixtral-8x22b-2404"],
@@ -260,7 +258,7 @@ class PuterJS(AsyncGeneratorProvider, ProviderModelMixin):
260 258 }
261 259
262 260 @classmethod
263 def get_models(cls, api_key: str = None) -> list[str]:
261 def get_models(cls, **kwargs) -> list[str]:
264 262 if not cls.models:
265 263 try:
266 264 url = "https://api.puter.com/puterai/chat/models/"
@@ -268,7 +266,8 @@ class PuterJS(AsyncGeneratorProvider, ProviderModelMixin):
268 266 cls.models = [model for model in cls.models if model not in ["abuse", "costly", "fake"]]
269 267 except Exception as e:
270 268 debug.log(f"PuterJS: Failed to fetch models from API: {e}")
271 cls.models = list(cls.model_aliases.keys())
269 cls.models = []
270 cls.models += [model for model in cls.model_aliases.keys() if model not in cls.models]
272 271 cls.vision_models = []
273 272 for model in cls.models:
274 273 for tag in ["vision", "multimodal", "gpt", "o1", "o3", "o4"]:
@@ -287,12 +286,12 @@ class PuterJS(AsyncGeneratorProvider, ProviderModelMixin):
287 286 return "mistral"
288 287 elif model in PuterJS.xai_models:
289 288 return "xai"
290 elif model in PuterJS.deepseek_models:
291 return "deepseek"
292 elif model in PuterJS.gemini_models:
293 return "gemini"
294 289 elif "openrouter:" in model:
295 290 return "openrouter"
291 elif "deepseek" in model:
292 return "deepseek"
293 elif "gemini" in model:
294 return "gemini"
296 295 else:
297 296 # Default to OpenAI for unknown models
298 297 return "openai-completion"
@@ -303,10 +302,6 @@ class PuterJS(AsyncGeneratorProvider, ProviderModelMixin):
303 302
304 303 if not model:
305 304 return cls.default_model
306
307 # Check if the model exists directly in our models list
308 if model in cls.models:
309 return model
310 305
311 306 # Check if there's an alias for this model
312 307 if model in cls.model_aliases:
@@ -319,6 +314,10 @@ class PuterJS(AsyncGeneratorProvider, ProviderModelMixin):
319 314 debug.log(f"PuterJS: Using model '{alias}' for alias '{model}'")
320 315 return alias
321 316
317 # Check if the model exists directly in our models list
318 if model in cls.models:
319 return model
320
322 321 raise ModelNotFoundError(f"Model {model} not found")
323 322
324 323 @classmethod
@@ -432,7 +431,11 @@ class PuterJS(AsyncGeneratorProvider, ProviderModelMixin):
432 431 raise ResponseError(result)
433 432 message = choice.get("message", {})
434 433 content = message.get("content", "")
435 if content:
434 if isinstance(content, list):
435 for item in content:
436 if item.get("type") == "text":
437 yield item.get("text", "")
438 elif content:
436 439 yield content
437 440 if "tool_calls" in message:
438 441 yield ToolCalls(message["tool_calls"])