summaryrefslogtreecommitdiffstats
path: root/g4f/base_provider.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-01-02 01:10:31 +0100
committerGitHub <noreply@github.com>2024-01-02 01:10:31 +0100
commitb1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366 (patch)
tree6cd09fb2eb4c144e28a82759a2a9a2fa7f30d311 /g4f/base_provider.py
parentMerge pull request #1414 from hlohaus/lia (diff)
parentFix markdown replace (diff)
downloadgpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar
gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar.gz
gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar.bz2
gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar.lz
gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar.xz
gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.tar.zst
gpt4free-b1b8ed40a4e8c7c3490b1c6b7cf6b55d0776f366.zip
Diffstat (limited to 'g4f/base_provider.py')
-rw-r--r--g4f/base_provider.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/g4f/base_provider.py b/g4f/base_provider.py
new file mode 100644
index 00000000..84cbc384
--- /dev/null
+++ b/g4f/base_provider.py
@@ -0,0 +1,54 @@
+from abc import ABC, abstractmethod
+from .typing import Messages, CreateResult, Union
+
+class BaseProvider(ABC):
+ url: str
+ working: bool = False
+ needs_auth: bool = False
+ supports_stream: bool = False
+ supports_gpt_35_turbo: bool = False
+ supports_gpt_4: bool = False
+ supports_message_history: bool = False
+ params: str
+
+ @classmethod
+ @abstractmethod
+ def create_completion(
+ cls,
+ model: str,
+ messages: Messages,
+ stream: bool,
+ **kwargs
+ ) -> CreateResult:
+ raise NotImplementedError()
+
+ @classmethod
+ @abstractmethod
+ async def create_async(
+ cls,
+ model: str,
+ messages: Messages,
+ **kwargs
+ ) -> str:
+ raise NotImplementedError()
+
+ @classmethod
+ def get_dict(cls):
+ return {'name': cls.__name__, 'url': cls.url}
+
+class BaseRetryProvider(BaseProvider):
+ __name__: str = "RetryProvider"
+ supports_stream: bool = True
+
+ def __init__(
+ self,
+ providers: list[type[BaseProvider]],
+ shuffle: bool = True
+ ) -> None:
+ self.providers: list[type[BaseProvider]] = providers
+ self.shuffle: bool = shuffle
+ self.working: bool = True
+ self.exceptions: dict[str, Exception] = {}
+ self.last_provider: type[BaseProvider] = None
+
+ProviderType = Union[type[BaseProvider], BaseRetryProvider] \ No newline at end of file