diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-03-13 17:52:48 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-03-13 17:52:48 +0100 |
commit | 13f1275ca307d77542708c83066ef2fe86f6284a (patch) | |
tree | fbca675486633937b2c94fde11bc5c2b17a4c24d /g4f/gui/server/backend.py | |
parent | Merge pull request #1684 from hlohaus/retry (diff) | |
download | gpt4free-13f1275ca307d77542708c83066ef2fe86f6284a.tar gpt4free-13f1275ca307d77542708c83066ef2fe86f6284a.tar.gz gpt4free-13f1275ca307d77542708c83066ef2fe86f6284a.tar.bz2 gpt4free-13f1275ca307d77542708c83066ef2fe86f6284a.tar.lz gpt4free-13f1275ca307d77542708c83066ef2fe86f6284a.tar.xz gpt4free-13f1275ca307d77542708c83066ef2fe86f6284a.tar.zst gpt4free-13f1275ca307d77542708c83066ef2fe86f6284a.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/gui/server/backend.py | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/g4f/gui/server/backend.py b/g4f/gui/server/backend.py index 454ed1c6..e9617c07 100644 --- a/g4f/gui/server/backend.py +++ b/g4f/gui/server/backend.py @@ -6,10 +6,11 @@ from g4f import version, models from g4f import get_last_provider, ChatCompletion from g4f.image import is_allowed_extension, to_image from g4f.errors import VersionNotFoundError -from g4f.Provider import __providers__ +from g4f.Provider import ProviderType, __providers__, __map__ +from g4f.providers.base_provider import ProviderModelMixin from g4f.Provider.bing.create_images import patch_provider -class Backend_Api: +class Backend_Api: """ Handles various endpoints in a Flask application for backend operations. @@ -33,6 +34,10 @@ class Backend_Api: 'function': self.get_models, 'methods': ['GET'] }, + '/backend-api/v2/models/<provider>': { + 'function': self.get_provider_models, + 'methods': ['GET'] + }, '/backend-api/v2/providers': { 'function': self.get_providers, 'methods': ['GET'] @@ -75,7 +80,21 @@ class Backend_Api: List[str]: A list of model names. """ return models._all_models - + + def get_provider_models(self, provider: str): + if provider in __map__: + provider: ProviderType = __map__[provider] + if issubclass(provider, ProviderModelMixin): + return [{"model": model, "default": model == provider.default_model} for model in provider.get_models()] + elif provider.supports_gpt_35_turbo or provider.supports_gpt_4: + return [ + *([{"model": "gpt-3.5-turbo", "default": not provider.supports_gpt_4}] if provider.supports_gpt_35_turbo else []), + *([{"model": "gpt-4", "default": not provider.supports_gpt_4}] if provider.supports_gpt_4 else []) + ] + else: + return []; + return 404, "Provider not found" + def get_providers(self): """ Return a list of all working providers. |