Skip to content

Latest commit

 

History

History
118 lines (91 loc) · 4.22 KB

plugin.md

File metadata and controls

118 lines (91 loc) · 4.22 KB

怎样开发插件

  • YLBot的插件理念不同于以往任意一个机器人,它不局限SQL查询,它关注自动化和更智能的语义理解,插件的作用是给LLM提供我们预定内容的上下文,它完全依赖语言模型的推理能力,得出答案和结果。

  • 插件必须放在./plugins目录下,一个python文件就是一个插件,文件里必须是函数

插件示意图

串行模式

# 主函数
def fun_add(name_space, function_type, post_type, user_state, priority, block=False):
    def decorator(func):
        func._name_space = name_space
        func._function_type = function_type
        func._post_type = post_type
        func._priority = priority
        func._user_state = user_state
        func._block = block
        return func
    return decorator

# 全局变量
msg = 0

# 子函数示例1
@fun_add(name_space="test", function_type="serial", post_type="message", user_state="插件问答", priority=0)
def fun_add_1(data={}): # 第一个函数的参数必须为字典类型
    global msg
    msg = 10000
    return msg

# 子函数示例2
@fun_add(name_space="test", function_type="serial", post_type="message", user_state="插件问答", priority=1, block=True)
def fun_add_2(data):
    global msg
    msg += 1
    return msg

# 子函数示例3
@fun_add(name_space="test", function_type="serial", post_type="message", user_state="插件问答", priority=2)
def fun_add_3(data):
    global msg
    msg += 1
    return msg

并行模式

################# 主函数 ##################
def fun_my_plugin(name_space, function_type, post_type, user_state, priority, block=False):
    def decorator(func):
        func._name_space = name_space
        func._function_type = function_type
        func._post_type = post_type
        func._priority = priority
        func._user_state = user_state
        func._block = block
        return func
    return decorator





################# 子函数 ##################
# 插件函数示例1
@fun_my_plugin(name_space="test", function_type="parallel", post_type="message", user_state="插件问答", priority=3)
def fun_1(data):
    msg = f"他今年45岁了"
    # 必须返回字符结果
    return msg

# 插件函数示例2
@fun_my_plugin(name_space="test", function_type="parallel", post_type="message", user_state="插件问答", priority=4, block=True)
def fun_2(data):
    msg = f"他喜欢国学文化"
    return msg

# 插件函数示例3
@fun_my_plugin(name_space="test", function_type="parallel", post_type="message", user_state="插件问答", priority=5)
def fun_3(data):
    msg = f"元龙居士原来是一个养猪的人"
    return msg

总程序会将串行、并行两种模式的所有结果全部交给LLM综合分析推理。