summaryrefslogtreecommitdiffstats
path: root/g4f
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2023-12-27 06:46:42 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2023-12-27 06:46:42 +0100
commit6d0d975c71ac3f1b2d3d42d0d9e8e1c58e82e5dc (patch)
tree65b44f440c1a439683e06e9c7f4d49b8ccef137d /g4f
parentAdded new Provider Chatxyz (#1393) (diff)
downloadgpt4free-6d0d975c71ac3f1b2d3d42d0d9e8e1c58e82e5dc.tar
gpt4free-6d0d975c71ac3f1b2d3d42d0d9e8e1c58e82e5dc.tar.gz
gpt4free-6d0d975c71ac3f1b2d3d42d0d9e8e1c58e82e5dc.tar.bz2
gpt4free-6d0d975c71ac3f1b2d3d42d0d9e8e1c58e82e5dc.tar.lz
gpt4free-6d0d975c71ac3f1b2d3d42d0d9e8e1c58e82e5dc.tar.xz
gpt4free-6d0d975c71ac3f1b2d3d42d0d9e8e1c58e82e5dc.tar.zst
gpt4free-6d0d975c71ac3f1b2d3d42d0d9e8e1c58e82e5dc.zip
Diffstat (limited to 'g4f')
-rw-r--r--g4f/Provider/Chatxyz.py36
1 files changed, 14 insertions, 22 deletions
diff --git a/g4f/Provider/Chatxyz.py b/g4f/Provider/Chatxyz.py
index 610cd45f..feb09be9 100644
--- a/g4f/Provider/Chatxyz.py
+++ b/g4f/Provider/Chatxyz.py
@@ -1,12 +1,16 @@
from __future__ import annotations
+
+import json
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
+ url = "https://chat.3211000.xyz"
+ working = True
supports_gpt_35_turbo = True
+ supports_message_history = True
@classmethod
async def create_async_generator(
@@ -16,8 +20,6 @@ class Chatxyz(AsyncGeneratorProvider):
proxy: str = None,
**kwargs
) -> AsyncResult:
- if not model:
- model = "gpt-3.5-turbo"
headers = {
'Accept': 'text/event-stream',
'Accept-Encoding': 'gzip, deflate, br',
@@ -35,28 +37,17 @@ class Chatxyz(AsyncGeneratorProvider):
'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,
+ "messages": messages,
"stream": True,
"model": "gpt-3.5-turbo",
"temperature": 0.5,
"presence_penalty": 0,
"frequency_penalty": 0,
- "top_p": 1
+ "top_p": 1,
+ **kwargs
}
- async with session.post(f'{cls.url}/api/openai/v1/chat/completions',json=data) as response:
+ async with session.post(f'{cls.url}/api/openai/v1/chat/completions', json=data, proxy=proxy) as response:
response.raise_for_status()
async for chunk in response.content:
line = chunk.decode()
@@ -64,5 +55,6 @@ class Chatxyz(AsyncGeneratorProvider):
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
+ chunk = line["choices"][0]["delta"].get("content")
+ if(chunk):
+ yield chunk \ No newline at end of file