summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Yqcloud.py
diff options
context:
space:
mode:
authorHeiner Lohaus <heiner.lohaus@netformic.com>2023-08-28 01:43:45 +0200
committerHeiner Lohaus <heiner.lohaus@netformic.com>2023-08-28 01:43:45 +0200
commit7294abc890c377d75c6c8c932620c2e2c8b3f0f9 (patch)
treef7d411570c71f5d225430d067ad64b620bb0d704 /g4f/Provider/Yqcloud.py
parent~ | code styling (diff)
downloadgpt4free-7294abc890c377d75c6c8c932620c2e2c8b3f0f9.tar
gpt4free-7294abc890c377d75c6c8c932620c2e2c8b3f0f9.tar.gz
gpt4free-7294abc890c377d75c6c8c932620c2e2c8b3f0f9.tar.bz2
gpt4free-7294abc890c377d75c6c8c932620c2e2c8b3f0f9.tar.lz
gpt4free-7294abc890c377d75c6c8c932620c2e2c8b3f0f9.tar.xz
gpt4free-7294abc890c377d75c6c8c932620c2e2c8b3f0f9.tar.zst
gpt4free-7294abc890c377d75c6c8c932620c2e2c8b3f0f9.zip
Diffstat (limited to '')
-rw-r--r--g4f/Provider/Yqcloud.py52
1 files changed, 23 insertions, 29 deletions
diff --git a/g4f/Provider/Yqcloud.py b/g4f/Provider/Yqcloud.py
index 44173525..7c1d06ba 100644
--- a/g4f/Provider/Yqcloud.py
+++ b/g4f/Provider/Yqcloud.py
@@ -1,29 +1,27 @@
-import requests
+from aiohttp import ClientSession
-from ..typing import Any, CreateResult
-from .base_provider import BaseProvider
+from .base_provider import AsyncProvider, format_prompt
-class Yqcloud(BaseProvider):
- url = "https://chat9.yqcloud.top/"
- working = True
- supports_gpt_35_turbo = True
+class Yqcloud(AsyncProvider):
+ url = "https://chat9.yqcloud.top/"
+ working = True
+ supports_gpt_35_turbo = True
@staticmethod
- def create_completion(
+ async def create_async(
model: str,
messages: list[dict[str, str]],
- stream: bool, **kwargs: Any) -> CreateResult:
-
- headers = _create_header()
- payload = _create_payload(messages)
-
- response = requests.post("https://api.aichatos.cloud/api/generateStream",
- headers=headers, json=payload)
-
- response.raise_for_status()
- response.encoding = 'utf-8'
- yield response.text
+ proxy: str = None,
+ **kwargs,
+ ) -> str:
+ async with ClientSession(
+ headers=_create_header()
+ ) as session:
+ payload = _create_payload(messages)
+ async with session.post("https://api.aichatos.cloud/api/generateStream", proxy=proxy, json=payload) as response:
+ response.raise_for_status()
+ return await response.text()
def _create_header():
@@ -35,15 +33,11 @@ def _create_header():
def _create_payload(messages: list[dict[str, str]]):
- prompt = ""
- for message in messages:
- prompt += "%s: %s\n" % (message["role"], message["content"])
- prompt += "assistant:"
-
return {
- "prompt" : prompt,
- "network" : True,
- "system" : "",
+ "prompt": format_prompt(messages),
+ "network": True,
+ "system": "",
"withoutContext": False,
- "stream" : False,
- } \ No newline at end of file
+ "stream": False,
+ "userId": "#/chat/1693025544336"
+ }