ravestate是一个实时自然语言对话系统的反应库。
ravestate的Python项目详细描述
关于
____ __ __ _____ _____
/ _ \____ __ ______ ______/ /_____/ /___ /_ _\ /_ _\
/ /_/ / __ \/ / / / __ \/ ___\, / __ \, / __ \ 0> 0> <0 <0
/ ,\ ,/ /_/ /\ \/ / /_/ /\__, / / /_/ / / /_/ / \__⊽__/ \__⊽__/
\/ \/\__/\/ \__/ ,___/\____/\/\__/\/\/ ,___/ ⋂ - Hey! ⋂
\____/ \____/ Olà! -
ravestate是一个实时自然语言对话系统的反应库。它将基于事件和反应式编程的元素组合到一个api中,在api中,应用程序状态被定义为在当前应用程序上下文中满足某个布尔条件集(信号)时运行的函数。它是第一个允许布尔事件组合的反应式api。你可以找到一个简短的介绍视频here。
反应性hello world
importravestateasrs# We want to write some text output, so we# need the raw:out context property from ravestate_rawio.importravestate_rawioasrawio# Make sure that we use some i/o implementation,# so we can actually see stuff that is written to rawio:out.importravestate_conio# Ravestate applications should always be wrapped in a Module.# This allows easier scoping, and enables separation of concerns# beyond states.withrs.Module(name="hi!"):# Create an application state which reacts to the `:startup` signal,# and writes a string to raw:out. Note: State functions are# always run asynchronously!@rs.state(cond=rs.sig_startup,write=rawio.prop_out)defhello_world(context):context[rawio.prop_out]="Waddup waddup waddup!"# Run context with console input/output and our 'hi!' module.rs.Context("conio","hi!").run()
可视化
ravestate具有基于d3.js的可视化。当使用ravestate_ui.UIContext
而不是Context
,或者使用python3 -m ravestate_ui
而不是python3 -m ravestate
时,状态机中所有状态/属性/信号的实时可视化将托管在端口5001上。这是启动后http://localhost:5001
的视图python3 ravestate_ui -f generic.yml
:
安装
通过PIP
安装ravestate最简单的方法是通过pip:
pip install ravestate
注意:ravestate需要python 3.6或更高版本。它是经过测试的 在Ubuntu16.04和18.04以及MacOS>;High Sierra上。 它目前没有在windows上测试。
为了提高可靠性,我们建议使用环境虚拟化工具, 就像virtualenv 或者conda。
对于开发者
初始配置和设置
克隆存储库并安装依赖项:
# Create a virtual python environment to not pollute the global setup python3 -m virtualenv python-ravestate # Source the virtual environment . python-ravestate/bin/activate # Clone the repo git clone git@github.com:roboy/ravestate &&cd ravestate # Install normal requirements pip install -r requirements.txt # To run tests & build docs, install pytest, mocking, fixtures, pydoc, ... pip install -r requirements-dev.txt # Link your local ravestate clone into your virtualenv pip install -e .
现在,启动一个neo4j docker实例来服务Scientio,这样对话框系统就有了一个内存:
docker run \ --publish=7474:7474 --publish=7687:7687 \ --volume=$HOME/neo4j/data:/data \ --volume=$HOME/neo4j/logs:/logs \ neo4j:latest # Open the address localhost:7474 in a browser, and enter the# credentials `neo4j`/`neo4j`. You will then be prompted to enter# your own password. Remember this password.
在config
文件夹中,创建一个名为keys.yml
的文件。它应该包含以下内容:
module:telegramioconfig:telegram-token:<sexycactus># This is where your own telegram bot token# will go later---module:ontologyconfig:neo4j_address:bolt://localhost:7687# Your neo4j server uri hereneo4j_username:neo4j# Your neo4j user hereneo4j_pw:test# Your neo4j pw here
现在您可以与ravestate进行第一次对话:
python3 -m ravestate -f config/generic.yml -f config/keys.yml
对话结束后,检查localhost:7474
下的neo4j接口。它现在应该包含一些节点!
提醒:无论何时从命令行使用ravestate,请首先激活虚拟环境!
设置PyCharm
- 在pycharm中打开本地ravestate克隆作为项目。
- 通过右键单击上下文菜单将
modules
文件夹标记为sources root。 - 在“编辑配置菜单”中创建运行配置:
•创建新的python配置。
•将modules/ravestate/__main__.py
设置为要执行的脚本
•将工作目录设置为git clone目录。
•将参数设置为-f config/generic.yml -f config/keys.yml
。
- 现在您应该可以从pycharm运行通用ravestate配置了。
运行Hello World
modules
文件夹标记为sources root。•将
modules/ravestate/__main__.py
设置为要执行的脚本
•将工作目录设置为git clone目录。•将参数设置为
-f config/generic.yml -f config/keys.yml
。RaveState应用程序由配置定义, 它指定应加载的ravestate模块。
要运行基本的hello world应用程序,请运行ravestate 使用配置文件或命令行参数:
使用命令行规范运行
您可以在共享上下文中轻松运行RaveState模块的组合,
把它们列为python3 -m ravestate
:
python3 -m ravestate \ ravestate_wildtalk \ ravestate_conio \ ravestate_hibye \ ravestate_persqa
运行python3 -m ravestate -h
查看更多选项!
使用配置文件运行
您可以指定一系列配置文件来配置ravestate上下文, 当通过命令行指定所有内容变得太费劲时:
# In file hello_world.ymlmodule:coreconfig:import:-ravestate_wildtalk-ravestate_conio-ravestate_hibye-ravestate_persqa
然后,使用此配置文件运行ravestate
:
python3 -m ravestate -f hello_world.yml
模块概述
ravestate提供了细粒度模块的景观 对于对话框应用程序任务的不同方面, 可以在下面的依赖关系图中看到。宽泛地说, 模块分为核心(蓝色)、I/O(黄色)和 外部(红色)和技能(绿色):
核心模块
Module name | Description |
---|---|
ravestate | Core ravestate library. |
ravestate_rawio | Provides ^{ |
ravestate_ontology | Connects to scientio to serve a built-in ontology. |
ravestate_interloc | Provides the ^{ |
ravestate_idle | Provides ^{ |
ravestate_verbaliser | Utilities for easy management of conversational text, documented here. |
ravestate_nlp | Spacy-based NLP properties and signals, documented here. |
ravestate_ros2 | Provides specific ^{ |
IO模块
Module name | Description |
---|---|
ravestate_conio | Simple command-line based IO for development purposes. |
ravestate_telegramio | Single- or Multi-process Telegram server module, documented here. |
ravestate_roboyio | PyroBoy -based STT/TTS with ROS2. |
技能模块
Module name | Description |
---|---|
ravestate_wildtalk | ParlAI -based generative conversational module. |
ravestate_hibye | Simply voices Hi! (or the likes thereof) when an interlocutor is added, and Bye when one is removed. |
ravestate_persqa | Conducts personalized smalltalk with interlocutors, interacts with Scientio to persist trivia. |
ravestate_genqa | DrQA -based general question answering module. |
ravestate_roboyqa | QA module which provides answers to questions about Roboy, such as Who is your dad? |
ravestate_akinator | Enables dialog-based play of Akinator! |
ravestate_sendpics | Uses face recognition to extract facial features and an assiciated Person with ^{ |
ravestate_stalker | Uses ^{ |
运行测试
如果您安装了来自requirements-dev.txt
的依赖项,则
可按如下方式运行RaveState测试套件:
./run_tests.sh
ROS和ROS2的Docker
ROS和ROS2支持有一个dockerfile,可以使用
docker build -t ravestate-ros2-image .
该图像包含ros,ros2和一个ros桥连接ros和ros2。 此外,Roboy_Communi已安装阳离子消息和服务类型。
然后可以使用docker-compose.yml创建容器:
docker-compose up --detach ravestate
容器现在正在运行,与容器的连接可以是 建立时间:
docker exec -it ravestate-ros2-container bash
在容器中,首先获取ros2设置的源代码,然后 ravestate可以在ros2和rclpy可用的情况下运行。
source ~/ros2_ws/install/setup.sh python3 -m ravestate [...]
启动ROS桥
为了启动ros桥,必须设置图像和容器 如上所述。连接到容器后,从容器内部运行:
exportROS_IP=192.168.0.105 source ~/melodic_ws/devel/setup.sh source ~/ros2_ws/install/setup.sh source ~/ros1_bridge_ws/install/setup.sh ros2 run ros1_bridge dynamic_bridge
建立/维护文档
如果您安装了来自requirements-dev.txt
的依赖项,
通过在项目根目录下运行此命令生成文档:
exportPYTHONPATH=$PYTHONPATH:$(pwd)/modules git rm -rf docs rm -rf _build docs pydocmd build mkdir -p docs/resources/docs && cp resources/docs/*.png docs/resources/docs && cp resources/docs/*.gif docs/resources/docs git add docs/* # For inspection: python3 -m http.server --directory docs
文档的结构和内容在文件pydocmd.yml
中定义。