Ryzenth 2.0.4__tar.gz → 2.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ryzenth-2.0.4 → ryzenth-2.0.5}/PKG-INFO +6 -1
- {ryzenth-2.0.4 → ryzenth-2.0.5}/README.md +5 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/__init__.py +2 -2
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/__version__.py +1 -1
- ryzenth-2.0.5/Ryzenth/_client.py +222 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/_shared.py +8 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/helper/__init__.py +3 -2
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/helper/_decorators.py +22 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/helper/_images.py +26 -3
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth.egg-info/PKG-INFO +6 -1
- ryzenth-2.0.4/Ryzenth/_client.py +0 -160
- {ryzenth-2.0.4 → ryzenth-2.0.5}/LICENSE +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/_asynchisded.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/_errors.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/_synchisded.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/helper/_federation.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/helper/_fonts.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/helper/_moderator.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/helper/_openai.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/helper/_ryzenth.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/helper/_thinking.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/pyoraddons/__init__.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/tests/__init__.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/tests/test_deepseek.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/tests/test_moderator.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/tests/test_send.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/tests/test_send_downloader.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth/types/__init__.py +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth.egg-info/SOURCES.txt +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth.egg-info/dependency_links.txt +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth.egg-info/requires.txt +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/Ryzenth.egg-info/top_level.txt +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/setup.cfg +0 -0
- {ryzenth-2.0.4 → ryzenth-2.0.5}/setup.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: Ryzenth
|
3
|
-
Version: 2.0.
|
3
|
+
Version: 2.0.5
|
4
4
|
Summary: Ryzenth Python Wrapper For Perfomance
|
5
5
|
Author: TeamKillerX
|
6
6
|
License: MIT
|
@@ -125,6 +125,11 @@ export RYZENTH_API_KEY=your-api-key
|
|
125
125
|
## Web scrapers
|
126
126
|
* [`itzpire`](https://itzpire.com) - Team Developer
|
127
127
|
|
128
|
+
## Tool Developer
|
129
|
+
~ Artificial Intelligence
|
130
|
+
- [`OpenAI`](https://platform.openai.com/docs) - OpenAI Docs
|
131
|
+
- [`Gemini AI`](https://ai.google.dev) - Gemini AI Docs
|
132
|
+
|
128
133
|
## Credits
|
129
134
|
|
130
135
|
* Built with love by [xtdevs](https://t.me/xtdevs)
|
@@ -73,6 +73,11 @@ export RYZENTH_API_KEY=your-api-key
|
|
73
73
|
## Web scrapers
|
74
74
|
* [`itzpire`](https://itzpire.com) - Team Developer
|
75
75
|
|
76
|
+
## Tool Developer
|
77
|
+
~ Artificial Intelligence
|
78
|
+
- [`OpenAI`](https://platform.openai.com/docs) - OpenAI Docs
|
79
|
+
- [`Gemini AI`](https://ai.google.dev) - Gemini AI Docs
|
80
|
+
|
76
81
|
## Credits
|
77
82
|
|
78
83
|
* Built with love by [xtdevs](https://t.me/xtdevs)
|
@@ -19,11 +19,11 @@
|
|
19
19
|
|
20
20
|
from . import *
|
21
21
|
from .__version__ import __version__
|
22
|
-
from ._client import ApiKeyFrom,
|
22
|
+
from ._client import ApiKeyFrom, FromConvertDot, RyzenthApiClient, UrHellFrom
|
23
23
|
|
24
24
|
__all__ = [
|
25
25
|
"ApiKeyFrom",
|
26
26
|
"RyzenthApiClient",
|
27
27
|
"UrHellFrom",
|
28
|
-
"
|
28
|
+
"FromConvertDot"
|
29
29
|
]
|
@@ -0,0 +1,222 @@
|
|
1
|
+
#!/usr/bin/env python
|
2
|
+
# -*- coding: utf-8 -*-
|
3
|
+
# Copyright 2019-2025 (c) Randy W @xtdevs, @xtsea
|
4
|
+
#
|
5
|
+
# from : https://github.com/TeamKillerX
|
6
|
+
# Channel : @RendyProjects
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
8
|
+
# it under the terms of the GNU Affero General Public License as published by
|
9
|
+
# the Free Software Foundation, either version 3 of the License, or
|
10
|
+
# (at your option) any later version.
|
11
|
+
#
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
+
# GNU Affero General Public License for more details.
|
16
|
+
#
|
17
|
+
# You should have received a copy of the GNU Affero General Public License
|
18
|
+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
19
|
+
|
20
|
+
import asyncio
|
21
|
+
import json
|
22
|
+
import platform
|
23
|
+
import random
|
24
|
+
import time
|
25
|
+
import typing as t
|
26
|
+
from os import environ, getenv
|
27
|
+
|
28
|
+
import aiohttp
|
29
|
+
import httpx
|
30
|
+
from box import Box
|
31
|
+
|
32
|
+
from .__version__ import get_user_agent
|
33
|
+
from ._asynchisded import RyzenthXAsync
|
34
|
+
from ._errors import ForbiddenError, InternalError, ToolNotFoundError, WhatFuckError
|
35
|
+
from ._shared import TOOL_DOMAIN_MAP
|
36
|
+
from ._synchisded import RyzenthXSync
|
37
|
+
from .helper import AutoRetry, Decorators
|
38
|
+
|
39
|
+
|
40
|
+
class ApiKeyFrom:
|
41
|
+
def __init__(self, api_key: str = None, is_ok=False):
|
42
|
+
if api_key is Ellipsis:
|
43
|
+
is_ok = True
|
44
|
+
api_key = None
|
45
|
+
|
46
|
+
if not api_key:
|
47
|
+
api_key = environ.get("RYZENTH_API_KEY")
|
48
|
+
|
49
|
+
if not api_key:
|
50
|
+
api_key = "akeno_UKQEQMt991kh2Ehh7JqJYKapx8CCyeC" if is_ok else None
|
51
|
+
|
52
|
+
self.api_key = api_key
|
53
|
+
self.aio = RyzenthXAsync(api_key)
|
54
|
+
self._sync = RyzenthXSync(api_key)
|
55
|
+
|
56
|
+
def something(self):
|
57
|
+
pass
|
58
|
+
|
59
|
+
class UrHellFrom:
|
60
|
+
def __init__(self, name: str, only_author=False):
|
61
|
+
self.decorators = Decorators(ApiKeyFrom)
|
62
|
+
self.ai = self.decorators.send_ai(name=name, only_author=only_author)
|
63
|
+
|
64
|
+
def something(self):
|
65
|
+
pass
|
66
|
+
|
67
|
+
class FromConvertDot:
|
68
|
+
def __init__(self, obj):
|
69
|
+
self.obj = obj
|
70
|
+
|
71
|
+
def to_dot(self):
|
72
|
+
return Box(self.obj if self.obj is not None else {})
|
73
|
+
|
74
|
+
class RyzenthApiClient:
|
75
|
+
def __init__(
|
76
|
+
self,
|
77
|
+
*,
|
78
|
+
tools_name: list[str],
|
79
|
+
api_key: dict[str, list[dict]],
|
80
|
+
rate_limit: int = 5,
|
81
|
+
use_default_headers: bool = False,
|
82
|
+
use_httpx: bool = False
|
83
|
+
) -> None:
|
84
|
+
if not isinstance(api_key, dict) or not api_key:
|
85
|
+
raise WhatFuckError("API Key must be a non-empty dict of tool_name → list of headers")
|
86
|
+
if not tools_name:
|
87
|
+
raise WhatFuckError("A non-empty list of tool names must be provided for 'tools_name'.")
|
88
|
+
|
89
|
+
self._api_keys = api_key
|
90
|
+
self._use_default_headers: bool = use_default_headers
|
91
|
+
self._rate_limit = rate_limit
|
92
|
+
self._request_counter = 0
|
93
|
+
self._last_reset = time.monotonic()
|
94
|
+
self._use_httpx = use_httpx
|
95
|
+
|
96
|
+
self._tools: dict[str, str] = {
|
97
|
+
name: TOOL_DOMAIN_MAP.get(name)
|
98
|
+
for name in tools_name
|
99
|
+
}
|
100
|
+
self._session = (
|
101
|
+
httpx.AsyncClient()
|
102
|
+
if use_httpx else
|
103
|
+
aiohttp.ClientSession()
|
104
|
+
)
|
105
|
+
|
106
|
+
def get_base_url(self, tool: str) -> str:
|
107
|
+
check_ok = self._tools.get(tool, None)
|
108
|
+
if check_ok is None:
|
109
|
+
raise ToolNotFoundError(f"Base URL for tool '{tool}' not found.")
|
110
|
+
return check_ok
|
111
|
+
|
112
|
+
def _get_headers_for_tool(self, tool: str) -> dict:
|
113
|
+
base = {"User-Agent": get_user_agent()}
|
114
|
+
if self._use_default_headers and tool in self._api_keys:
|
115
|
+
base.update(random.choice(self._api_keys[tool]))
|
116
|
+
return base
|
117
|
+
|
118
|
+
async def _throttle(self):
|
119
|
+
now = time.monotonic()
|
120
|
+
if now - self._last_reset >= 1:
|
121
|
+
self._last_reset = now
|
122
|
+
self._request_counter = 0
|
123
|
+
|
124
|
+
if self._request_counter >= self._rate_limit:
|
125
|
+
await asyncio.sleep(1 - (now - self._last_reset))
|
126
|
+
self._last_reset = time.monotonic()
|
127
|
+
self._request_counter = 0
|
128
|
+
|
129
|
+
self._request_counter += 1
|
130
|
+
|
131
|
+
@classmethod
|
132
|
+
def from_env(cls) -> "RyzenthApiClient":
|
133
|
+
tools_raw = getenv("RYZENTH_TOOLS")
|
134
|
+
api_key_raw = getenv("RYZENTH_API_KEY_JSON")
|
135
|
+
rate_limit_raw = getenv("RYZENTH_RATE_LIMIT", "5")
|
136
|
+
use_headers = getenv("RYZENTH_USE_HEADERS", "true")
|
137
|
+
use_httpx = getenv("RYZENTH_USE_HTTPX", "false")
|
138
|
+
|
139
|
+
if not tools_raw or not api_key_raw:
|
140
|
+
raise WhatFuckError("Environment variables RYZENTH_TOOLS and RYZENTH_API_KEY_JSON are required.")
|
141
|
+
|
142
|
+
tools = [t.strip() for t in tools_raw.split(",")]
|
143
|
+
api_keys = json.loads(api_key_raw)
|
144
|
+
rate_limit = int(rate_limit_raw)
|
145
|
+
use_default_headers = use_headers.lower() == "true"
|
146
|
+
httpx_flag = use_httpx.lower() == "true"
|
147
|
+
|
148
|
+
return cls(
|
149
|
+
tools_name=tools,
|
150
|
+
api_key=api_keys,
|
151
|
+
rate_limit=rate_limit,
|
152
|
+
use_default_headers=use_default_headers,
|
153
|
+
use_httpx=httpx_flag
|
154
|
+
)
|
155
|
+
|
156
|
+
async def _status_resp_error(self, resp, status_httpx=False):
|
157
|
+
if status_httpx:
|
158
|
+
if resp.status_code == 403:
|
159
|
+
raise ForbiddenError("Access Forbidden: You may be blocked or banned.")
|
160
|
+
elif resp.status_code == 401:
|
161
|
+
raise ForbiddenError("Access Forbidden: Required API key or invalid params.")
|
162
|
+
elif resp.status_code == 500:
|
163
|
+
raise InternalError("Error requests status code 500")
|
164
|
+
else:
|
165
|
+
if resp.status == 403:
|
166
|
+
raise ForbiddenError("Access Forbidden: You may be blocked or banned.")
|
167
|
+
elif resp.status == 401:
|
168
|
+
raise ForbiddenError("Access Forbidden: Required API key or invalid params.")
|
169
|
+
elif resp.status == 500:
|
170
|
+
raise InternalError("Error requests status code 500")
|
171
|
+
|
172
|
+
@AutoRetry(max_retries=3, delay=1.5)
|
173
|
+
async def get(
|
174
|
+
self,
|
175
|
+
tool: str,
|
176
|
+
path: str,
|
177
|
+
params: t.Optional[dict] = None,
|
178
|
+
use_image_content: bool = False
|
179
|
+
) -> t.Union[dict, bytes]:
|
180
|
+
await self._throttle()
|
181
|
+
base_url = self.get_base_url(tool)
|
182
|
+
url = f"{base_url}{path}"
|
183
|
+
headers = self._get_headers_for_tool(tool)
|
184
|
+
|
185
|
+
if self._use_httpx:
|
186
|
+
resp = await self._session.get(url, params=params, headers=headers)
|
187
|
+
await self._status_resp_error(resp, status_httpx=True)
|
188
|
+
resp.raise_for_status()
|
189
|
+
return resp.content if use_image_content else resp.json()
|
190
|
+
else:
|
191
|
+
async with self._session.get(url, params=params, headers=headers) as resp:
|
192
|
+
await self._status_resp_error(resp, status_httpx=False)
|
193
|
+
resp.raise_for_status()
|
194
|
+
return await resp.read() if use_image_content else await resp.json()
|
195
|
+
|
196
|
+
@AutoRetry(max_retries=3, delay=1.5)
|
197
|
+
async def post(
|
198
|
+
self,
|
199
|
+
tool: str,
|
200
|
+
path: str,
|
201
|
+
data: t.Optional[dict] = None,
|
202
|
+
json: t.Optional[dict] = None,
|
203
|
+
use_image_content: bool = False
|
204
|
+
) -> t.Union[dict, bytes]:
|
205
|
+
await self._throttle()
|
206
|
+
base_url = self.get_base_url(tool)
|
207
|
+
url = f"{base_url}{path}"
|
208
|
+
headers = self._get_headers_for_tool(tool)
|
209
|
+
|
210
|
+
if self._use_httpx:
|
211
|
+
resp = await self._session.post(url, data=data, json=json, headers=headers)
|
212
|
+
await self._status_resp_error(resp, status_httpx=True)
|
213
|
+
resp.raise_for_status()
|
214
|
+
return resp.content if use_image_content else resp.json()
|
215
|
+
else:
|
216
|
+
async with self._session.post(url, data=data, json=json, headers=headers) as resp:
|
217
|
+
await self._status_resp_error(resp, status_httpx=False)
|
218
|
+
resp.raise_for_status()
|
219
|
+
return await resp.read() if use_image_content else await resp.json()
|
220
|
+
|
221
|
+
async def close(self):
|
222
|
+
await self._session.close()
|
@@ -1,3 +1,11 @@
|
|
1
|
+
TOOL_DOMAIN_MAP = {
|
2
|
+
"itzpire": "https://itzpire.com",
|
3
|
+
"ryzenth": "https://randydev-ryu-js.hf.space",
|
4
|
+
"onrender": "https://x-api-js.onrender.com",
|
5
|
+
"openai": "https://api.openai.com/v1",
|
6
|
+
"gemini": "https://generativelanguage.googleapis.com/v1"
|
7
|
+
}
|
8
|
+
|
1
9
|
# this API is different
|
2
10
|
|
3
11
|
BASE_DICT_RENDER = {
|
@@ -17,7 +17,7 @@
|
|
17
17
|
# You should have received a copy of the GNU Affero General Public License
|
18
18
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
-
from ._decorators import Decorators
|
20
|
+
from ._decorators import AutoRetry, Decorators
|
21
21
|
from ._federation import FbanAsync, FbanSync
|
22
22
|
from ._fonts import FontsAsync, FontsSync
|
23
23
|
from ._images import ImagesAsync, ImagesSync
|
@@ -41,5 +41,6 @@ __all__ = [
|
|
41
41
|
"FontsSync",
|
42
42
|
"HumanizeAsync",
|
43
43
|
"HumanizeSync",
|
44
|
-
"Decorators"
|
44
|
+
"Decorators",
|
45
|
+
"AutoRetry"
|
45
46
|
]
|
@@ -17,11 +17,33 @@
|
|
17
17
|
# You should have received a copy of the GNU Affero General Public License
|
18
18
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
+
import asyncio
|
20
21
|
from functools import wraps
|
21
22
|
|
23
|
+
import aiohttp
|
24
|
+
import httpx
|
25
|
+
|
22
26
|
from ..types import QueryParameter
|
23
27
|
|
24
28
|
|
29
|
+
def AutoRetry(max_retries: int = 3, delay: float = 1.5):
|
30
|
+
def decorator(func):
|
31
|
+
@wraps(func)
|
32
|
+
async def wrapper(*args, **kwargs):
|
33
|
+
for attempt in range(max_retries):
|
34
|
+
try:
|
35
|
+
return await func(*args, **kwargs)
|
36
|
+
except (
|
37
|
+
httpx.HTTPError,
|
38
|
+
aiohttp.ClientError,
|
39
|
+
asyncio.TimeoutError
|
40
|
+
) as e:
|
41
|
+
if attempt == max_retries - 1:
|
42
|
+
raise e
|
43
|
+
await asyncio.sleep(delay)
|
44
|
+
return wrapper
|
45
|
+
return decorator
|
46
|
+
|
25
47
|
class Decorators:
|
26
48
|
def __init__(self, class_func):
|
27
49
|
self._clients_ai = class_func(..., is_ok=True)
|
@@ -17,6 +17,11 @@
|
|
17
17
|
# You should have received a copy of the GNU Affero General Public License
|
18
18
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
19
19
|
|
20
|
+
import asyncio
|
21
|
+
import logging
|
22
|
+
import os
|
23
|
+
import uuid
|
24
|
+
|
20
25
|
from .._errors import WhatFuckError
|
21
26
|
from ..types import QueryParameter
|
22
27
|
|
@@ -43,7 +48,7 @@ class ImagesAsync:
|
|
43
48
|
|
44
49
|
async def to_save(self, params: QueryParameter, file_path="fluxai.jpg"):
|
45
50
|
content = await self.generate(params)
|
46
|
-
return ResponseFileImage(content).to_save(file_path)
|
51
|
+
return await ResponseFileImage(content).to_save(file_path)
|
47
52
|
|
48
53
|
class ImagesSync:
|
49
54
|
def __init__(self, parent):
|
@@ -66,14 +71,32 @@ class ImagesSync:
|
|
66
71
|
|
67
72
|
def to_save(self, params: QueryParameter, file_path="fluxai.jpg"):
|
68
73
|
content = self.generate(params)
|
69
|
-
return ResponseFileImage(content).
|
74
|
+
return ResponseFileImage(content).sync_to_save(file_path)
|
70
75
|
|
71
76
|
|
72
77
|
class ResponseFileImage:
|
73
78
|
def __init__(self, response_content: bytes):
|
74
79
|
self.response_content = response_content
|
75
80
|
|
76
|
-
def
|
81
|
+
def sync_to_save(self, file_path="fluxai.jpg"):
|
82
|
+
with open(file_path, "wb") as f:
|
83
|
+
f.write(self.response_content)
|
84
|
+
logging.info(f"File saved: {file_path}")
|
85
|
+
return file_path
|
86
|
+
|
87
|
+
async def to_save(self, file_path: str = None, auto_delete: bool = False, delay: int = 5):
|
88
|
+
if file_path is None:
|
89
|
+
file_path = f"{uuid.uuid4().hex}.jpg"
|
90
|
+
|
77
91
|
with open(file_path, "wb") as f:
|
78
92
|
f.write(self.response_content)
|
93
|
+
logging.info(f"File saved: {file_path}")
|
94
|
+
|
95
|
+
if auto_delete:
|
96
|
+
await asyncio.sleep(delay)
|
97
|
+
try:
|
98
|
+
os.remove(file_path)
|
99
|
+
return True
|
100
|
+
except FileNotFoundError:
|
101
|
+
return False
|
79
102
|
return file_path
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: Ryzenth
|
3
|
-
Version: 2.0.
|
3
|
+
Version: 2.0.5
|
4
4
|
Summary: Ryzenth Python Wrapper For Perfomance
|
5
5
|
Author: TeamKillerX
|
6
6
|
License: MIT
|
@@ -125,6 +125,11 @@ export RYZENTH_API_KEY=your-api-key
|
|
125
125
|
## Web scrapers
|
126
126
|
* [`itzpire`](https://itzpire.com) - Team Developer
|
127
127
|
|
128
|
+
## Tool Developer
|
129
|
+
~ Artificial Intelligence
|
130
|
+
- [`OpenAI`](https://platform.openai.com/docs) - OpenAI Docs
|
131
|
+
- [`Gemini AI`](https://ai.google.dev) - Gemini AI Docs
|
132
|
+
|
128
133
|
## Credits
|
129
134
|
|
130
135
|
* Built with love by [xtdevs](https://t.me/xtdevs)
|
ryzenth-2.0.4/Ryzenth/_client.py
DELETED
@@ -1,160 +0,0 @@
|
|
1
|
-
#!/usr/bin/env python
|
2
|
-
# -*- coding: utf-8 -*-
|
3
|
-
# Copyright 2019-2025 (c) Randy W @xtdevs, @xtsea
|
4
|
-
#
|
5
|
-
# from : https://github.com/TeamKillerX
|
6
|
-
# Channel : @RendyProjects
|
7
|
-
# This program is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU Affero General Public License as published by
|
9
|
-
# the Free Software Foundation, either version 3 of the License, or
|
10
|
-
# (at your option) any later version.
|
11
|
-
#
|
12
|
-
# This program is distributed in the hope that it will be useful,
|
13
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
14
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
15
|
-
# GNU Affero General Public License for more details.
|
16
|
-
#
|
17
|
-
# You should have received a copy of the GNU Affero General Public License
|
18
|
-
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
19
|
-
|
20
|
-
import os
|
21
|
-
import platform
|
22
|
-
import typing as t
|
23
|
-
|
24
|
-
import aiohttp
|
25
|
-
from box import Box
|
26
|
-
|
27
|
-
from .__version__ import get_user_agent
|
28
|
-
from ._asynchisded import RyzenthXAsync
|
29
|
-
from ._errors import ForbiddenError, InternalError, ToolNotFoundError, WhatFuckError
|
30
|
-
from ._synchisded import RyzenthXSync
|
31
|
-
from .helper import Decorators
|
32
|
-
|
33
|
-
|
34
|
-
class ApiKeyFrom:
|
35
|
-
def __init__(self, api_key: str = None, is_ok=False):
|
36
|
-
if api_key is Ellipsis:
|
37
|
-
is_ok = True
|
38
|
-
api_key = None
|
39
|
-
|
40
|
-
if not api_key:
|
41
|
-
api_key = os.environ.get("RYZENTH_API_KEY")
|
42
|
-
|
43
|
-
if not api_key:
|
44
|
-
api_key = "akeno_UKQEQMt991kh2Ehh7JqJYKapx8CCyeC" if is_ok else None
|
45
|
-
|
46
|
-
self.api_key = api_key
|
47
|
-
self.aio = RyzenthXAsync(api_key)
|
48
|
-
self._sync = RyzenthXSync(api_key)
|
49
|
-
|
50
|
-
def something(self):
|
51
|
-
pass
|
52
|
-
|
53
|
-
class UrHellFrom:
|
54
|
-
def __init__(self, name: str, only_author=False):
|
55
|
-
self.decorators = Decorators(ApiKeyFrom)
|
56
|
-
self.ai = self.decorators.send_ai(name=name, only_author=only_author)
|
57
|
-
|
58
|
-
def something(self):
|
59
|
-
pass
|
60
|
-
|
61
|
-
class SmallConvertDot:
|
62
|
-
def __init__(self, obj):
|
63
|
-
self.obj = obj
|
64
|
-
|
65
|
-
def to_dot(self):
|
66
|
-
return Box(self.obj if self.obj is not None else {})
|
67
|
-
|
68
|
-
TOOL_DOMAIN_MAP = {
|
69
|
-
"itzpire": "https://itzpire.com",
|
70
|
-
"ryzenth": "https://randydev-ryu-js.hf.space",
|
71
|
-
}
|
72
|
-
|
73
|
-
class RyzenthApiClient:
|
74
|
-
def __init__(
|
75
|
-
self,
|
76
|
-
*,
|
77
|
-
api_key: str,
|
78
|
-
tools_name: list[str],
|
79
|
-
use_default_headers: bool = False
|
80
|
-
) -> None:
|
81
|
-
if not api_key:
|
82
|
-
raise WhatFuckError("API Key cannot be empty.")
|
83
|
-
if not tools_name:
|
84
|
-
raise WhatFuckError("A non-empty list of tool names must be provided for 'tools_name'.")
|
85
|
-
|
86
|
-
self._api_key: str = api_key
|
87
|
-
self._use_default_headers: bool = use_default_headers
|
88
|
-
self._session: aiohttp.ClientSession = aiohttp.ClientSession(
|
89
|
-
headers={
|
90
|
-
"User-Agent": get_user_agent(),
|
91
|
-
**({"x-api-key": self._api_key} if self._use_default_headers else {})
|
92
|
-
}
|
93
|
-
)
|
94
|
-
self._tools: dict[str, str] = {
|
95
|
-
name: TOOL_DOMAIN_MAP.get(name)
|
96
|
-
for name in tools_name
|
97
|
-
}
|
98
|
-
|
99
|
-
def get_base_url(self, tool: str) -> str:
|
100
|
-
check_ok = self._tools.get(tool, None)
|
101
|
-
if check_ok is None:
|
102
|
-
raise ToolNotFoundError(f"Base URL for tool '{tool}' not found.")
|
103
|
-
return check_ok
|
104
|
-
|
105
|
-
@classmethod
|
106
|
-
def from_env(cls) -> "RyzenthApiClient":
|
107
|
-
api_key: t.Optional[str] = os.environ.get("RYZENTH_API_KEY")
|
108
|
-
if not api_key:
|
109
|
-
raise WhatFuckError("API Key cannot be empty.")
|
110
|
-
return cls(api_key=api_key)
|
111
|
-
|
112
|
-
async def _status_resp_error(self, resp):
|
113
|
-
if resp.status == 403:
|
114
|
-
raise ForbiddenError("Access Forbidden: You may be blocked or banned.")
|
115
|
-
if resp.status == 500:
|
116
|
-
raise InternalError("Error requests status code 5000")
|
117
|
-
|
118
|
-
async def get(
|
119
|
-
self,
|
120
|
-
tool: str,
|
121
|
-
path: str,
|
122
|
-
params: t.Optional[dict] = None
|
123
|
-
) -> dict:
|
124
|
-
base_url = self.get_base_url(tool)
|
125
|
-
url = f"{base_url}{path}"
|
126
|
-
try:
|
127
|
-
async with self._session.get(url, params=params) as resp:
|
128
|
-
await self._status_resp_error(resp)
|
129
|
-
resp.raise_for_status()
|
130
|
-
return await resp.json()
|
131
|
-
except ForbiddenError as e:
|
132
|
-
return {"error": str(e)}
|
133
|
-
except aiohttp.ClientResponseError as e:
|
134
|
-
return {"error": f"HTTP Error: {e.status} {e.message}"}
|
135
|
-
except Exception as e:
|
136
|
-
return {"error": str(e)}
|
137
|
-
|
138
|
-
async def post(
|
139
|
-
self,
|
140
|
-
tool: str,
|
141
|
-
path: str,
|
142
|
-
data: t.Optional[dict] = None,
|
143
|
-
json: t.Optional[dict] = None
|
144
|
-
) -> dict:
|
145
|
-
base_url = self.get_base_url(tool)
|
146
|
-
url = f"{base_url}{path}"
|
147
|
-
try:
|
148
|
-
async with self._session.post(url, data=data, json=json) as resp:
|
149
|
-
await self._status_resp_error(resp)
|
150
|
-
resp.raise_for_status()
|
151
|
-
return await resp.json()
|
152
|
-
except ForbiddenError as e:
|
153
|
-
return {"error": str(e)}
|
154
|
-
except aiohttp.ClientResponseError as e:
|
155
|
-
return {"error": f"HTTP Error: {e.status} {e.message}"}
|
156
|
-
except Exception as e:
|
157
|
-
return {"error": str(e)}
|
158
|
-
|
159
|
-
async def close(self):
|
160
|
-
await self._session.close()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|