新增插件智能模式适配 (#1850)

* 新增插件智能模式适配

* 🚨 auto fix by pre-commit hooks

* 更改类名,命名更清晰

* 🎨 添加模块化参数

* 🎨  AI模块化修改

* 🩹  道具调用修复

* 🩹 修复商品使用前检测

* ✨ retry增加参数适配

* ✨  修改道具使用函数参数传递

* ✨ 捕获道具无法使用异常

* 🐛 添加依赖require

* 🐛  修复插件使用问题

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: HibiKier <45528451+HibiKier@users.noreply.github.com>
This commit is contained in:
ChthollyWn
2025-02-24 09:28:53 +08:00
committed by GitHub
co-authored by pre-commit-ci[bot] HibiKier
parent 78df9ed086
commit a6ddb726d3
5 changed files with 97 additions and 40 deletions
+14 -6
View File
@@ -1,16 +1,24 @@
from anyio import EndOfStream
from httpx import ConnectError, HTTPStatusError, TimeoutException
from tenacity import retry, retry_if_exception_type, stop_after_attempt, wait_fixed
class Retry:
@staticmethod
def api():
def api(
retry_count: int = 3, wait: int = 1, exception: tuple[type[Exception], ...] = ()
):
"""接口调用重试"""
base_exceptions = (
TimeoutException,
ConnectError,
HTTPStatusError,
EndOfStream,
*exception,
)
return retry(
reraise=True,
stop=stop_after_attempt(3),
wait=wait_fixed(1),
retry=retry_if_exception_type(
(TimeoutException, ConnectError, HTTPStatusError)
),
stop=stop_after_attempt(retry_count),
wait=wait_fixed(wait),
retry=retry_if_exception_type(base_exceptions),
)