Comments (2)
这不太难,下面是响应端发送消息的小示例。
平台配置
在 https://github.com/LlmKira/Openaibot/tree/main/app/setting 新建新文件即可,抄写已有的模组。在run中直接调用。如果没有配置就结束协程。(我们在 https://github.com/LlmKira/Openaibot/blob/main/app/sender/app.py 和 https://github.com/LlmKira/Openaibot/blob/main/app/receiver/app.py 注册入口程序,继承实现后放在这里)
发送消息
TelegramTask = Task(queue=__sender__)
uploaded_file = [
await File.upload_file(
creator=uid, file_name=name, file_data=downloaded_bytes_file
)
]
event_message = await self.transcribe( # 这里是转译,将上传的文件和消息转译为通用消息,不同类不同实现
last_message=message, # 平台的消息
messages=history_message_list, # 如果消息回复了其他消息,这里的参数就是其他消息,和 last_message 一个类型
files=uploaded_file,
)
sign = Sign.from_root( # 关于函数调用的设置
disable_tool_action=disable_tool_action,
response_snapshot=True,
platform=__sender__,
)
_, event_message, sign = await self.hook( # Hook,原样复制即可
platform=__sender__, messages=event_message, sign=sign
)
# Reply
success, logs = await TelegramTask.send_task(
task=TaskHeader.from_sender(
task_sign=sign,
event_messages=event_message,
chat_id=str(message.chat.id),
user_id=str(message.from_user.id),
message_id=str(message.message_id),
platform=__sender__,
)
)
将消息转换为通用消息,即可从这里发送出去。完成接受发送两端的继承,即可完成新的平台支持。
建议直接照抄已有的 sender 代码进行更改。
接收LLM的消息
直接抄写 https://github.com/LlmKira/Openaibot/blob/main/app/receiver/telegram/__init__.py 即可,将其中的发送方法改为 SDK 对应的发送方法
示例
https://github.com/LlmKira/Openaibot/blob/main/app/sender/telegram/__init__.py#L224 (投送消息进入消息队列)
https://github.com/LlmKira/Openaibot/blob/main/app/receiver/telegram/__init__.py#L117 (从消息队列中收取LLM的响应)
问题是引入可靠的SDK。
需要注意的是,收发消息是解耦的,信息需要在 EventMessage 通用信息类中传递。
from openaibot.
你可以先提 draft pr 同步进度,方便一起行动
from openaibot.
Related Issues (20)
- TelegramReply Fix
- FFmpeg Converter
- Handle `VOICE_MESSAGES_FORBIDDEN` for telegram
- Docs Update
- Async Chain Release / 异步逻辑指名释放 HOT 1
- 🍖search\_in\_google Run Failed:No module named 'duckduckgo\_search'
- Zeabur Template
- 平台指定支持
- [BUG] Make api_key a SecretStr
- Change To Azure
- [BUG] docker compose 安装运行, ValueError: Exception is not allowed in handle_exceptions HOT 1
- [BUG] Too many trash code
- Plugin Hook
- Image Input
- Roadmap
- tool_ghost HOT 1
- Fix
- Fix
- Support User Whitelist
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from openaibot.