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

XFEstudio/gpt4free

fix: update media file mode and add working check for providers

* In `g4f/client/__init__.py` within the `Images.get_b64_from_url` function, change the file open mode from `"wb"` to `"rb"` to correctly read file data. * In `g4f/providers/any_provider.py`, add an `if provider.working:` condition before checking if the provider matches the model criteria, ensuring that only working providers are appended.

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

代码差异

2 个文件 +4 -3
Modified g4f/client/__init__.py +1 -1
@@ -529,7 +529,7 @@ class Images:
529 529 # Convert URLs directly to base64 without saving
530 530 async def get_b64_from_url(url: str) -> Image:
531 531 if url.startswith("/media/"):
532 with open(os.path.join(get_media_dir(), os.path.basename(url)), "wb") as f:
532 with open(os.path.join(get_media_dir(), os.path.basename(url)), "rb") as f:
533 533 b64_data = base64.b64encode(f.read()).decode()
534 534 return Image.model_construct(b64_json=b64_data, revised_prompt=response.alt)
535 535 async with aiohttp.ClientSession(cookies=response.get("cookies")) as session:
Modified g4f/providers/any_provider.py +3 -2
@@ -142,8 +142,9 @@ class AnyProvider(AsyncGeneratorProvider, ProviderModelMixin):
142 142 OpenaiChat, Cloudflare, LMArenaProvider, PerplexityLabs, Gemini, Grok, DeepSeekAPI, FreeRouter, Blackbox,
143 143 HuggingFace, HuggingFaceMedia, HuggingSpace, LambdaChat, CopilotAccount, PollinationsAI, DeepInfraChat
144 144 ]:
145 if not model or model in provider.get_models() or model in provider.model_aliases:
146 providers.append(provider)
145 if provider.working:
146 if not model or model in provider.get_models() or model in provider.model_aliases:
147 providers.append(provider)
147 148 if model in models.__models__:
148 149 for provider in models.__models__[model][1]:
149 150 providers.append(provider)