mirror of
https://github.com/xtekky/gpt4free.git
synced 2025-12-23 02:20:49 -08:00
Fix Liaobots provider
This commit is contained in:
parent
6f07ce4525
commit
0fc0f0e977
1 changed files with 9 additions and 32 deletions
|
|
@ -219,17 +219,6 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
|
||||||
_auth_code = ""
|
_auth_code = ""
|
||||||
_cookie_jar = None
|
_cookie_jar = None
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def get_model(cls, model: str) -> str:
|
|
||||||
"""
|
|
||||||
Retrieve the internal model identifier based on the provided model name or alias.
|
|
||||||
"""
|
|
||||||
if model in cls.model_aliases:
|
|
||||||
model = cls.model_aliases[model]
|
|
||||||
if model not in models:
|
|
||||||
raise ValueError(f"Model '{model}' is not supported.")
|
|
||||||
return model
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def is_supported(cls, model: str) -> bool:
|
def is_supported(cls, model: str) -> bool:
|
||||||
"""
|
"""
|
||||||
|
|
@ -249,10 +238,8 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
|
||||||
model = cls.get_model(model)
|
model = cls.get_model(model)
|
||||||
|
|
||||||
headers = {
|
headers = {
|
||||||
"authority": "liaobots.com",
|
"referer": "https://liaobots.work/",
|
||||||
"content-type": "application/json",
|
"origin": "https://liaobots.work",
|
||||||
"origin": cls.url,
|
|
||||||
"referer": f"{cls.url}/",
|
|
||||||
"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",
|
"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",
|
||||||
}
|
}
|
||||||
async with ClientSession(
|
async with ClientSession(
|
||||||
|
|
@ -292,18 +279,13 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
|
||||||
verify_ssl=False
|
verify_ssl=False
|
||||||
) as response:
|
) as response:
|
||||||
await raise_for_status(response)
|
await raise_for_status(response)
|
||||||
async for chunk in response.content.iter_any():
|
async for line in response.content:
|
||||||
if b"<html coupert-item=" in chunk:
|
if line.startswith(b"data: "):
|
||||||
raise RuntimeError("Invalid session")
|
yield json.loads(line[6:]).get("content")
|
||||||
if chunk:
|
|
||||||
if chunk.startswith(b"data: "):
|
|
||||||
yield json.loads(chunk[6:]).get("content")
|
|
||||||
else:
|
|
||||||
yield chunk.decode(errors="ignore")
|
|
||||||
except:
|
except:
|
||||||
async with session.post(
|
async with session.post(
|
||||||
"https://liaobots.work/api/user",
|
"https://liaobots.work/api/user",
|
||||||
json={"authcode": "pTIQr4FTnVRfr"},
|
json={"authcode": "jGDRFOqHcZKAo"},
|
||||||
verify_ssl=False
|
verify_ssl=False
|
||||||
) as response:
|
) as response:
|
||||||
await raise_for_status(response)
|
await raise_for_status(response)
|
||||||
|
|
@ -318,14 +300,9 @@ class Liaobots(AsyncGeneratorProvider, ProviderModelMixin):
|
||||||
verify_ssl=False
|
verify_ssl=False
|
||||||
) as response:
|
) as response:
|
||||||
await raise_for_status(response)
|
await raise_for_status(response)
|
||||||
async for chunk in response.content.iter_any():
|
async for line in response.content:
|
||||||
if b"<html coupert-item=" in chunk:
|
if line.startswith(b"data: "):
|
||||||
raise RuntimeError("Invalid session")
|
yield json.loads(line[6:]).get("content")
|
||||||
if chunk:
|
|
||||||
if chunk.startswith(b"data: "):
|
|
||||||
yield json.loads(chunk[6:]).get("content")
|
|
||||||
else:
|
|
||||||
yield chunk.decode(errors="ignore")
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def initialize_auth_code(cls, session: ClientSession) -> None:
|
async def initialize_auth_code(cls, session: ClientSession) -> None:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue