fix: improve error handling and add type checks in various providers and API

- Updated error handling in g4f/Provider/DDG.py to raise ResponseError instead of yield error strings
- Replaced yield statements with raises in g4f/Provider/DDG.py for HTTP and response errors
- Added response raising in g4f/Provider/DeepInfraChat.py for image upload responses
- Included model alias validation and error raising in g4f/Provider/hf/HuggingFaceMedia.py
- Corrected model alias dictionary key in g4f/Provider/hf_space/StabilityAI_SD35Large.py
- Ensured referrer parameter default value in g4f/Provider/PollinationsImage.py
- Removed duplicate imports and adjusted get_models method in g4f/Provider/har/__init__.py
- Modified g4f/gui/server/api.py to remove unused conversation parameter in _create_response_stream
- Fixed logic to handle single exception in g4f/providers/retry_provider.py
- Added missing import of JsonConversation in g4f/providers/retry_provider.py
- Corrected stream_read_files to replace extension in return string in g4f/tools/files.py
This commit is contained in:
hlohaus 2025-05-17 10:02:13 +02:00
parent 33b3e1d431
commit 3775c1e06d
17 changed files with 239 additions and 131 deletions

View file

@ -143,11 +143,10 @@ class Api:
"messages": messages,
"stream": True,
"ignore_stream": True,
"return_conversation": True,
**kwargs
}
def _create_response_stream(self, kwargs: dict, conversation_id: str, provider: str, download_media: bool = True) -> Iterator:
def _create_response_stream(self, kwargs: dict, provider: str, download_media: bool = True) -> Iterator:
def decorated_log(text: str, file = None):
debug.logs.append(text)
if debug.logging:
@ -178,12 +177,9 @@ class Api:
for chunk in result:
if isinstance(chunk, ProviderInfo):
yield self.handle_provider(chunk, model)
provider = chunk.name
elif isinstance(chunk, JsonConversation):
if provider is not None:
if hasattr(provider, "__name__"):
provider = provider.__name__
yield self._format_json("conversation", {
yield self._format_json("conversation", chunk.get_dict() if provider == "AnyProvider" else {
provider: chunk.get_dict()
})
elif isinstance(chunk, Exception):