跳转到主要内容

模块化可组合聊天机器人开发

项目描述

Discord

代理(agt)

代理是一个用于使用会话组件构建聊天机器人的高级工具包。如果您想使用可组合组件使聊天机器人模块化,请尝试代理。

安装

# optional: create a virtual environment
python3 -m venv myvenv
source myvenv/bin/activate

# install agt
pip3 install agt

其他依赖项

您可能想安装依赖项以连接到如telegram和discord等渠道或共享cocohub上的组件。

可用的依赖项

  • discord - 将您的机器人/组件连接到discord
  • telegram - 将您的机器人/组件连接到telegram
  • msbf - 将您的机器人/组件连接到微软机器人框架
  • vendor - 在cocohub上发布组件
  • dsl - Hy DSL,用于构建组件/nlu时提供更简洁的语法

示例

pip install agt[telegram]
# or for multiple dependecies
pip install agt[telegram,dsl]

入门

创建您的第一个机器人

代理组件是Python协程(注意async def

我们将state作为第一个参数 - 这是一个对象,允许我们与环境交互,该组件/机器人在其上运行

async def mybot(state):
    # state.user_input() waits for the next user input
    user_input = await state.user_input()

    # state.say sends a response
    await state.say(user_input)

将此代码粘贴到名为example.py的文件中

在终端中尝试运行它

python3 -m agt example.mybot

渠道

连接到渠道非常简单,只需使用常规的代理组件即可

Telegram

请确保安装带有telegram支持的agt - pip install agt[telegram]

创建一个新的机器人并使用以下指南从Telegram机器人父亲那里获取Telegram令牌: https://core.telegram.org/bots#6-botfather

export TELEGRAM_TOKEN=<Your telegram bot token>
python3 -m agt.channels.telegram example.mybot

Discord

请确保安装具有Discord支持的agt - pip install agt[discord]

创建一个新的机器人账户并使用以下指南获取令牌: https://discordpy.readthedocs.io/en/latest/discord.html

export DISCORD_KEY=<Your discord bot token>
python3 -m agt.channels.discord example.mybot

Microsoft机器人框架

请确保安装具有Microsoft机器人框架支持的agt - pip install agt[msbf]

export MicrosoftAppId=<Your bot Microsft App Id>
export MicrosoftAppPassword=<Your bot Microsoft App Password>
python3 -m agt.channels.msbf example.mybot

基本语言理解

在agt.nlu中,我们有简单的模式到正则表达式编译器,用于执行基本理解任务

将简单单词模式编译成正则表达式

一些示例

intent = Intent(
    Pattern("the", "boy", "ate", "an", "apple")
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == False

intent = Intent(
    Pattern("the", "boy", "ate", "an", AnyWords(min=1, max=1))
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == True

intent = Intent(
    Pattern("the", Words("boy", "girl"), "ate", "an", AnyWords(min=1, max=1))
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == True
assert intent("the girl ate an orange") == True
assert intent("the girl ate a banana") == False

intent = Intent(
    Pattern("the", ("boy", "girl"), "ate", WordsRegex(r"an?"), AnyWords(min=1, max=1))
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == True
assert intent("the girl ate an orange") == True
assert intent("the girl ate a banana") == True
assert intent("a nice boy ate an apple") == False

intent = Intent(
    Pattern(WILDCARD, Words("boy", "girl"), "ate", WordsRegex(r"an?"), AnyWords(min=1, max=1))
)
assert intent("a nice boy ate an apple") == True

模式接收句子元素并将每个元素转换为优化的正则表达式。

意图将多个模式分组,因此如果任何模式匹配意图,则评估为True

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分布

agt-0.6.4.tar.gz (33.2 kB 查看散列)

上传时间

构建分布

agt-0.6.4-py3-none-any.whl (35.6 kB 查看散列)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面