summaryrefslogtreecommitdiffstats
path: root/g4f/Provider/Yqcloud.py
diff options
context:
space:
mode:
authorTekky <98614666+xtekky@users.noreply.github.com>2023-10-08 14:21:21 +0200
committerGitHub <noreply@github.com>2023-10-08 14:21:21 +0200
commitd804b20694c8ffc88355adee610d1424a1df1263 (patch)
tree9750cb102284d9445d60c539f4e6d3586603e917 /g4f/Provider/Yqcloud.py
parent~ | `v-0.1.5.5` (diff)
parentAdd Messages and AsyncResult typing (diff)
downloadgpt4free-d804b20694c8ffc88355adee610d1424a1df1263.tar
gpt4free-d804b20694c8ffc88355adee610d1424a1df1263.tar.gz
gpt4free-d804b20694c8ffc88355adee610d1424a1df1263.tar.bz2
gpt4free-d804b20694c8ffc88355adee610d1424a1df1263.tar.lz
gpt4free-d804b20694c8ffc88355adee610d1424a1df1263.tar.xz
gpt4free-d804b20694c8ffc88355adee610d1424a1df1263.tar.zst
gpt4free-d804b20694c8ffc88355adee610d1424a1df1263.zip
Diffstat (limited to 'g4f/Provider/Yqcloud.py')
-rw-r--r--g4f/Provider/Yqcloud.py31
1 files changed, 21 insertions, 10 deletions
diff --git a/g4f/Provider/Yqcloud.py b/g4f/Provider/Yqcloud.py
index ac93315c..0e96e20f 100644
--- a/g4f/Provider/Yqcloud.py
+++ b/g4f/Provider/Yqcloud.py
@@ -1,8 +1,9 @@
from __future__ import annotations
+import random
from aiohttp import ClientSession
-from ..typing import AsyncGenerator
+from ..typing import AsyncResult, Messages
from .base_provider import AsyncGeneratorProvider, format_prompt
@@ -14,19 +15,22 @@ class Yqcloud(AsyncGeneratorProvider):
@staticmethod
async def create_async_generator(
model: str,
- messages: list[dict[str, str]],
+ messages: Messages,
proxy: str = None,
**kwargs,
- ) -> AsyncGenerator:
+ ) -> AsyncResult:
async with ClientSession(
headers=_create_header()
) as session:
- payload = _create_payload(messages)
+ payload = _create_payload(messages, **kwargs)
async with session.post("https://api.aichatos.cloud/api/generateStream", proxy=proxy, json=payload) as response:
response.raise_for_status()
- async for stream in response.content.iter_any():
- if stream:
- yield stream.decode()
+ async for chunk in response.content.iter_any():
+ if chunk:
+ chunk = chunk.decode()
+ if "sorry, 您的ip已由于触发防滥用检测而被封禁" in chunk:
+ raise RuntimeError("IP address is blocked by abuse detection.")
+ yield chunk
def _create_header():
@@ -37,12 +41,19 @@ def _create_header():
}
-def _create_payload(messages: list[dict[str, str]]):
+def _create_payload(
+ messages: Messages,
+ system_message: str = "",
+ user_id: int = None,
+ **kwargs
+):
+ if not user_id:
+ user_id = random.randint(1690000544336, 2093025544336)
return {
"prompt": format_prompt(messages),
"network": True,
- "system": "",
+ "system": system_message,
"withoutContext": False,
"stream": True,
- "userId": "#/chat/1693025544336"
+ "userId": f"#/chat/{user_id}"
}