diff options
author | H Lohaus <hlohaus@users.noreply.github.com> | 2023-12-27 06:47:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-27 06:47:19 +0100 |
commit | cc57efeca38c9f8cfa25149fe35711de63384937 (patch) | |
tree | 65b44f440c1a439683e06e9c7f4d49b8ccef137d /g4f/Provider | |
parent | Added new Provider Chatxyz (#1393) (diff) | |
parent | Improve Chatxyz Provider (diff) | |
download | gpt4free-cc57efeca38c9f8cfa25149fe35711de63384937.tar gpt4free-cc57efeca38c9f8cfa25149fe35711de63384937.tar.gz gpt4free-cc57efeca38c9f8cfa25149fe35711de63384937.tar.bz2 gpt4free-cc57efeca38c9f8cfa25149fe35711de63384937.tar.lz gpt4free-cc57efeca38c9f8cfa25149fe35711de63384937.tar.xz gpt4free-cc57efeca38c9f8cfa25149fe35711de63384937.tar.zst gpt4free-cc57efeca38c9f8cfa25149fe35711de63384937.zip |
Diffstat (limited to 'g4f/Provider')
-rw-r--r-- | g4f/Provider/Chatxyz.py | 36 |
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 |