返回提交历史
Modified
g4f/Provider/PollinationsAI.py
+1
-0
Modified
g4f/Provider/needs_auth/LMArena.py
+2
-0
Modified
g4f/Provider/template/OpenaiTemplate.py
+1
-1
Modified
g4f/providers/base_provider.py
+5
-0
XFEstudio/gpt4free
Track live model instances in PollinationsAI, LMArena, OpenaiTemplate, and base_provider classes
5bfea461
代码差异
4 个文件
+9
-1
@@ -155,6 +155,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
155
155
cls.model_aliases[alias] = model.get("name")
156
156
elif model.get("name") not in cls.text_models:
157
157
cls.text_models.append(model.get("name"))
158
cls.live += 1
158
159
159
160
except Exception as e:
160
161
# Save default models in case of an error
@@ -485,8 +485,10 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
485
485
cls.models = list(cls.text_models) + list(cls.image_models)
486
486
cls.default_model = list(cls.text_models.keys())[0]
487
487
cls._models_loaded = True
488
cls.live += 1
488
489
break
489
490
else:
491
cls.live -= 1
490
492
debug.log(f"Failed to load models from {cls.url}: {response.status_code} {response.reason}")
491
493
return cls.models
492
494
@@ -49,7 +49,7 @@ class OpenaiTemplate(AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
49
49
raise_for_status(response)
50
50
data = response.json()
51
51
data = data.get("data") if isinstance(data, dict) else data
52
if data:
52
if (not cls.needs_auth or cls.models_needs_auth) and data:
53
53
cls.live += 1
54
54
cls.image_models = [model.get("name") if cls.use_model_names else model.get("id", model.get("name")) for model in data if model.get("image") or model.get("type") == "image" or model.get("supports_images")]
55
55
cls.vision_models = cls.vision_models.copy()
@@ -371,11 +371,16 @@ class ProviderModelMixin:
371
371
video_models: list = []
372
372
audio_models: dict = {}
373
373
last_model: str = None
374
models_loaded: bool = False
374
375
375
376
@classmethod
376
377
def get_models(cls, **kwargs) -> list[str]:
377
378
if not cls.models and cls.default_model is not None:
378
379
cls.models = [cls.default_model]
380
if not cls.models_loaded and hasattr(cls, "get_cache_file"):
381
if cls.get_cache_file().exists():
382
cls.live += 1
383
cls.models_loaded = True
379
384
return cls.models
380
385
381
386
@classmethod