ravestate是一个实时自然语言对话系统的反应库。

ravestate的Python项目详细描述


ReleaseBuild Statuscodecov

关于

   ____                          __      __        _____       _____   
  / _  \____  __  ______  ______/ /_____/ /___    /_   _\     /_   _\  
 / /_/ / __ \/ / / / __ \/ ___\, / __ \, / __ \    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
  1. 在pycharm中打开本地ravestate克隆作为项目。
  2. 通过右键单击上下文菜单将modules文件夹标记为sources root。
  3. 在“编辑配置菜单”中创建运行配置: •创建新的python配置。
    •将modules/ravestate/__main__.py设置为要执行的脚本 •将工作目录设置为git clone目录。
    •将参数设置为-f config/generic.yml -f config/keys.yml
  4. 现在您应该可以从pycharm运行通用ravestate配置了。

运行Hello World

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 nameDescription
ravestateCore ravestate library.
ravestate_rawioProvides ^{}, ^{}, ^{} properties, which are served by the IO modules.
ravestate_ontologyConnects to scientio to serve a built-in ontology.
ravestate_interlocProvides the ^{} property, where present interlocutors are registered by the IO modules.
ravestate_idleProvides ^{} and ^{} signals, as specified here.
ravestate_verbaliserUtilities for easy management of conversational text, documented here.
ravestate_nlpSpacy-based NLP properties and signals, documented here.
ravestate_ros2Provides specific ^{}, ^{} and ^{} context props., which greatly simplify working with ROS2 in ravestate.

IO模块

Module nameDescription
ravestate_conioSimple command-line based IO for development purposes.
ravestate_telegramioSingle- or Multi-process Telegram server module, documented here.
ravestate_roboyioPyroBoy -based STT/TTS with ROS2.

技能模块
Module nameDescription
ravestate_wildtalkParlAI -based generative conversational module.
ravestate_hibyeSimply voices Hi! (or the likes thereof) when an interlocutor is added, and Bye when one is removed.
ravestate_persqaConducts personalized smalltalk with interlocutors, interacts with Scientio to persist trivia.
ravestate_genqaDrQA -based general question answering module.
ravestate_roboyqaQA module which provides answers to questions about Roboy, such as Who is your dad?
ravestate_akinatorEnables dialog-based play of Akinator!
ravestate_sendpicsUses face recognition to extract facial features and an assiciated Person with ^{} and ontology, which are then persisted in Redis and Scientio.
ravestate_stalkerUses ^{} tuples generated by sendpics, to surprise people in front of a camera with knowledge of their names.

运行测试

如果您安装了来自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中定义。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
在数据库中存储密码的java加密方法   java正则表达式否定整个正则表达式   java为什么要得到这个Hashmap输出?   看不到玻璃鱼爪哇SE 6   类对象包装器中的Java基本数据字段   java从文本文件中读取整数并存储到单独的变量中?(扫描仪)   优化大型Java数据阵列的处理和管理   如何使用Java XML包装类创建对象   java为ExecutorService invokeAll()创建包装器   java如何在Android Studio 1.0.0中设置Facebook SDK?获取SDK位置未找到错误   java在尝试从线程启动动画时调用了FromErrorThreadException   java根据哈希确认文件内容   通过java在neo4j中获取索引值相同的所有节点?   java为什么我的Validare邮政编码(布尔)程序返回false?   java会话自动从servlet/jsp生成,尽管存在以下条件:<%@page session=“false”%>   创建新LANsocket时拒绝java连接   java如何多线程更新由sql代码更新的数据库?   安卓 Java使用类作为集合来添加项   安卓为什么我的清单文件不声明java包?