diff --git a/astrbot/core/platform/sources/gewechat/client.py b/astrbot/core/platform/sources/gewechat/client.py index 7e935a1e4..66eded18c 100644 --- a/astrbot/core/platform/sources/gewechat/client.py +++ b/astrbot/core/platform/sources/gewechat/client.py @@ -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}") \ No newline at end of file + 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}") \ No newline at end of file diff --git a/astrbot/core/platform/sources/gewechat/gewechat_event.py b/astrbot/core/platform/sources/gewechat/gewechat_event.py index 8ed1c5fd7..da94aff66 100644 --- a/astrbot/core/platform/sources/gewechat/gewechat_event.py +++ b/astrbot/core/platform/sources/gewechat/gewechat_event.py @@ -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) \ No newline at end of file diff --git a/astrbot/core/provider/sources/openai_source.py b/astrbot/core/provider/sources/openai_source.py index 051029806..8062a055c 100644 --- a/astrbot/core/provider/sources/openai_source.py +++ b/astrbot/core/provider/sources/openai_source.py @@ -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}。")