Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 如果支持微信 或者更多的聊天客户端 有没有文档说明呢? #418

Open
thinker007 opened this issue Jul 31, 2024 · 2 comments
Labels
New Features New feature or request

Comments

@thinker007
Copy link

如何支持微信或者更多的聊天客户端?

我可以贡献代码,不过需要一些指引。

@sudoskys
Copy link
Member

sudoskys commented Jul 31, 2024

这不太难,下面是响应端发送消息的小示例。

平台配置

https://github.com/LlmKira/Openaibot/tree/main/app/setting 新建新文件即可,抄写已有的模组。在run中直接调用。如果没有配置就结束协程。(我们在 https://github.com/LlmKira/Openaibot/blob/main/app/sender/app.pyhttps://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 通用信息类中传递。

@sudoskys sudoskys added the New Features New feature or request label Jul 31, 2024
@sudoskys
Copy link
Member

你可以先提 draft pr 同步进度,方便一起行动

@sudoskys sudoskys changed the title 如果支持微信 或者更多的聊天客户端 有没有文档说明呢? feat: 如果支持微信 或者更多的聊天客户端 有没有文档说明呢? Jul 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
New Features New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants