mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-06 02:30:41 -08:00
Track live model instances in PollinationsAI, LMArena, OpenaiTemplate, and base_provider classes
This commit is contained in:
parent
1cbf9dfb6a
commit
5bfea4611a
4 changed files with 9 additions and 1 deletions
|
|
@ -155,6 +155,7 @@ class PollinationsAI(AsyncGeneratorProvider, ProviderModelMixin):
|
|||
cls.model_aliases[alias] = model.get("name")
|
||||
elif model.get("name") not in cls.text_models:
|
||||
cls.text_models.append(model.get("name"))
|
||||
cls.live += 1
|
||||
|
||||
except Exception as e:
|
||||
# Save default models in case of an error
|
||||
|
|
|
|||
|
|
@ -485,8 +485,10 @@ class LMArena(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
|
|||
cls.models = list(cls.text_models) + list(cls.image_models)
|
||||
cls.default_model = list(cls.text_models.keys())[0]
|
||||
cls._models_loaded = True
|
||||
cls.live += 1
|
||||
break
|
||||
else:
|
||||
cls.live -= 1
|
||||
debug.log(f"Failed to load models from {cls.url}: {response.status_code} {response.reason}")
|
||||
return cls.models
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class OpenaiTemplate(AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
|
|||
raise_for_status(response)
|
||||
data = response.json()
|
||||
data = data.get("data") if isinstance(data, dict) else data
|
||||
if data:
|
||||
if (not cls.needs_auth or cls.models_needs_auth) and data:
|
||||
cls.live += 1
|
||||
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")]
|
||||
cls.vision_models = cls.vision_models.copy()
|
||||
|
|
|
|||
|
|
@ -371,11 +371,16 @@ class ProviderModelMixin:
|
|||
video_models: list = []
|
||||
audio_models: dict = {}
|
||||
last_model: str = None
|
||||
models_loaded: bool = False
|
||||
|
||||
@classmethod
|
||||
def get_models(cls, **kwargs) -> list[str]:
|
||||
if not cls.models and cls.default_model is not None:
|
||||
cls.models = [cls.default_model]
|
||||
if not cls.models_loaded and hasattr(cls, "get_cache_file"):
|
||||
if cls.get_cache_file().exists():
|
||||
cls.live += 1
|
||||
cls.models_loaded = True
|
||||
return cls.models
|
||||
|
||||
@classmethod
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue