summaryrefslogtreecommitdiffstats
path: root/g4f
diff options
context:
space:
mode:
authorDebaditya Banerji <77636021+devAdityaa@users.noreply.github.com>2023-12-27 06:13:52 +0100
committerGitHub <noreply@github.com>2023-12-27 06:13:52 +0100
commiteb1e91d1235655a56f904c767debc44c409d5c4c (patch)
treed65914e82570f0062c9e464af4be071cd4fee2fb /g4f
parentMerge pull request #1398 from SilverMarcs/phind_challenge_parameter (diff)
downloadgpt4free-eb1e91d1235655a56f904c767debc44c409d5c4c.tar
gpt4free-eb1e91d1235655a56f904c767debc44c409d5c4c.tar.gz
gpt4free-eb1e91d1235655a56f904c767debc44c409d5c4c.tar.bz2
gpt4free-eb1e91d1235655a56f904c767debc44c409d5c4c.tar.lz
gpt4free-eb1e91d1235655a56f904c767debc44c409d5c4c.tar.xz
gpt4free-eb1e91d1235655a56f904c767debc44c409d5c4c.tar.zst
gpt4free-eb1e91d1235655a56f904c767debc44c409d5c4c.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/Chatxyz.py68
-rw-r--r--g4f/Provider/__init__.py1
2 files changed, 69 insertions, 0 deletions
diff --git a/g4f/Provider/Chatxyz.py b/g4f/Provider/Chatxyz.py
new file mode 100644
index 00000000..610cd45f
--- /dev/null
+++ b/g4f/Provider/Chatxyz.py
@@ -0,0 +1,68 @@
+from __future__ import annotations
+from aiohttp import ClientSession
+from ..typing import AsyncResult, Messages
+from .base_provider import AsyncGeneratorProvider
+import json
+class Chatxyz(AsyncGeneratorProvider):
+ url = "https://chat.3211000.xyz"
+ working = True
+ supports_gpt_35_turbo = True
+
+ @classmethod
+ async def create_async_generator(
+ cls,
+ model: str,
+ messages: Messages,
+ proxy: str = None,
+ **kwargs
+ ) -> AsyncResult:
+ if not model:
+ model = "gpt-3.5-turbo"
+ headers = {
+ 'Accept': 'text/event-stream',
+ 'Accept-Encoding': 'gzip, deflate, br',
+ 'Accept-Language': 'en-US,en;q=0.5',
+ 'Alt-Used': 'chat.3211000.xyz',
+ 'Content-Type': 'application/json',
+ 'Host': 'chat.3211000.xyz',
+ 'Origin': 'https://chat.3211000.xyz',
+ 'Referer': 'https://chat.3211000.xyz/',
+ 'Sec-Fetch-Dest': 'empty',
+ 'Sec-Fetch-Mode': 'cors',
+ 'Sec-Fetch-Site': 'same-origin',
+ 'TE': 'trailers',
+ 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0',
+ 'x-requested-with': 'XMLHttpRequest'
+ }
+ async with ClientSession(headers=headers) as session:
+
+ system_message = ""
+ user_messages=[]
+ for message in messages:
+ if message["role"] == "system":
+ system_message+=f'{message["content"]}\n'
+ else:
+ user_messages.append(message)
+ new_message = [{'role':'system','content':system_message}]
+ for i in user_messages:
+ new_message.append(i)
+
+ data = {
+ "messages": new_message,
+ "stream": True,
+ "model": "gpt-3.5-turbo",
+ "temperature": 0.5,
+ "presence_penalty": 0,
+ "frequency_penalty": 0,
+ "top_p": 1
+ }
+ async with session.post(f'{cls.url}/api/openai/v1/chat/completions',json=data) as response:
+ response.raise_for_status()
+ async for chunk in response.content:
+ line = chunk.decode()
+ if line.startswith("data: [DONE]"):
+ break
+ elif line.startswith("data: "):
+ line = json.loads(line[6:])
+ if(line["choices"][0]["delta"]["content"]!=None):
+ yield line["choices"][0]["delta"]["content"] \ No newline at end of file
diff --git a/g4f/Provider/__init__.py b/g4f/Provider/__init__.py
index ba62a199..5f2b8344 100644
--- a/g4f/Provider/__init__.py
+++ b/g4f/Provider/__init__.py
@@ -25,6 +25,7 @@ from .ChatgptFree import ChatgptFree
from .ChatgptLogin import ChatgptLogin
from .ChatgptNext import ChatgptNext
from .ChatgptX import ChatgptX
+from .Chatxyz import Chatxyz
from .DeepInfra import DeepInfra
from .FakeGpt import FakeGpt
from .FreeGpt import FreeGpt