summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/unfinished/AiChatting.py
diff options
context:
space:
mode:
authorH Lohaus <hlohaus@users.noreply.github.com>2023-12-07 07:18:05 +0100
committerGitHub <noreply@github.com>2023-12-07 07:18:05 +0100
commit484b96d850aca9b9144f3b8dd2fb502b25356c22 (patch)
treeb10fe200193cfdbe0ee25714df49959c01c6265f /g4f/Provider/unfinished/AiChatting.py
parentUpdate Pi.py (diff)
downloadgpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar.gz
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar.bz2
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar.lz
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar.xz
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.tar.zst
gpt4free-484b96d850aca9b9144f3b8dd2fb502b25356c22.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/unfinished/AiChatting.py66
1 files changed, 66 insertions, 0 deletions
diff --git a/g4f/Provider/unfinished/AiChatting.py b/g4f/Provider/unfinished/AiChatting.py
new file mode 100644
index 00000000..a66921c1
--- /dev/null
+++ b/g4f/Provider/unfinished/AiChatting.py
@@ -0,0 +1,66 @@
+from __future__ import annotations
+
+from urllib.parse import unquote
+
+from ...typing import AsyncResult, Messages
+from ..base_provider import BaseProvider
+from ...webdriver import WebDriver
+from ...requests import Session, get_session_from_browser
+
+class AiChatting(BaseProvider):
+ url = "https://www.aichatting.net"
+ supports_gpt_35_turbo = True
+ _session: Session = None
+
+ @classmethod
+ def create_completion(
+ cls,
+ model: str,
+ messages: Messages,
+ stream: bool,
+ proxy: str = None,
+ timeout: int = 120,
+ webdriver: WebDriver = None,
+ **kwargs
+ ) -> AsyncResult:
+ if not cls._session:
+ cls._session = get_session_from_browser(cls.url, webdriver, proxy, timeout)
+ visitorId = unquote(cls._session.cookies.get("aichatting.website.visitorId"))
+
+ headers = {
+ "accept": "application/json, text/plain, */*",
+ "lang": "en",
+ "source": "web"
+ }
+ data = {
+ "roleId": 0,
+ }
+ try:
+ response = cls._session.post("https://aga-api.aichatting.net/aigc/chat/record/conversation/create", json=data, headers=headers)
+ response.raise_for_status()
+ conversation_id = response.json()["data"]["conversationId"]
+ except Exception as e:
+ cls.reset()
+ raise e
+ headers = {
+ "authority": "aga-api.aichatting.net",
+ "accept": "text/event-stream,application/json, text/event-stream",
+ "lang": "en",
+ "source": "web",
+ "vtoken": visitorId,
+ }
+ data = {
+ "spaceHandle": True,
+ "roleId": 0,
+ "messages": messages,
+ "conversationId": conversation_id,
+ }
+ response = cls._session.post("https://aga-api.aichatting.net/aigc/chat/v2/stream", json=data, headers=headers, stream=True)
+ response.raise_for_status()
+ for chunk in response.iter_lines():
+ if chunk.startswith(b"data:"):
+ yield chunk[5:].decode().replace("-=- --", " ").replace("-=-n--", "\n").replace("--@DONE@--", "")
+
+ @classmethod
+ def reset(cls):
+ cls._session = None \ No newline at end of file