当前位置: 首页 > news >正文

qq机器人 连接本地llm 注意这个c2c

tencent-connect/botpy: QQ频道机器人PythonSDK

tencent-connect/botpy | DeepWiki

2026-02-23 13:03:09,652 | INFO | _toolkit:register_agent_skill:1104 - Registered agent skill 'web_skill' from directory 'skills\web_skill'. 2026-02-23 13:03:09,653 | INFO | _toolkit:register_agent_skill:1104 - Registered agent skill 'ue_skill' from directory 'skills\ue_skill'. 2026-02-23 13:03:09,653 | INFO | _toolkit:register_agent_skill:1104 - Registered agent skill 'blenderskill' from directory 'skills\blender_skill'. 🚀 启动 QQ 机器人... 🤖 使用模型: 杜野りんせ 💬 机器人已准备就绪,等待消息... [INFO] (client.py:162)_bot_login [botpy] 登录机器人账号中... [INFO] (robot.py:65)update_access_token [botpy] access_token expires_in 6263 e:\code\my_python_server\.venv\lib\site-packages\botpy\http.py:153: DeprecationWarning: ssl.SSLContext() without protocol argument is deprecated. connector=TCPConnector(limit=500, ssl=SSLContext(), force_close=True), e:\code\my_python_server\.venv\lib\site-packages\botpy\http.py:153: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated connector=TCPConnector(limit=500, ssl=SSLContext(), force_close=True), [INFO] (client.py:181)_bot_init [botpy] 程序启动... [INFO] (connection.py:60)multi_run [botpy] 最大并发连接数: 1, 启动会话数: 1 [INFO] (client.py:242)bot_connect [botpy] 会话启动中... [INFO] (gateway.py:115)ws_connect [botpy] 启动中... e:\code\my_python_server\.venv\lib\site-packages\botpy\gateway.py:121: DeprecationWarning: ssl.SSLContext() without protocol argument is deprecated. async with ClientSession(connector=TCPConnector(limit=10, ssl=SSLContext())) as session: e:\code\my_python_server\.venv\lib\site-packages\botpy\gateway.py:121: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated async with ClientSession(connector=TCPConnector(limit=10, ssl=SSLContext())) as session: [INFO] (gateway.py:142)ws_identify [botpy] 鉴权中... [INFO] (gateway.py:85)on_message [botpy] 机器人「杜野凛世-测试中」启动成功! [INFO] (gateway.py:223)_send_heart [botpy] 心跳维持启动... (.venv) PS E:\code\my_python_server> e:; cd 'e:\code\my_python_server'; & 'e:\code\my_python_server\.venv\Scripts\python.exe' 'c:\Users\njsgcs\.lingma\extensions\ms-python.debugpy-2025.19.2026021801-win32-x64\bundled\libs\debugpy\launcher' '65027' '--' 'E:\code\my_python_server\front\qq\qqbot.py' 2026-02-23 13:09:29,053 | INFO | _toolkit:register_agent_skill:1104 - Registered agent skill 'web_skill' from directory 'skills\web_skill'. 2026-02-23 13:09:29,054 | INFO | _toolkit:register_agent_skill:1104 - Registered agent skill 'ue_skill' from directory 'skills\ue_skill'. 2026-02-23 13:09:29,054 | INFO | _toolkit:register_agent_skill:1104 - Registered agent skill 'blenderskill' from directory 'skills\blender_skill'. 🚀 启动 QQ 机器人... 🤖 使用模型: 杜野りんせ 💬 支持频道@消息和好友私聊 ⏳ 正在连接... [INFO] (client.py:162)_bot_login [botpy] 登录机器人账号中... [INFO] (robot.py:65)update_access_token [botpy] access_token expires_in 5883 e:\code\my_python_server\.venv\lib\site-packages\botpy\http.py:153: DeprecationWarning: ssl.SSLContext() without protocol argument is deprecated. connector=TCPConnector(limit=500, ssl=SSLContext(), force_close=True), e:\code\my_python_server\.venv\lib\site-packages\botpy\http.py:153: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated connector=TCPConnector(limit=500, ssl=SSLContext(), force_close=True), [INFO] (client.py:181)_bot_init [botpy] 程序启动... [INFO] (connection.py:60)multi_run [botpy] 最大并发连接数: 1, 启动会话数: 1 [INFO] (client.py:242)bot_connect [botpy] 会话启动中... [INFO] (gateway.py:115)ws_connect [botpy] 启动中... e:\code\my_python_server\.venv\lib\site-packages\botpy\gateway.py:121: DeprecationWarning: ssl.SSLContext() without protocol argument is deprecated. async with ClientSession(connector=TCPConnector(limit=10, ssl=SSLContext())) as session: e:\code\my_python_server\.venv\lib\site-packages\botpy\gateway.py:121: DeprecationWarning: ssl.PROTOCOL_TLS is deprecated async with ClientSession(connector=TCPConnector(limit=10, ssl=SSLContext())) as session: [INFO] (gateway.py:142)ws_identify [botpy] 鉴权中... [INFO] (gateway.py:85)on_message [botpy] 机器人「杜野凛世-测试中」启动成功! [INFO] (gateway.py:223)_send_heart [botpy] 心跳维持启动... [2026-02-23 13:09:29] [on_ready] 机器人已上线 ✅ 支持频道消息和好友私聊 [2026-02-23 13:09:38] [C2C消息] 你好 杜野りんせ: こんにちは!何かお手伝いできることがありますか? [2026-02-23 13:09:38] [C2C回复] こんにちは!何かお手伝いできることがあります か?

llmchat方法自己实现接受一个输入返回一个输出就行

import sys import os sys.path.append(os.getcwd()) import botpy from botpy.message import Message, C2CMessage import asyncio from typing import Callable from datetime import datetime # 导入你的 LLM 聊天函数 from agent_scope.chat_llm import llm_chat from share_config.api_key import qq_appid, qq_secret class QQBotClient(botpy.Client): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.chat_handler: Callable[[str], str] = None def set_chat_handler(self, handler: Callable[[str], str]): """注册聊天处理函数""" if not callable(handler): raise ValueError("handler 必须是可调用对象") self.chat_handler = handler async def _call_handler(self, text: str) -> str: """统一调用同步/异步 handler""" if asyncio.iscoroutinefunction(self.chat_handler): return await self.chat_handler(text) else: return self.chat_handler(text) async def on_ready(self): """机器人启动完成回调""" print(f"[{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}] [on_ready] 机器人已上线") print("✅ 支持频道消息和好友私聊") async def on_at_message_create(self, message: Message): """频道@消息处理""" if not self.chat_handler: await message.reply(content="聊天服务未初始化") return # 获取用户消息内容 user_text = message.content or "" timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') print(f"[{timestamp}] [频道消息] {user_text}") try: # 调用你的 LLM 处理函数 reply_text = await self._call_handler(user_text) print(f"[{timestamp}] [频道回复] {reply_text[:100]}{'...' if len(reply_text) > 100 else ''}") # 如果回复内容过长,分段发送 if len(reply_text) > 1000: chunks = [reply_text[i:i+1000] for i in range(0, len(reply_text), 1000)] for chunk in chunks: await message.reply(content=chunk) else: await message.reply(content=reply_text) except Exception as e: error_msg = f"处理消息时出错: {str(e)}" print(f"[{timestamp}] [频道错误] {error_msg}") await message.reply(content=error_msg) async def on_c2c_message_create(self, message: C2CMessage): """C2C好友私聊消息处理""" if not self.chat_handler: await self.api.post_c2c_message( openid=message.author.user_openid, content="聊天服务未初始化" ) return # 获取用户消息内容 user_text = message.content or "" timestamp = datetime.now().strftime('%Y-%m-%d %H:%M:%S') print(f"[{timestamp}] [C2C消息] {user_text}") try: # 调用你的 LLM 处理函数 reply_text = await self._call_handler(user_text) print(f"[{timestamp}] [C2C回复] {reply_text[:100]}{'...' if len(reply_text) > 100 else ''}") # 发送 C2C 回复 await self.api.post_c2c_message( openid=message.author.user_openid, content=reply_text ) except Exception as e: error_msg = f"处理消息时出错: {str(e)}" print(f"[{timestamp}] [C2C错误] {error_msg}") await self.api.post_c2c_message( openid=message.author.user_openid, content=error_msg ) def main(): # 创建机器人实例 - 开启公域 C2C/群消息 intents = botpy.Intents(public_messages=True) client = QQBotClient(intents=intents) # 注册你的 LLM 聊天处理函数 client.set_chat_handler(llm_chat) # 启动机器人 print("🚀 启动 QQ 机器人...") print(f"🤖 使用模型: 杜野りんせ") print("💬 支持频道@消息和好友私聊") print("⏳ 正在连接...") client.run(appid=qq_appid, secret=qq_secret) if __name__ == "__main__": main()
http://www.jsqmd.com/news/405374/

相关文章:

  • python基于django框架和协同过滤算法的图书推荐系统设计与实现_7b2iz8a3
  • jspm酒店客房预定系统_65gd09g4
  • 5家抖音优化推广公司服务和优势拆解
  • python健身房管理系统(编号:27805230)
  • java基于springboot框架的APP开发者信息管理平台的设计与实现(编号:40791381)安卓
  • 开题报告总被退回?别再靠“感觉”写了!百考通AI 10分钟生成导师点赞的开题初稿
  • 真的太省时间! 降AI率网站 千笔·降AI率助手 VS 云笔AI
  • 开题卡在综述?百考通AI输入关键词,输出可直接用的综述初稿!
  • Claude Code 免费从入门到精通
  • 2026苏州会展市场新动态:这些公司值得关注,展台搭建/展陈设计/展位搭建/展览搭建/展厅装修/展览,会展企业口碑推荐 - 品牌推荐师
  • 不是复制粘贴!百考通AI生成原创性文献综述,查重友好+AI检测安全
  • Pinia action深度解析
  • 从50篇论文到一篇综述,百考通AI帮你提炼、归纳、学术化表达!
  • 技术日报|龙虾AI助手openclaw二连冠日增2380星持续领跑,多智能体平台rowboat强势登榜第二
  • 告别东拼西凑!百考通AI智能梳理领域研究脉络,自动生成高质量综述
  • 激光设备品牌怎么选?主流厂商实力深度对比
  • 文献综述总被说“堆砌”?试试百考通AI——有观点、有脉络、有深度!
  • 文献看不完?百考通AI 5分钟生成逻辑清晰、引用规范的文献综述!
  • 技术日报|龙虾AI助手openclaw强势回归日增3873星破20万,阿里向量数据库zvec爆火登榜第二
  • 实测才敢推!专科生专属AI论文网站 —— 千笔·专业论文写作工具
  • 导师夸我文献功底深?其实我用了百考通AI——结构严谨、0抄袭风险!
  • 2026别错过!AI论文网站 千笔 VS 万方智搜AI,研究生写作神器!
  • 2026农业高精度气象:别再卷“温度准不准”!把灾害做成“物候期命中概率”,才是真减灾
  • 毕业季自救指南:用AI工具高质量通关论文全流程
  • 2026风电功率预测:别再盯着平均风速!把“阵风尾部”做成风险指标,让Ramp曲线稳下来
  • 从“瞎猜”到“学会”:深度拆解神经网络如何通过梯度下降实现智能
  • 数据分析在P2P平台用户风险分析中的应用
  • 2026风电光伏功率预测:别再只给一条曲线!调度和交易真正要的是“三张表”——区间(P10/P50/P90) + 风险等级 + 动作建议
  • 建议收藏|9个降AI率网站测评:继续教育必备工具全解析
  • 大专政务大数据应用专业学习数据分析的价值分析