summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/base_provider.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-23 19:44:48 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-01-23 19:44:48 +0100
commit91feb34054f529c37e10d98d2471c8c0c6780147 (patch)
tree8708fc00fe39d8756a16f14b10b4f4fc29eb4877 /g4f/Provider/base_provider.py
parentUpload transparency image (diff)
downloadgpt4free-91feb34054f529c37e10d98d2471c8c0c6780147.tar
gpt4free-91feb34054f529c37e10d98d2471c8c0c6780147.tar.gz
gpt4free-91feb34054f529c37e10d98d2471c8c0c6780147.tar.bz2
gpt4free-91feb34054f529c37e10d98d2471c8c0c6780147.tar.lz
gpt4free-91feb34054f529c37e10d98d2471c8c0c6780147.tar.xz
gpt4free-91feb34054f529c37e10d98d2471c8c0c6780147.tar.zst
gpt4free-91feb34054f529c37e10d98d2471c8c0c6780147.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/base_provider.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/g4f/Provider/base_provider.py b/g4f/Provider/base_provider.py
index bc47a1fa..e1dcd24d 100644
--- a/g4f/Provider/base_provider.py
+++ b/g4f/Provider/base_provider.py
@@ -8,7 +8,7 @@ from inspect import signature, Parameter
from .helper import get_cookies, format_prompt
from ..typing import CreateResult, AsyncResult, Messages, Union
from ..base_provider import BaseProvider
-from ..errors import NestAsyncioError
+from ..errors import NestAsyncioError, ModelNotSupportedError
if sys.version_info < (3, 10):
NoneType = type(None)
@@ -251,4 +251,23 @@ class AsyncGeneratorProvider(AsyncProvider):
Returns:
AsyncResult: An asynchronous generator yielding results.
"""
- raise NotImplementedError() \ No newline at end of file
+ raise NotImplementedError()
+
+class ProviderModelMixin:
+ default_model: str
+ models: list[str] = []
+ model_aliases: dict[str, str] = {}
+
+ @classmethod
+ def get_models(cls) -> list[str]:
+ return cls.models
+
+ @classmethod
+ def get_model(cls, model: str) -> str:
+ if not model:
+ return cls.default_model
+ elif model in cls.model_aliases:
+ return cls.model_aliases[model]
+ elif model not in cls.get_models():
+ raise ModelNotSupportedError(f"Model is not supported: {model} in: {cls.__name__}")
+ return model \ No newline at end of file