summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Liaobots.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner.lohaus@netformic.com>2023-09-05 17:27:24 +0200
committerHeiner Lohaus <heiner.lohaus@netformic.com>2023-09-05 17:27:24 +0200
commit5ca47b44b2b42abb4f48163c17500b5ee67ab28f (patch)
treeb8fba4bde73d59c05857459eac41b25347d65c8e /g4f/Provider/Liaobots.py
parent~ | Merge pull request #869 from ahobsonsayers/add-console-script (diff)
downloadgpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.gz
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.bz2
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.lz
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.xz
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.tar.zst
gpt4free-5ca47b44b2b42abb4f48163c17500b5ee67ab28f.zip
Diffstat (limited to 'g4f/Provider/Liaobots.py')
-rw-r--r--g4f/Provider/Liaobots.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/g4f/Provider/Liaobots.py b/g4f/Provider/Liaobots.py
index 2360c8a5..2cc5ff99 100644
--- a/g4f/Provider/Liaobots.py
+++ b/g4f/Provider/Liaobots.py
@@ -32,7 +32,6 @@ models = {
class Liaobots(AsyncGeneratorProvider):
url = "https://liaobots.com"
working = True
- supports_stream = True
supports_gpt_35_turbo = True
supports_gpt_4 = True
_auth_code = None
@@ -46,24 +45,24 @@ class Liaobots(AsyncGeneratorProvider):
proxy: str = None,
**kwargs
) -> AsyncGenerator:
+ model = model if model in models else "gpt-3.5-turbo"
if proxy and "://" not in proxy:
proxy = f"http://{proxy}"
headers = {
"authority": "liaobots.com",
"content-type": "application/json",
- "origin": "https://liaobots.com",
- "referer": "https://liaobots.com/",
+ "origin": cls.url,
+ "referer": 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",
}
async with ClientSession(
headers=headers
) as session:
- model = model if model in models else "gpt-3.5-turbo"
auth_code = auth if isinstance(auth, str) else cls._auth_code
if not auth_code:
- async with session.post("https://liaobots.com/api/user", proxy=proxy, json={"authcode": ""}) as response:
+ async with session.post(cls.url + "/api/user", proxy=proxy, json={"authcode": ""}) as response:
response.raise_for_status()
- auth_code = cls._auth_code = json.loads((await response.text()))["authCode"]
+ auth_code = cls._auth_code = json.loads(await response.text())["authCode"]
data = {
"conversationId": str(uuid.uuid4()),
"model": models[model],
@@ -71,10 +70,11 @@ class Liaobots(AsyncGeneratorProvider):
"key": "",
"prompt": "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully.",
}
- async with session.post("https://liaobots.com/api/chat", proxy=proxy, json=data, headers={"x-auth-code": auth_code}) as response:
+ async with session.post(cls.url + "/api/chat", proxy=proxy, json=data, headers={"x-auth-code": auth_code}) as response:
response.raise_for_status()
- async for line in response.content:
- yield line.decode("utf-8")
+ async for stream in response.content.iter_any():
+ if stream:
+ yield stream.decode()
@classmethod