diff options
Diffstat (limited to '')
-rw-r--r-- | g4f/gui/__init__.py | 3 | ||||
-rw-r--r-- | g4f/gui/gui_parser.py | 1 | ||||
-rw-r--r-- | g4f/gui/run.py | 6 | ||||
-rw-r--r-- | g4f/gui/server/api.py | 32 | ||||
-rw-r--r-- | g4f/gui/server/backend.py | 4 |
5 files changed, 39 insertions, 7 deletions
diff --git a/g4f/gui/__init__.py b/g4f/gui/__init__.py index f5e448ad..930a2aa0 100644 --- a/g4f/gui/__init__.py +++ b/g4f/gui/__init__.py @@ -12,9 +12,6 @@ def run_gui(host: str = '0.0.0.0', port: int = 8080, debug: bool = False) -> Non if import_error is not None: raise MissingRequirementsError(f'Install "gui" requirements | pip install -U g4f[gui]\n{import_error}') - if debug: - from g4f import debug - debug.logging = True config = { 'host' : host, 'port' : port, diff --git a/g4f/gui/gui_parser.py b/g4f/gui/gui_parser.py index ad458f5c..9fd70bef 100644 --- a/g4f/gui/gui_parser.py +++ b/g4f/gui/gui_parser.py @@ -5,4 +5,5 @@ def gui_parser(): parser.add_argument("-host", type=str, default="0.0.0.0", help="hostname") parser.add_argument("-port", type=int, default=8080, help="port") parser.add_argument("-debug", action="store_true", help="debug mode") + parser.add_argument("--ignore-cookie-files", action="store_true", help="Don't read .har and cookie files.") return parser
\ No newline at end of file diff --git a/g4f/gui/run.py b/g4f/gui/run.py index 91314d2d..9b1c527c 100644 --- a/g4f/gui/run.py +++ b/g4f/gui/run.py @@ -1,6 +1,12 @@ from .gui_parser import gui_parser +from ..cookies import read_cookie_files +import g4f.debug def run_gui_args(args): + if args.debug: + g4f.debug.logging = True + if not args.ignore_cookie_files: + read_cookie_files() from g4f.gui import run_gui host = args.host port = args.port diff --git a/g4f/gui/server/api.py b/g4f/gui/server/api.py index 47c25eb7..3d9f6a1c 100644 --- a/g4f/gui/server/api.py +++ b/g4f/gui/server/api.py @@ -16,7 +16,8 @@ conversations: dict[dict[str, BaseConversation]] = {} class Api(): - def get_models(self) -> list[str]: + @staticmethod + def get_models() -> list[str]: """ Return a list of all models. @@ -27,7 +28,8 @@ class Api(): """ return models._all_models - def get_provider_models(self, provider: str) -> list[dict]: + @staticmethod + def get_provider_models(provider: str) -> list[dict]: if provider in __map__: provider: ProviderType = __map__[provider] if issubclass(provider, ProviderModelMixin): @@ -40,7 +42,28 @@ class Api(): else: return []; - def get_providers(self) -> list[str]: + @staticmethod + def get_image_models() -> list[dict]: + image_models = [] + for provider in __providers__: + if hasattr(provider, "image_models"): + if hasattr(provider, "get_models"): + provider.get_models() + parent = provider + if hasattr(provider, "parent"): + parent = __map__[provider.parent] + for model in provider.image_models: + image_models.append({ + "provider": parent.__name__, + "url": parent.url, + "label": parent.label if hasattr(parent, "label") else None, + "image_model": model, + "vision_model": parent.default_vision_model if hasattr(parent, "default_vision_model") else None + }) + return image_models + + @staticmethod + def get_providers() -> list[str]: """ Return a list of all working providers. """ @@ -58,7 +81,8 @@ class Api(): if provider.working } - def get_version(self): + @staticmethod + def get_version(): """ Returns the current and latest version of the application. diff --git a/g4f/gui/server/backend.py b/g4f/gui/server/backend.py index d30b97d9..d9e31c0e 100644 --- a/g4f/gui/server/backend.py +++ b/g4f/gui/server/backend.py @@ -31,6 +31,10 @@ class Backend_Api(Api): 'function': self.get_provider_models, 'methods': ['GET'] }, + '/backend-api/v2/image_models': { + 'function': self.get_image_models, + 'methods': ['GET'] + }, '/backend-api/v2/providers': { 'function': self.get_providers, 'methods': ['GET'] |