XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Add error handling for missing authentication and Unicode encoding in response streaming

de688319
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

2 个文件 +7 -1
Modified g4f/Provider/template/OpenaiTemplate.py +2 -0
@@ -58,6 +58,8 @@ class OpenaiTemplate(AsyncGeneratorProvider, ProviderModelMixin, RaiseErrorMixin
58 58 cls.models_count = {model.get("name") if cls.use_model_names else model.get("id", model.get("name")): len(model.get("providers", [])) for model in data if len(model.get("providers", [])) > 1}
59 59 if cls.sort_models:
60 60 cls.models.sort()
61 except MissingAuthError:
62 raise
61 63 except Exception as e:
62 64 debug.error(e)
63 65 return cls.fallback_models
Modified g4f/cli/client.py +5 -1
@@ -130,7 +130,11 @@ async def stream_response(
130 130 continue
131 131 if is_content(delta):
132 132 response_tokens.append(delta)
133 print(delta, end="", flush=True)
133 try:
134 print(delta, end="", flush=True)
135 except UnicodeEncodeError as e:
136 debug.error(e)
137 pass
134 138 print()
135 139
136 140 if last_chunk and hasattr(last_chunk, "conversation"):