diff options
author | abc <98614666+xtekky@users.noreply.github.com> | 2023-08-27 17:37:44 +0200 |
---|---|---|
committer | abc <98614666+xtekky@users.noreply.github.com> | 2023-08-27 17:37:44 +0200 |
commit | efd75a11b871d61ac31b0e274acdfb33daba361d (patch) | |
tree | 22bd158324444cdbb9dbed46f25f8dffa60f3756 /g4f/Provider/Liaobots.py | |
parent | ~ | v-0.0.2.5 (diff) | |
download | gpt4free-efd75a11b871d61ac31b0e274acdfb33daba361d.tar gpt4free-efd75a11b871d61ac31b0e274acdfb33daba361d.tar.gz gpt4free-efd75a11b871d61ac31b0e274acdfb33daba361d.tar.bz2 gpt4free-efd75a11b871d61ac31b0e274acdfb33daba361d.tar.lz gpt4free-efd75a11b871d61ac31b0e274acdfb33daba361d.tar.xz gpt4free-efd75a11b871d61ac31b0e274acdfb33daba361d.tar.zst gpt4free-efd75a11b871d61ac31b0e274acdfb33daba361d.zip |
Diffstat (limited to '')
-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") |