GithubHelp home page GithubHelp logo

joaorafaelm / nlcli Goto Github PK

View Code? Open in Web Editor NEW
22.0 2.0 2.0 68 KB

Natural language interface for the command line.

License: MIT License

Python 69.64% Makefile 23.06% Dockerfile 7.29%
intent-parser intent-classification natural-language-understanding text-processing python cli

nlcli's Introduction

nlcli

Open in Gitpod Open In Colab

Nlcli is a python package that offers a natural language interface for your programs. It is primarly focused on command line interaction, but it can be used as a chatbot and even as an interface for HTTP based programs; checkout the examples.

Built on top of mycroftai/padatious and libfann/fann.

Getting started

You can run this tutorial interactively on google colab.

Installation

Both https://github.com/libfann/fann and https://github.com/swig/swig are required in order to install nlcli.

On macos you might have to compile FANN from source, swig can be instaled via brew.

To install the libs on linux, run the following command:

!sudo apt-get -qq install libfann-dev swig

Install nlcli using pip:

!pip install -q nlcli

Usage example

import nlcli


@nlcli.cmd(["hi", "Hi my name is {name}"])
def hi(name=""):
    return f"hi {name}"


@nlcli.cmd(
    ["search for {query} on {engine}", "search {query} on {engine}", "search {query} {engine}"]
)
def search(query, engine="google"):
    return f"query: {query}, engine: {engine}"


if __name__ == "__main__":
    nlcli.interact()
$ python example.py hi my name is joao
hi joao

$ python example.py search python on bing
query: python, engine: bing

Python api

Call nlcli.interact to parse the query and call the function intent automatically:

>>> nlcli.interact("search for brazil on google", debug=True)

{'name': 'search', 'sent': ['search', 'for', 'brazil', 'on', 'google'], 'matches': {'query': 'brazil', 'engine': 'google'}, 'conf': 1.0}

query: brazil, engine: google

>>> nlcli.interact("hi", debug=True)

{'name': 'hi', 'sent': ['hi'], 'matches': {}, 'conf': 1.0}

hi

>>> nlcli.interact("hi, my name is joao", debug=True)

{'name': 'hi', 'sent': ['hi', ',', 'my', 'name', 'is', 'joao'], 'matches': {'name': 'joao'}, 'conf': 1.0}

hi joao

By default, nlcli comes with two builtin commands: help and exit. When nlcli fails to match a query with an intent, help command will be automatically called, you can change the default command by passing default=True to the desired @nlcli.cmd decorator.

>>> nlcli.interact("help", debug=True)

{'name': 'help', 'sent': 'help', 'matches': {}, 'conf': 0.49447914140834637}

Heres what I can do:

help - usage: help (|me) with {skill}

bye - usage: Goodbye!

hi - usage: hi

search - usage: search for {query} on {engine}

All custom commands have help automatically, if you want help on a command, simply ask for it:

>>> nlcli.interact("help me with search", debug=True)

{'name': 'help', 'sent': ['help', 'me', 'with', 'search'], 'matches': {'skill': 'search'}, 'conf': 1.0}

here are some examples on how to use search:

search for {query} on {engine}

search {query} on {engine}

search {query} {engine}

CLI usage:

!git clone -q https://github.com/joaorafaelm/nlcli.git && cd nlcli
!python -m examples.getting_started hi my name is joao

TODO

nlcli's People

Contributors

joaorafaelm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

shinroo jnash10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.