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

XFEstudio/gpt4free

Refactor Gemini, GeminiCLI, GeminiPro, and QwenCode providers to streamline model handling and track live instances

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

代码差异

4 个文件 +11 -29
Modified g4f/Provider/needs_auth/Gemini.py +0 -27
@@ -91,10 +91,6 @@ class Gemini(AsyncGeneratorProvider, ProviderModelMixin):
91 91 models = [
92 92 default_model, "gemini-2.5-flash", "gemini-2.5-pro"
93 93 ]
94 model_aliases = {
95 "gemini-2.0": "",
96 "gemini-2.0-flash": ["gemini-2.0-flash", "gemini-2.0-flash", "gemini-2.0-flash-exp"],
97 }
98 94
99 95 synthesize_content_type = "audio/vnd.wav"
100 96
@@ -106,29 +102,6 @@ class Gemini(AsyncGeneratorProvider, ProviderModelMixin):
106 102 refresh_interval = 540
107 103 rotate_tasks = {}
108 104
109 @classmethod
110 def get_model(cls, model: str) -> str:
111 """Get the internal model name from the user-provided model name."""
112 if not model:
113 return cls.default_model
114
115 # Check if the model exists directly in our models list
116 if model in cls.models:
117 return model
118
119 # Check if there's an alias for this model
120 if model in cls.model_aliases:
121 alias = cls.model_aliases[model]
122 # If the alias is a list, randomly select one of the options
123 if isinstance(alias, list):
124 selected_model = random.choice(alias)
125 debug.log(f"Gemini: Selected model '{selected_model}' from alias '{model}'")
126 return selected_model
127 debug.log(f"Gemini: Using model '{alias}' for alias '{model}'")
128 return alias
129
130 raise ModelNotFoundError(f"Model {model} not found")
131
132 105 @classmethod
133 106 async def nodriver_login(cls, proxy: str = None) -> AsyncIterator[str]:
134 107 if not has_nodriver:
Modified g4f/Provider/needs_auth/GeminiCLI.py +9 -0
@@ -510,6 +510,15 @@ class GeminiCLI(AsyncGeneratorProvider, ProviderModelMixin):
510 510
511 511 auth_manager: AuthManager = None
512 512
513 @classmethod
514 def get_models(cls, **kwargs):
515 if cls.live == 0:
516 if cls.auth_manager is None:
517 cls.auth_manager = AuthManager(env=os.environ)
518 if cls.auth_manager.get_access_token() is not None:
519 cls.live += 1
520 return cls.models
521
513 522 @classmethod
514 523 async def create_async_generator(
515 524 cls,
Modified g4f/Provider/needs_auth/GeminiPro.py +1 -0
@@ -59,6 +59,7 @@ class GeminiPro(AsyncGeneratorProvider, ProviderModelMixin):
59 59 if "generateContent" in model.get("supportedGenerationMethods")
60 60 ]
61 61 cls.models.sort()
62 cls.live += 1
62 63 except Exception as e:
63 64 debug.error(e)
64 65 if api_key is not None:
Modified g4f/Provider/qwen/QwenCode.py +1 -2
@@ -15,12 +15,11 @@ class QwenCode(OpenaiTemplate):
15 15 needs_auth = True
16 16 active_by_default = True
17 17 default_model = "qwen3-coder-plus"
18 models = [default_model]
18 19 client = QwenContentGenerator(QwenOAuth2Client())
19 20
20 21 @classmethod
21 22 def get_models(cls, **kwargs):
22 if not cls.models:
23 cls.models = [cls.default_model]
24 23 if cls.live == 0 and cls.client.shared_manager.isTokenValid(cls.client.shared_manager.getCurrentCredentials()):
25 24 cls.live += 1
26 25 return cls.models