summaryrefslogtreecommitdiffstats
path: root/g4f/client/service.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2024-11-16 13:19:51 +0100
committerGitHub <noreply@github.com>2024-11-16 13:19:51 +0100
commit6ce493d4dfc2884832ff5b5be4479a55818b2fe7 (patch)
tree92e9efce62f7832ebe56969c120d8e92e75881a3 /g4f/client/service.py
parentUpdate internet.py (diff)
downloadgpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.gz
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.bz2
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.lz
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.xz
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.tar.zst
gpt4free-6ce493d4dfc2884832ff5b5be4479a55818b2fe7.zip
Diffstat (limited to 'g4f/client/service.py')
-rw-r--r--g4f/client/service.py30
1 files changed, 16 insertions, 14 deletions
diff --git a/g4f/client/service.py b/g4f/client/service.py
index 5fdb150c..aa209b22 100644
--- a/g4f/client/service.py
+++ b/g4f/client/service.py
@@ -55,7 +55,6 @@ def get_model_and_provider(model : Union[Model, str],
provider = convert_to_provider(provider)
if isinstance(model, str):
-
if model in ModelUtils.convert:
model = ModelUtils.convert[model]
@@ -75,11 +74,11 @@ def get_model_and_provider(model : Union[Model, str],
if not ignore_working and not provider.working:
raise ProviderNotWorkingError(f'{provider.__name__} is not working')
- if not ignore_working and isinstance(provider, BaseRetryProvider):
- provider.providers = [p for p in provider.providers if p.working]
-
- if ignored and isinstance(provider, BaseRetryProvider):
- provider.providers = [p for p in provider.providers if p.__name__ not in ignored]
+ if isinstance(provider, BaseRetryProvider):
+ if not ignore_working:
+ provider.providers = [p for p in provider.providers if p.working]
+ if ignored:
+ provider.providers = [p for p in provider.providers if p.__name__ not in ignored]
if not ignore_stream and not provider.supports_stream and stream:
raise StreamNotSupportedError(f'{provider.__name__} does not support "stream" argument')
@@ -95,7 +94,7 @@ def get_model_and_provider(model : Union[Model, str],
return model, provider
-def get_last_provider(as_dict: bool = False) -> Union[ProviderType, dict[str, str]]:
+def get_last_provider(as_dict: bool = False) -> Union[ProviderType, dict[str, str], None]:
"""
Retrieves the last used provider.
@@ -108,11 +107,14 @@ def get_last_provider(as_dict: bool = False) -> Union[ProviderType, dict[str, st
last = debug.last_provider
if isinstance(last, BaseRetryProvider):
last = last.last_provider
- if last and as_dict:
- return {
- "name": last.__name__,
- "url": last.url,
- "model": debug.last_model,
- "label": last.label if hasattr(last, "label") else None
- }
+ if as_dict:
+ if last:
+ return {
+ "name": last.__name__,
+ "url": last.url,
+ "model": debug.last_model,
+ "label": getattr(last, "label", None) if hasattr(last, "label") else None
+ }
+ else:
+ return {}
return last \ No newline at end of file