diff options
author | Luneye <73485421+Luneye@users.noreply.github.com> | 2023-08-28 16:55:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-28 16:55:36 +0200 |
commit | 01294db6995511de37e9078e03ce32e54dbdad52 (patch) | |
tree | d6c4c14f4e6a3a81660ddb75272bc5da81cacecc /g4f/Provider/Liaobots.py | |
parent | Update Bing.py (diff) | |
parent | ~ | code styling (diff) | |
download | gpt4free-01294db6995511de37e9078e03ce32e54dbdad52.tar gpt4free-01294db6995511de37e9078e03ce32e54dbdad52.tar.gz gpt4free-01294db6995511de37e9078e03ce32e54dbdad52.tar.bz2 gpt4free-01294db6995511de37e9078e03ce32e54dbdad52.tar.lz gpt4free-01294db6995511de37e9078e03ce32e54dbdad52.tar.xz gpt4free-01294db6995511de37e9078e03ce32e54dbdad52.tar.zst gpt4free-01294db6995511de37e9078e03ce32e54dbdad52.zip |
Diffstat (limited to 'g4f/Provider/Liaobots.py')
-rw-r--r-- | g4f/Provider/Liaobots.py | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/g4f/Provider/Liaobots.py b/g4f/Provider/Liaobots.py index a969b643..a8bb83e8 100644 --- a/g4f/Provider/Liaobots.py +++ b/g4f/Provider/Liaobots.py @@ -1,33 +1,31 @@ -import uuid +import uuid, requests -import requests - -from ..typing import Any, CreateResult +from ..typing import Any, CreateResult from .base_provider import BaseProvider class Liaobots(BaseProvider): - url = "https://liaobots.com" - supports_stream = True - needs_auth = True - supports_gpt_35_turbo = True - supports_gpt_4 = True + url: str = "https://liaobots.com" + supports_stream = True + needs_auth = True + supports_gpt_35_turbo = True + supports_gpt_4 = True @staticmethod def create_completion( model: str, messages: list[dict[str, str]], - stream: bool, - **kwargs: Any, - ) -> CreateResult: + stream: bool, **kwargs: Any) -> CreateResult: + headers = { - "authority": "liaobots.com", - "content-type": "application/json", - "origin": "https://liaobots.com", - "referer": "https://liaobots.com/", - "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", - "x-auth-code": str(kwargs.get("auth")), + "authority" : "liaobots.com", + "content-type" : "application/json", + "origin" : "https://liaobots.com", + "referer" : "https://liaobots.com/", + "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", + "x-auth-code" : str(kwargs.get("auth")), } + models = { "gpt-4": { "id": "gpt-4", @@ -44,18 +42,15 @@ class Liaobots(BaseProvider): } json_data = { "conversationId": str(uuid.uuid4()), - "model": models[model], - "messages": messages, - "key": "", - "prompt": "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.", + "model" : models[model], + "messages" : messages, + "key" : "", + "prompt" : "You are ChatGPT, a large language model trained by OpenAI. Follow the user's instructions carefully. Respond using markdown.", } - response = requests.post( - "https://liaobots.com/api/chat", - headers=headers, - json=json_data, - stream=True, - ) + response = requests.post("https://liaobots.com/api/chat", + headers=headers, json=json_data, stream=True) + response.raise_for_status() for token in response.iter_content(chunk_size=2046): yield token.decode("utf-8") |