summaryrefslogtreecommitdiffstats
path: root/g4f/__init__.py
diff options
context:
space:
mode:
authorCommenter123321 <36051603+Commenter123321@users.noreply.github.com>2023-10-10 14:15:12 +0200
committerCommenter123321 <36051603+Commenter123321@users.noreply.github.com>2023-10-10 14:15:12 +0200
commit0e4297494dd46533738f786e4ac675541586177a (patch)
tree6c2999e14ed831f7f37cc60991571cd040772918 /g4f/__init__.py
parentadd cool testing for gpt-3.5 and and gpt-4 (diff)
parentUpdate Aivvm.py (diff)
downloadgpt4free-0e4297494dd46533738f786e4ac675541586177a.tar
gpt4free-0e4297494dd46533738f786e4ac675541586177a.tar.gz
gpt4free-0e4297494dd46533738f786e4ac675541586177a.tar.bz2
gpt4free-0e4297494dd46533738f786e4ac675541586177a.tar.lz
gpt4free-0e4297494dd46533738f786e4ac675541586177a.tar.xz
gpt4free-0e4297494dd46533738f786e4ac675541586177a.tar.zst
gpt4free-0e4297494dd46533738f786e4ac675541586177a.zip
Diffstat (limited to 'g4f/__init__.py')
-rw-r--r--g4f/__init__.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/g4f/__init__.py b/g4f/__init__.py
index 4b1e4b80..fa20f6eb 100644
--- a/g4f/__init__.py
+++ b/g4f/__init__.py
@@ -2,10 +2,10 @@ from __future__ import annotations
from requests import get
from g4f.models import Model, ModelUtils
from .Provider import BaseProvider
-from .typing import CreateResult, Union
+from .typing import Messages, CreateResult, Union
from .debug import logging
-version = '0.1.5.6'
+version = '0.1.5.7'
version_check = True
def check_pypi_version() -> None:
@@ -27,19 +27,19 @@ def get_model_and_provider(model : Union[Model, str],
if model in ModelUtils.convert:
model = ModelUtils.convert[model]
else:
- raise Exception(f'The model: {model} does not exist')
+ raise ValueError(f'The model: {model} does not exist')
if not provider:
provider = model.best_provider
if not provider:
- raise Exception(f'No provider found for model: {model}')
+ raise RuntimeError(f'No provider found for model: {model}')
if not provider.working:
- raise Exception(f'{provider.__name__} is not working')
+ raise RuntimeError(f'{provider.__name__} is not working')
if not provider.supports_stream and stream:
- raise Exception(f'ValueError: {provider.__name__} does not support "stream" argument')
+ raise ValueError(f'{provider.__name__} does not support "stream" argument')
if logging:
print(f'Using {provider.__name__} provider')
@@ -48,17 +48,20 @@ def get_model_and_provider(model : Union[Model, str],
class ChatCompletion:
@staticmethod
- def create(model: Union[Model, str],
- messages : list[dict[str, str]],
+ def create(
+ model: Union[Model, str],
+ messages : Messages,
provider : Union[type[BaseProvider], None] = None,
stream : bool = False,
- auth : Union[str, None] = None, **kwargs) -> Union[CreateResult, str]:
+ auth : Union[str, None] = None,
+ **kwargs
+ ) -> Union[CreateResult, str]:
model, provider = get_model_and_provider(model, provider, stream)
if provider.needs_auth and not auth:
- raise Exception(
- f'ValueError: {provider.__name__} requires authentication (use auth=\'cookie or token or jwt ...\' param)')
+ raise ValueError(
+ f'{provider.__name__} requires authentication (use auth=\'cookie or token or jwt ...\' param)')
if provider.needs_auth:
kwargs['auth'] = auth
@@ -69,10 +72,14 @@ class ChatCompletion:
@staticmethod
async def create_async(
model: Union[Model, str],
- messages: list[dict[str, str]],
+ messages: Messages,
provider: Union[type[BaseProvider], None] = None,
+ stream: bool = False,
**kwargs
) -> str:
+ if stream:
+ raise ValueError(f'"create_async" does not support "stream" argument')
+
model, provider = get_model_and_provider(model, provider, False)
return await provider.create_async(model.name, messages, **kwargs)