Skip to content

Commit

Permalink
Started working on a more complete documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
YuukanOO committed Dec 7, 2018
1 parent 001c751 commit 9833801
Show file tree
Hide file tree
Showing 9 changed files with 426 additions and 1 deletion.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = pytlas
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
157 changes: 157 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/master/config

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))


# -- Project information -----------------------------------------------------

from pytlas.version import __version__

project = 'pytlas'
copyright = '2018, Julien LEICHER'
author = 'Julien LEICHER'

# The short X.Y version
version = __version__
# The full version, including alpha/beta/rc tags
release = __version__


# -- General configuration ---------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'

# The master toctree document.
master_doc = 'index'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = None

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'default'


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
# html_theme_options = {}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}


# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'pytlasdoc'


# -- Options for LaTeX output ------------------------------------------------

latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'pytlas.tex', 'pytlas Documentation',
'Julien LEICHER', 'manual'),
]


# -- Options for manual page output ------------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'pytlas', 'pytlas Documentation',
[author], 1)
]


# -- Options for Texinfo output ----------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'pytlas', 'pytlas Documentation',
author, 'pytlas', 'One line description of project.',
'Miscellaneous'),
]
10 changes: 10 additions & 0 deletions docs/getting_started/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Getting started
===============

Here is the basic steps to get you started quickly.

.. toctree::
:maxdepth: 2

installation
usage
50 changes: 50 additions & 0 deletions docs/getting_started/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
Installation
============

There's multiple way to install pytlas. You're free to pick the one that better fit your needs.

.. note::

Whatever installation you choose, you may need additional setup related to the interpreter you have decided to use. See `Choosing your interpreter`_ below for more information.

In the following examples, pytlas is installed with the extra require **snips** which is the official interpreter used by pytlas.

From pypi
---------

.. code:: bash
$ pip install pytlas[snips]
From source
-----------

.. code:: bash
$ git clone https://github.com/atlassistant/pytlas.git
$ cd pytlas
$ pip install -e .[snips]
Choosing your interpreter
-------------------------

in order to understand natural language, pytlas is backed by **interpreters** which may need additional installation steps.

snips
~~~~~

The official interpreter supported use the fantastic `snips-nlu <https://github.com/snipsco/snips-nlu>`_ python library.

Given the language you want your assistant to understand, you may need to `download additional resources <https://github.com/snipsco/snips-nlu#language-resources>`_ using the following command:

.. code:: bash
$ snips-nlu download en
to download only needed english resources or:

.. code:: bash
$ snips-nlu download-all-languages
to download all language resources.
118 changes: 118 additions & 0 deletions docs/getting_started/usage.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
Usage
=====

Using the pytlas CLI
--------------------

pytlas include a basic CLI interface to interact with the system.

This line will start the pytlas REPL with skills located in the example/skills/ directory. It will load all data and fit the engine before starting the interactive prompt.

.. code:: bash
$ pytlas -s example/skills -v -l en repl
Using the library
-----------------

Here is a snippet which cover the basics of using pytlas inside your own program :

.. code-block:: python
# pytlas is fairly easy to understand.
# It will take raw user inputs, parse them and call appropriate handlers with
# parsed slots values. It will also manage the conversation states so skills can
# ask for user inputs if they need to.
from pytlas import Agent, intent, training
from pytlas.interpreters.snips import SnipsInterpreter
# Here, we register a sentence as training data for the specified language
# Those training sample are written using a simple DSL named chatl. It make it
# back-end agnostic and is much more readable than raw dataset needed by NLU
# engines.
#
# Those data will be parsed by `pychatl` to output the correct dataset use for the fit
# part.
@training('en')
def en_data(): return """
%[lights_on]
turn the @[room]'s lights on would you
turn lights on in the @[room]
lights on in @[room] please
turn on the lights in @[room]
turn the lights on in @[room]
enlight me in @[room]
~[basement]
cellar
@[room](extensible=false)
living room
kitchen
bedroom
~[basement]
"""
# Here we are registering a function (with the intent decorator) as an handler
# for the intent 'lights_on'.
#
# So when a user input will be parsed as a 'lights_on' intent by the interpreter,
# this handler will be called with a special `Request` object which contains the
# agent (which triggered this handler) and the intent with its slots.
@intent('lights_on')
def on_intent_lights_on(request):
# With the request object, we can communicate back with the `answer` method
# or the `ask` method if we need more user input. Here we are joining on each
# slot `value` because a slot can have multiple values.
request.agent.answer('Turning lights on in %s' % ', '.join([v.value for v in request.intent.slot('room')]))
# When using the `answer` method, you should call the `done` method as well. This is
# useful because a skill could communicate multiple answers at different intervals
# (ie. when fetching the information elsewhere).
return request.agent.done()
class Client:
"""This client is used as a model for an agent. It will receive lifecycle events
raised by the agent.
"""
def on_answer(self, text, cards, **meta):
print (text)
def on_ask(self, slot, text, choices, **meta):
print (text)
if __name__ == '__main__':
# The last piece is the `Interpreter`. This is the part responsible for human
# language parsing. It parses raw human sentences into something more useful for
# the program.
interpreter = SnipsInterpreter('en')
# Train the interpreter using training data register with the `training` decorator
# or `pytlas.training.register` function.
interpreter.fit_from_skill_data()
# The `Agent` uses the model given to call appropriate lifecycle hooks.
agent = Agent(interpreter, model=Client())
# With this next line, this is what happenned:
#
# - The message is parsed by the `SnipsInterpreter`
# - A 'lights_on' intents is retrieved and contains 'kitchen' and 'bedroom' as the 'room' slot values
# - Since the `Agent` is asleep, it will transition to the 'lights_on' state immediately
# - Transitioning to this state call the appropriate handler (at the beginning of this file)
# - 'Turning lights on in kitchen, bedroom' is printed to the terminal by the `Client.on_answer` defined above
# - `done` is called by the skill so the agent transitions back to the 'asleep' state
agent.parse('turn the lights on in kitchen and bedroom please')
30 changes: 30 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.. pytlas documentation master file, created by
sphinx-quickstart on Fri Dec 7 12:50:34 2018.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
pytlas |travis| |coveralls| |pypi| |license|
============================================

.. |travis| image:: https://travis-ci.org/atlassistant/pytlas.svg?branch=master
:target: https://travis-ci.org/atlassistant/pytlas

.. |coveralls| image:: https://coveralls.io/repos/github/atlassistant/pytlas/badge.svg?branch=master
:target: https://coveralls.io/github/atlassistant/pytlas?branch=master

.. |pypi| image:: https://badge.fury.io/py/pytlas.svg
:target: https://badge.fury.io/py/pytlas

.. |license| image:: https://img.shields.io/badge/License-GPL%20v3-blue.svg
:target: https://www.gnu.org/licenses/gpl-3.0

pytlas is an open-source 馃馃挰 assistant library built for people and made to be super easy to setup and understand.

Its goal is to make easy to map natural language sentences to python function handlers. It also manages a conversation with the help of a finite state machine.

.. toctree::
:maxdepth: 2
:caption: Contents

getting_started/index

0 comments on commit 9833801

Please sign in to comment.