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

XFEstudio/gpt4free

feat: Add default model attributes and improve caching logic

- Added `audio_models` attribute in `EdgeTTS.py` to store available audio models. - Defined `default_model` attribute in `gTTS.py` with `"en-US"` and added `audio_models` list. - Introduced `default_model` in `HarProvider` within `har/__init__.py` and updated model retrieval logic. - Modified `HuggingFaceMedia.py` to change the `label` attribute from `"HuggingFace (Image/Video Generation)"` to `"HuggingFace"`. - Improved caching behavior in `base_provider.py` by ensuring the cache file is written only once per generation cycle. - Removed redundant `finally` block in `base_provider.py` that was rewriting the cache file unnecessarily.

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

代码差异

5 个文件 +12 -6
Modified g4f/Provider/audio/EdgeTTS.py +1 -0
@@ -31,6 +31,7 @@ class EdgeTTS(AsyncGeneratorProvider, ProviderModelMixin):
31 31 voices = asyncio.run(VoicesManager.create())
32 32 cls.default_model = voices.find(Locale=cls.default_locale)[0]["Name"]
33 33 cls.models = [voice["Name"] for voice in voices.voices]
34 cls.audio_models = cls.models
34 35 return cls.models
35 36
36 37 @classmethod
Modified g4f/Provider/audio/gTTS.py +3 -0
@@ -43,7 +43,10 @@ class gTTS(AsyncGeneratorProvider, ProviderModelMixin):
43 43 default_language = "en"
44 44 default_tld = "com"
45 45 default_format = "mp3"
46
47 default_model = "en-US"
46 48 models = list(models.keys())
49 audio_models = models
47 50
48 51 @classmethod
49 52 async def create_async_generator(
Modified g4f/Provider/har/__init__.py +2 -0
@@ -14,6 +14,7 @@ from ..openai.har_file import get_headers
14 14 class HarProvider(AsyncGeneratorProvider, ProviderModelMixin):
15 15 url = "https://lmarena.ai"
16 16 working = True
17 default_model = "chatgpt-4o-latest-20250326"
17 18
18 19 @classmethod
19 20 def get_models(cls):
@@ -26,6 +27,7 @@ class HarProvider(AsyncGeneratorProvider, ProviderModelMixin):
26 27 continue
27 28 chunk = v['response']['content']['text'].split("\n\ndata: ")[2]
28 29 cls.models = list(dict.fromkeys(get_str_list(find_list(json.loads(chunk), 'choices'))).keys())
30 cls.models[0] = cls.default_model
29 31 if cls.models:
30 32 break
31 33 return cls.models
Modified g4f/Provider/hf/HuggingFaceMedia.py +1 -1
@@ -16,7 +16,7 @@ from ...image import use_aspect_ratio
16 16 from ... import debug
17 17
18 18 class HuggingFaceMedia(AsyncGeneratorProvider, ProviderModelMixin):
19 label = "HuggingFace (Image/Video Generation)"
19 label = "HuggingFace"
20 20 parent = "HuggingFace"
21 21 url = "https://huggingface.co"
22 22 working = True
Modified g4f/providers/base_provider.py +5 -5
@@ -465,9 +465,11 @@ class AsyncAuthedProvider(AsyncGeneratorProvider, AuthFileMixin):
465 465 auth_result = chunk
466 466 else:
467 467 yield chunk
468 yield from to_sync_generator(cls.create_authed(model, messages, auth_result, **kwargs))
469 finally:
470 cls.write_cache_file(cache_file, auth_result)
468 for chunk in to_sync_generator(cls.create_authed(model, messages, auth_result, **kwargs)):
469 if cache_file is not None:
470 cls.write_cache_file(cache_file, auth_result)
471 cache_file = None
472 yield chunk
471 473
472 474 @classmethod
473 475 async def create_async_generator(
@@ -506,5 +508,3 @@ class AsyncAuthedProvider(AsyncGeneratorProvider, AuthFileMixin):
506 508 cls.write_cache_file(cache_file, auth_result)
507 509 cache_file = None
508 510 yield chunk
509 finally:
510 cls.write_cache_file(cache_file, auth_result)