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

XFEstudio/gpt4free

Fix Liaobots provider

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

代码差异

1 个文件 +9 -32
Modified g4f/Provider/Liaobots.py +9 -32
@@ -219,17 +219,6 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
219 219 _auth_code = ""
220 220 _cookie_jar = None
221 221
222 @classmethod
223 def get_model(cls, model: str) -> str:
224 """
225 Retrieve the internal model identifier based on the provided model name or alias.
226 """
227 if model in cls.model_aliases:
228 model = cls.model_aliases[model]
229 if model not in models:
230 raise ValueError(f"Model '{model}' is not supported.")
231 return model
232
233 222 @classmethod
234 223 def is_supported(cls, model: str) -> bool:
235 224 """
@@ -249,10 +238,8 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
249 238 model = cls.get_model(model)
250 239
251 240 headers = {
252 "authority": "liaobots.com",
253 "content-type": "application/json",
254 "origin": cls.url,
255 "referer": f"{cls.url}/",
241 "referer": "https://liaobots.work/",
242 "origin": "https://liaobots.work",
256 243 "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36",
257 244 }
258 245 async with ClientSession(
@@ -292,18 +279,13 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
292 279 verify_ssl=False
293 280 ) as response:
294 281 await raise_for_status(response)
295 async for chunk in response.content.iter_any():
296 if b"<html coupert-item=" in chunk:
297 raise RuntimeError("Invalid session")
298 if chunk:
299 if chunk.startswith(b"data: "):
300 yield json.loads(chunk[6:]).get("content")
301 else:
302 yield chunk.decode(errors="ignore")
282 async for line in response.content:
283 if line.startswith(b"data: "):
284 yield json.loads(line[6:]).get("content")
303 285 except:
304 286 async with session.post(
305 287 "https://liaobots.work/api/user",
306 json={"authcode": "pTIQr4FTnVRfr"},
288 json={"authcode": "jGDRFOqHcZKAo"},
307 289 verify_ssl=False
308 290 ) as response:
309 291 await raise_for_status(response)
@@ -318,14 +300,9 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
318 300 verify_ssl=False
319 301 ) as response:
320 302 await raise_for_status(response)
321 async for chunk in response.content.iter_any():
322 if b"<html coupert-item=" in chunk:
323 raise RuntimeError("Invalid session")
324 if chunk:
325 if chunk.startswith(b"data: "):
326 yield json.loads(chunk[6:]).get("content")
327 else:
328 yield chunk.decode(errors="ignore")
303 async for line in response.content:
304 if line.startswith(b"data: "):
305 yield json.loads(line[6:]).get("content")
329 306
330 307 @classmethod
331 308 async def initialize_auth_code(cls, session: ClientSession) -> None: