首页 » 技术资讯 » AI Agent项目实战(04)-让你的AI Agent接入机器人!(机器人接入实战项目架构)

AI Agent项目实战(04)-让你的AI Agent接入机器人!(机器人接入实战项目架构)

神尊大人 2024-07-24 01:23:43 技术资讯 0

扫一扫用手机浏览

文章目录 [+]

这个才是正版!

1.1 新建一个机器人

1.2 编辑机器人信息

AI Agent项目实战(04)-让你的AI Agent接入机器人!(机器人接入实战项目架构) AI Agent项目实战(04)-让你的AI Agent接入机器人!(机器人接入实战项目架构) 技术资讯
(图片来自网络侵删)

编辑“关于”信息:

设置机器人头像

AI Agent项目实战(04)-让你的AI Agent接入机器人!(机器人接入实战项目架构) AI Agent项目实战(04)-让你的AI Agent接入机器人!(机器人接入实战项目架构) 技术资讯
(图片来自网络侵删)

行了,直接访问 bot 吧!

2 引入telebot包

import telebot# 之前获取的 user tokenbot = telebot.TeleBot('xxx:xxx')3 编写客户端代码

@bot.message_handler(commands=['start'])def start_message(message): bot.send_message(message.chat.id, '你好我是JavaEdge,欢迎光临!')

python tele-qwen.py

启动项目,对话 bot,即可看到

3.1 指定回复

3.2 引用&&回复

@bot.message_handler(commands=['start'])def start_message(message): bot.reply_to(message, '你好!')4 将 bot 关联到 server 端

即关联到 chat 接口:

@bot.message_handler(func=lambda message: True)def echo_all(message): # bot.reply_to(message, message.text) try: encoded_text = urllib.parse.quote(message.text) response = requests.post('http://localhost:8090/chat?query=' + encoded_text, timeout=100) if response.status_code == 200: ai_say = json.loads(response.text) if "msg" in ai_say: bot.reply_to(message, ai_say["msg"]["output"]) audio_path = f"{ai_say['id']}.mp3" asyncio.run(check_audio(message, audio_path)) else: bot.reply_to(message, "对不起,我不知道怎么回答你") except requests.RequestException as e: bot.reply_to(message, "对不起,我不知道怎么回答你")async def check_audio(message, audio_path): while True: if os.path.exists(audio_path): with open(audio_path, 'rb') as f: bot.send_audio(message.chat.id, f) os.remove(audio_path) break else: print("waiting") await asyncio.sleep(1)bot.infinity_polling()

这样就能将 LLM 的回复响应给 tg 用户:

参考:

tg api

关注我,紧跟本系列专栏文章,咱们下篇再续!

作者简介:魔都架构师,多家大厂后端一线研发经验,在分布式系统设计、数据平台架构和AI应用开发等领域都有丰富实践经验。

各大技术社区头部专家博主。
具有丰富的引领团队经验,深厚业务架构和解决方案的积累。

负责:

中央/分销预订系统性能优化

活动&券等营销中台建设

交易平台及数据中台等架构和开发设计

车联网核心平台-物联网连接平台、大数据平台架构设计及优化

LLM应用开发

目前主攻降低软件复杂性设计、构建高可用系统方向。

参考:

编程严选网
标签:

相关文章