Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

Commit 2d0e25a

Browse files
committed
feat: Dify加入Http代理
1 parent 2e35637 commit 2d0e25a

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

plugins/all_in_one_config.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ price = 0 # 用一次扣积分,如果0则不扣
1717
admin_ignore = true #admin是否忽略扣除
1818
whitelist_ignore = true #白名单是否忽略扣除
1919

20+
# Http代理设置
21+
# 格式: http://用户名:密码@代理地址:代理端口
22+
# 例如:http://127.0.0.1:7890
23+
http-proxy = ""
24+
2025
[BotStatus]
2126
enable = true
2227
command = ["status", "bot", "机器人状态", "状态"]

plugins/dify.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def __init__(self):
4343
self.admin_ignore = plugin_config["admin_ignore"]
4444
self.whitelist_ignore = plugin_config["whitelist_ignore"]
4545

46+
self.http_proxy = plugin_config["http-proxy"]
47+
4648
self.db = BotDatabase()
4749

4850
@on_text_message
@@ -174,7 +176,7 @@ async def dify(self, bot: WechatAPIClient, message: dict, query: str, files=None
174176
url = f"{self.base_url}/chat-messages"
175177

176178
ai_resp = ""
177-
async with aiohttp.ClientSession() as session:
179+
async with aiohttp.ClientSession(proxy=self.http_proxy) as session:
178180
async with session.post(url=url, headers=headers, data=payload) as resp:
179181
if resp.status == 200:
180182
# 读取响应
@@ -238,7 +240,7 @@ async def upload_file(self, user: str, file: bytes):
238240

239241
url = f"{self.base_url}/files/upload"
240242

241-
async with aiohttp.ClientSession() as session:
243+
async with aiohttp.ClientSession(proxy=self.http_proxy) as session:
242244
async with session.post(url, headers=headers, data=formdata) as resp:
243245
resp_json = await resp.json()
244246

@@ -267,16 +269,14 @@ async def dify_handle_text(self, bot: WechatAPIClient, message: dict, text: str)
267269
if text:
268270
await bot.send_at_message(message["FromWxid"], "\n" + text, [message["SenderWxid"]])
269271

270-
@staticmethod
271-
async def download_file(url: str) -> bytes:
272-
async with aiohttp.ClientSession() as session:
272+
async def download_file(self, url: str) -> bytes:
273+
async with aiohttp.ClientSession(proxy=self.http_proxy) as session:
273274
async with session.get(url) as resp:
274275
return await resp.read()
275276

276-
@staticmethod
277-
async def dify_handle_image(bot: WechatAPIClient, message: dict, image: Union[str, bytes]):
277+
async def dify_handle_image(self, bot: WechatAPIClient, message: dict, image: Union[str, bytes]):
278278
if isinstance(image, str) and image.startswith("http"):
279-
async with aiohttp.ClientSession() as session:
279+
async with aiohttp.ClientSession(proxy=self.http_proxy) as session:
280280
async with session.get(image) as resp:
281281
image = bot.byte_to_base64(await resp.read())
282282
elif isinstance(image, bytes):

0 commit comments

Comments
 (0)