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

XFEstudio/gpt4free

Update LMArena provider

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

代码差异

1 个文件 +19 -20
Modified g4f/Provider/needs_auth/LMArenaBeta.py +19 -20
@@ -180,20 +180,6 @@ class LMArenaBeta(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
180 180 timeout: int = None,
181 181 **kwargs
182 182 ) -> AsyncResult:
183 if not cls._models_loaded:
184 cls.get_models()
185 is_image_model = model in image_models
186 if not model:
187 model = cls.default_model
188 if model in cls.model_aliases:
189 model = cls.model_aliases[model]
190 if model in cls.text_models:
191 model_id = cls.text_models[model]
192 elif model in cls.image_models:
193 model_id = cls.image_models[model]
194 else:
195 raise ModelNotFoundError(f"Model '{model}' is not supported by LMArena Beta.")
196
197 183 if cls.share_url is None:
198 184 cls.share_url = os.getenv("G4F_SHARE_URL")
199 185 prompt = get_last_user_message(messages)
@@ -234,7 +220,9 @@ class LMArenaBeta(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
234 220 await asyncio.sleep(1)
235 221 while not await page.evaluate('document.querySelector(\'textarea\')'):
236 222 await asyncio.sleep(1)
237 args = await get_args_from_nodriver(cls.url, proxy=proxy, callback=callback, user_data_dir=None)
223 args = await get_args_from_nodriver(cls.url, proxy=proxy, callback=callback)
224 with cache_file.open("w") as f:
225 json.dump(args, f)
238 226 elif not cls.looked:
239 227 cls.looked = True
240 228 try:
@@ -244,7 +232,7 @@ class LMArenaBeta(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
244 232 "model": model,
245 233 "provider": cls.__name__
246 234 })
247 response.raise_for_status()
235 raise_for_status(response)
248 236 text, *args = response.text.split("\n" * 10 + "<!--", 1)
249 237 if args:
250 238 debug.log("Save args to cache file:", str(cache_file))
@@ -255,6 +243,20 @@ class LMArenaBeta(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
255 243 cls.looked = False
256 244 return
257 245
246 if not cls._models_loaded:
247 cls.get_models()
248 is_image_model = model in image_models
249 if not model:
250 model = cls.default_model
251 if model in cls.model_aliases:
252 model = cls.model_aliases[model]
253 if model in cls.text_models:
254 model_id = cls.text_models[model]
255 elif model in cls.image_models:
256 model_id = cls.image_models[model]
257 else:
258 raise ModelNotFoundError(f"Model '{model}' is not supported by LMArena Beta.")
259
258 260 userMessageId = str(uuid.uuid4())
259 261 modelAMessageId = str(uuid.uuid4())
260 262 evaluationSessionId = str(uuid.uuid4())
@@ -331,13 +333,10 @@ class LMArenaBeta(AsyncGeneratorProvider, ProviderModelMixin, AuthFileMixin):
331 333 args = None
332 334 debug.log(f"{cls.__name__}: Cloudflare error")
333 335 continue
334 if os.getenv("G4F_SHARE_AUTH"):
336 if args and os.getenv("G4F_SHARE_AUTH"):
335 337 yield "\n" * 10
336 338 yield "<!--"
337 339 yield json.dumps(args)
338 # Save the args to cache file
339 with cache_file.open("w") as f:
340 json.dump(args, f)
341 340
342 341 def get_content_type(url: str) -> str:
343 342 if url.endswith(".webp"):