diff options
author | Tekky <98614666+xtekky@users.noreply.github.com> | 2023-11-20 19:27:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-20 19:27:38 +0100 |
commit | e8d88c955f75f539dd71bd4b713e90094751161c (patch) | |
tree | 6d1ad2636abfd7ad0b4f5a59aa4630cf2a29723e /g4f/Provider/base_provider.py | |
parent | Merge pull request #1275 from egcash/patch-1 (diff) | |
parent | Merge branch 'main' into webdriver (diff) | |
download | gpt4free-e8d88c955f75f539dd71bd4b713e90094751161c.tar gpt4free-e8d88c955f75f539dd71bd4b713e90094751161c.tar.gz gpt4free-e8d88c955f75f539dd71bd4b713e90094751161c.tar.bz2 gpt4free-e8d88c955f75f539dd71bd4b713e90094751161c.tar.lz gpt4free-e8d88c955f75f539dd71bd4b713e90094751161c.tar.xz gpt4free-e8d88c955f75f539dd71bd4b713e90094751161c.tar.zst gpt4free-e8d88c955f75f539dd71bd4b713e90094751161c.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/Provider/base_provider.py | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/g4f/Provider/base_provider.py b/g4f/Provider/base_provider.py index 47ea6ff8..564dd77e 100644 --- a/g4f/Provider/base_provider.py +++ b/g4f/Provider/base_provider.py @@ -3,6 +3,8 @@ from __future__ import annotations from asyncio import AbstractEventLoop from concurrent.futures import ThreadPoolExecutor from abc import ABC, abstractmethod +from inspect import signature, Parameter +from types import NoneType from .helper import get_event_loop, get_cookies, format_prompt from ..typing import CreateResult, AsyncResult, Messages @@ -52,17 +54,42 @@ class BaseProvider(ABC): executor, create_func ) - + @classmethod @property def params(cls) -> str: - params = [ - ("model", "str"), - ("messages", "list[dict[str, str]]"), - ("stream", "bool"), - ] - param = ", ".join([": ".join(p) for p in params]) - return f"g4f.provider.{cls.__name__} supports: ({param})" + if issubclass(cls, AsyncGeneratorProvider): + sig = signature(cls.create_async_generator) + elif issubclass(cls, AsyncProvider): + sig = signature(cls.create_async) + else: + sig = signature(cls.create_completion) + + def get_type_name(annotation: type) -> str: + if hasattr(annotation, "__name__"): + annotation = annotation.__name__ + elif isinstance(annotation, NoneType): + annotation = "None" + return str(annotation) + + args = ""; + for name, param in sig.parameters.items(): + if name in ("self", "kwargs"): + continue + if name == "stream" and not cls.supports_stream: + continue + if args: + args += ", " + args += "\n" + args += " " + name + if name != "model" and param.annotation is not Parameter.empty: + args += f": {get_type_name(param.annotation)}" + if param.default == "": + args += ' = ""' + elif param.default is not Parameter.empty: + args += f" = {param.default}" + + return f"g4f.Provider.{cls.__name__} supports: ({args}\n)" class AsyncProvider(BaseProvider): |