feat: 支持gewechat文件输出

This commit is contained in:
Soulter
2025-02-10 18:46:54 +08:00
parent aa276ca6af
commit 0a970e8c31
3 changed files with 38 additions and 3 deletions
@@ -153,12 +153,11 @@ class SimpleGewechatClient():
with open(file_path, "wb") as f:
f.write(voice_data)
abm.message.append(Record(file=file_path, url=file_path))
case _:
logger.info(f"未实现的消息类型: {d['MsgType']}")
return
logger.info(f"abm: {abm}")
logger.debug(f"abm: {abm}")
return abm
async def callback(self):
@@ -363,4 +362,21 @@ class SimpleGewechatClient():
json=payload
) as resp:
json_blob = await resp.json()
logger.debug(f"发送语音结果: {json_blob}")
logger.debug(f"发送语音结果: {json_blob}")
async def post_file(self, to_wxid, file_url: str, file_name: str):
payload = {
"appId": self.appid,
"toWxid": to_wxid,
"fileUrl": file_url,
"fileName": file_name
}
async with aiohttp.ClientSession() as session:
async with session.post(
f"{self.base_url}/message/postFile",
headers=self.headers,
json=payload
) as resp:
json_blob = await resp.json()
logger.debug(f"发送文件结果: {json_blob}")
@@ -123,5 +123,21 @@ class GewechatPlatformEvent(AstrMessageEvent):
file_id = os.path.basename(silk_path)
record_url = f"{self.client.file_server_url}/{file_id}"
logger.debug(f"gewe callback record url: {record_url}")
await self.client.post_voice(to_wxid, record_url, duration*1000)
elif isinstance(comp, File):
file_path = comp.file
file_name = comp.name
if file_path.startswith("file:///"):
file_path = file_path[8:]
elif file_path.startswith("http"):
await download_file(file_path, f"data/temp/{file_name}")
else:
file_path = file_path
file_id = os.path.basename(file_path)
file_url = f"{self.client.file_server_url}/{file_id}"
logger.debug(f"gewe callback file url: {file_url}")
await self.client.post_file(to_wxid, file_url, file_id)
await super().send(message)
@@ -100,6 +100,9 @@ class ProviderOpenAIOfficial(Provider):
llm_response.role = "tool"
llm_response.tools_call_args = args_ls
llm_response.tools_call_name = func_name_ls
if choice.finish_reason == 'content_filter':
raise Exception("API 返回的 completion 由于内容安全过滤被拒绝(非 AstrBot)。")
if not llm_response.completion_text and not llm_response.tools_call_args:
logger.error(f"API 返回的 completion 无法解析:{completion}")