Coder Social home page Coder Social logo

Comments (2)

sudoskys avatar sudoskys commented on September 27, 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 通用信息类中传递。

from openaibot.

sudoskys avatar sudoskys commented on September 27, 2024

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

from openaibot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.