neon-solvers


Nameneon-solvers JSON
Version 0.0.2a1 PyPI version JSON
download
home_pagehttps://github.com/NeonGeckoCom/neon_solvers
Summaryneon question solver plugin framework
upload_time2022-05-31 21:14:53
maintainer
docs_urlNone
authorNeongecko
requires_python
licensebsd3
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Neon Solvers

A framework for question answering, provides a unified conversational api for arbitrary data sources

## Creating a plugin

A plugin can define the language it works in, eg, wolfram alpha only accepts english input at the time of this writing

Bidirectional translation will be handled behind the scenes for other languages

Plugins are expected to implement the get_xxx methods and leave the user facing equivalents alone

```python
from neon_solvers import AbstractSolver


class MySolver(AbstractSolver):
    def __init__(self):
         # set the "internal" language, defined by dev, not user
         # this plugin only accepts and outputs english
        config={"lang": "en"}
        super(MySolver, self).__init__(name="MySolver", priority=100, 
                                       config=config)

    # expected solver methods to be implemented
    def get_data(self, query, context):
        """
        query assured to be in self.default_lang
        return a dict response
        """
        return {"error": "404 answer not found"}

    def get_image(self, query, context=None):
        """
        query assured to be in self.default_lang
        return path/url to a single image to acompany spoken_answer
        """
        return "http://stock.image.jpg"

    def get_spoken_answer(self, query, context=None):
        """
        query assured to be in self.default_lang
        return a single sentence text response
        """
        return "The full answer is XXX"

    def get_expanded_answer(self, query, context=None):
        """
        query assured to be in self.default_lang
        return a list of ordered steps to expand the answer, eg, "tell me more"

        {
            "title": "optional",
            "summary": "speak this",
            "img": "optional/path/or/url
        }
        :return:
        """
        steps = [
            {"title": "the question", "summary": "we forgot the question", "image": "404.jpg"},
            {"title": "the answer", "summary": "but the answer is 42", "image": "42.jpg"}
        ]
        return steps

```

## Using a plugin

Plugins work with any language as long as you stick to the officially supported wrapper methods

```python
    # user facing methods, user should only be calling these
    def search(self, query, context=None, lang=None):
        """
        cache and auto translate query if needed
        returns translated response from self.get_data
        """

    def visual_answer(self, query, context=None, lang=None):
        """
        cache and auto translate query if needed
        returns image that answers query
        """

    def spoken_answer(self, query, context=None, lang=None):
        """
        cache and auto translate query if needed
        returns chunked and translated response from self.get_spoken_answer
        """

    def long_answer(self, query, context=None, lang=None):
        """
        return a list of ordered steps to expand the answer, eg, "tell me more"
        translated response from self.get_expanded_answer
        {
            "title": "optional",
            "summary": "speak this",
            "img": "optional/path/or/url
        }
        :return:
        """
```


# Example Usage  - DuckDuckGo plugin

single answer

```python
from neon_solver_ddg_plugin import DDGSolver

d = DDGSolver()

query = "who is Isaac Newton"

# full answer
ans = d.spoken_answer(query)
print(ans)
# Sir Isaac Newton was an English mathematician, physicist, astronomer, alchemist, theologian, and author widely recognised as one of the greatest mathematicians and physicists of all time and among the most influential scientists. He was a key figure in the philosophical revolution known as the Enlightenment. His book Philosophiæ Naturalis Principia Mathematica, first published in 1687, established classical mechanics. Newton also made seminal contributions to optics, and shares credit with German mathematician Gottfried Wilhelm Leibniz for developing infinitesimal calculus. In the Principia, Newton formulated the laws of motion and universal gravitation that formed the dominant scientific viewpoint until it was superseded by the theory of relativity.
```

chunked answer, for conversational dialogs, ie "tell me more"

```python
from neon_solver_ddg_plugin import DDGSolver

d = DDGSolver()

query = "who is Isaac Newton"

# chunked answer
for sentence in d.long_answer(query):
    print(sentence["title"])
    print(sentence["summary"])
    print(sentence.get("img"))

    # who is Isaac Newton
    # Sir Isaac Newton was an English mathematician, physicist, astronomer, alchemist, theologian, and author widely recognised as one of the greatest mathematicians and physicists of all time and among the most influential scientists.
    # https://duckduckgo.com/i/ea7be744.jpg

    # who is Isaac Newton
    # He was a key figure in the philosophical revolution known as the Enlightenment.
    # https://duckduckgo.com/i/ea7be744.jpg

    # who is Isaac Newton
    # His book Philosophiæ Naturalis Principia Mathematica, first published in 1687, established classical mechanics.
    # https://duckduckgo.com/i/ea7be744.jpg

    # who is Isaac Newton
    # Newton also made seminal contributions to optics, and shares credit with German mathematician Gottfried Wilhelm Leibniz for developing infinitesimal calculus.
    # https://duckduckgo.com/i/ea7be744.jpg

    # who is Isaac Newton
    # In the Principia, Newton formulated the laws of motion and universal gravitation that formed the dominant scientific viewpoint until it was superseded by the theory of relativity.
    # https://duckduckgo.com/i/ea7be744.jpg
  ```  

Auto translation, pass user language in context

```python
from neon_solver_ddg_plugin import DDGSolver

d = DDGSolver()

# bidirectional auto translate by passing lang context
sentence = d.spoken_answer("Quem é Isaac Newton",
                           context={"lang": "pt"})
print(sentence)
# Sir Isaac Newton foi um matemático inglês, físico, astrônomo, alquimista, teólogo e autor amplamente reconhecido como um dos maiores matemáticos e físicos de todos os tempos e entre os cientistas mais influentes. Ele era uma figura chave na revolução filosófica conhecida como o Iluminismo. Seu livro Philosophiæ Naturalis Principia Mathematica, publicado pela primeira vez em 1687, estabeleceu a mecânica clássica. Newton também fez contribuições seminais para a óptica, e compartilha crédito com o matemático alemão Gottfried Wilhelm Leibniz para desenvolver cálculo infinitesimal. No Principia, Newton formulou as leis do movimento e da gravitação universal que formaram o ponto de vista científico dominante até ser superado pela teoria da relatividade
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/NeonGeckoCom/neon_solvers",
    "name": "neon-solvers",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Neongecko",
    "author_email": "developers@neon.ai",
    "download_url": "",
    "platform": null,
    "description": "# Neon Solvers\n\nA framework for question answering, provides a unified conversational api for arbitrary data sources\n\n## Creating a plugin\n\nA plugin can define the language it works in, eg, wolfram alpha only accepts english input at the time of this writing\n\nBidirectional translation will be handled behind the scenes for other languages\n\nPlugins are expected to implement the get_xxx methods and leave the user facing equivalents alone\n\n```python\nfrom neon_solvers import AbstractSolver\n\n\nclass MySolver(AbstractSolver):\n    def __init__(self):\n         # set the \"internal\" language, defined by dev, not user\n         # this plugin only accepts and outputs english\n        config={\"lang\": \"en\"}\n        super(MySolver, self).__init__(name=\"MySolver\", priority=100, \n                                       config=config)\n\n    # expected solver methods to be implemented\n    def get_data(self, query, context):\n        \"\"\"\n        query assured to be in self.default_lang\n        return a dict response\n        \"\"\"\n        return {\"error\": \"404 answer not found\"}\n\n    def get_image(self, query, context=None):\n        \"\"\"\n        query assured to be in self.default_lang\n        return path/url to a single image to acompany spoken_answer\n        \"\"\"\n        return \"http://stock.image.jpg\"\n\n    def get_spoken_answer(self, query, context=None):\n        \"\"\"\n        query assured to be in self.default_lang\n        return a single sentence text response\n        \"\"\"\n        return \"The full answer is XXX\"\n\n    def get_expanded_answer(self, query, context=None):\n        \"\"\"\n        query assured to be in self.default_lang\n        return a list of ordered steps to expand the answer, eg, \"tell me more\"\n\n        {\n            \"title\": \"optional\",\n            \"summary\": \"speak this\",\n            \"img\": \"optional/path/or/url\n        }\n        :return:\n        \"\"\"\n        steps = [\n            {\"title\": \"the question\", \"summary\": \"we forgot the question\", \"image\": \"404.jpg\"},\n            {\"title\": \"the answer\", \"summary\": \"but the answer is 42\", \"image\": \"42.jpg\"}\n        ]\n        return steps\n\n```\n\n## Using a plugin\n\nPlugins work with any language as long as you stick to the officially supported wrapper methods\n\n```python\n    # user facing methods, user should only be calling these\n    def search(self, query, context=None, lang=None):\n        \"\"\"\n        cache and auto translate query if needed\n        returns translated response from self.get_data\n        \"\"\"\n\n    def visual_answer(self, query, context=None, lang=None):\n        \"\"\"\n        cache and auto translate query if needed\n        returns image that answers query\n        \"\"\"\n\n    def spoken_answer(self, query, context=None, lang=None):\n        \"\"\"\n        cache and auto translate query if needed\n        returns chunked and translated response from self.get_spoken_answer\n        \"\"\"\n\n    def long_answer(self, query, context=None, lang=None):\n        \"\"\"\n        return a list of ordered steps to expand the answer, eg, \"tell me more\"\n        translated response from self.get_expanded_answer\n        {\n            \"title\": \"optional\",\n            \"summary\": \"speak this\",\n            \"img\": \"optional/path/or/url\n        }\n        :return:\n        \"\"\"\n```\n\n\n# Example Usage  - DuckDuckGo plugin\n\nsingle answer\n\n```python\nfrom neon_solver_ddg_plugin import DDGSolver\n\nd = DDGSolver()\n\nquery = \"who is Isaac Newton\"\n\n# full answer\nans = d.spoken_answer(query)\nprint(ans)\n# Sir Isaac Newton was an English mathematician, physicist, astronomer, alchemist, theologian, and author widely recognised as one of the greatest mathematicians and physicists of all time and among the most influential scientists. He was a key figure in the philosophical revolution known as the Enlightenment. His book Philosophi\u00e6 Naturalis Principia Mathematica, first published in 1687, established classical mechanics. Newton also made seminal contributions to optics, and shares credit with German mathematician Gottfried Wilhelm Leibniz for developing infinitesimal calculus. In the Principia, Newton formulated the laws of motion and universal gravitation that formed the dominant scientific viewpoint until it was superseded by the theory of relativity.\n```\n\nchunked answer, for conversational dialogs, ie \"tell me more\"\n\n```python\nfrom neon_solver_ddg_plugin import DDGSolver\n\nd = DDGSolver()\n\nquery = \"who is Isaac Newton\"\n\n# chunked answer\nfor sentence in d.long_answer(query):\n    print(sentence[\"title\"])\n    print(sentence[\"summary\"])\n    print(sentence.get(\"img\"))\n\n    # who is Isaac Newton\n    # Sir Isaac Newton was an English mathematician, physicist, astronomer, alchemist, theologian, and author widely recognised as one of the greatest mathematicians and physicists of all time and among the most influential scientists.\n    # https://duckduckgo.com/i/ea7be744.jpg\n\n    # who is Isaac Newton\n    # He was a key figure in the philosophical revolution known as the Enlightenment.\n    # https://duckduckgo.com/i/ea7be744.jpg\n\n    # who is Isaac Newton\n    # His book Philosophi\u00e6 Naturalis Principia Mathematica, first published in 1687, established classical mechanics.\n    # https://duckduckgo.com/i/ea7be744.jpg\n\n    # who is Isaac Newton\n    # Newton also made seminal contributions to optics, and shares credit with German mathematician Gottfried Wilhelm Leibniz for developing infinitesimal calculus.\n    # https://duckduckgo.com/i/ea7be744.jpg\n\n    # who is Isaac Newton\n    # In the Principia, Newton formulated the laws of motion and universal gravitation that formed the dominant scientific viewpoint until it was superseded by the theory of relativity.\n    # https://duckduckgo.com/i/ea7be744.jpg\n  ```  \n\nAuto translation, pass user language in context\n\n```python\nfrom neon_solver_ddg_plugin import DDGSolver\n\nd = DDGSolver()\n\n# bidirectional auto translate by passing lang context\nsentence = d.spoken_answer(\"Quem \u00e9 Isaac Newton\",\n                           context={\"lang\": \"pt\"})\nprint(sentence)\n# Sir Isaac Newton foi um matem\u00e1tico ingl\u00eas, f\u00edsico, astr\u00f4nomo, alquimista, te\u00f3logo e autor amplamente reconhecido como um dos maiores matem\u00e1ticos e f\u00edsicos de todos os tempos e entre os cientistas mais influentes. Ele era uma figura chave na revolu\u00e7\u00e3o filos\u00f3fica conhecida como o Iluminismo. Seu livro Philosophi\u00e6 Naturalis Principia Mathematica, publicado pela primeira vez em 1687, estabeleceu a mec\u00e2nica cl\u00e1ssica. Newton tamb\u00e9m fez contribui\u00e7\u00f5es seminais para a \u00f3ptica, e compartilha cr\u00e9dito com o matem\u00e1tico alem\u00e3o Gottfried Wilhelm Leibniz para desenvolver c\u00e1lculo infinitesimal. No Principia, Newton formulou as leis do movimento e da gravita\u00e7\u00e3o universal que formaram o ponto de vista cient\u00edfico dominante at\u00e9 ser superado pela teoria da relatividade\n```\n\n",
    "bugtrack_url": null,
    "license": "bsd3",
    "summary": "neon question solver plugin framework",
    "version": "0.0.2a1",
    "project_urls": {
        "Homepage": "https://github.com/NeonGeckoCom/neon_solvers"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6cf298d1e9bb47b9b945c39ed7472af350e2cc4a6eaec272ee9dd9f1e3c2eed3",
                "md5": "28c7552f0087fea94a73117691fc97cb",
                "sha256": "51f99cb443cc53f4141fb44e3fe075bacde6d917a0598cf7feac30a03bada180"
            },
            "downloads": -1,
            "filename": "neon_solvers-0.0.2a1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "28c7552f0087fea94a73117691fc97cb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8626,
            "upload_time": "2022-05-31T21:14:53",
            "upload_time_iso_8601": "2022-05-31T21:14:53.137470Z",
            "url": "https://files.pythonhosted.org/packages/6c/f2/98d1e9bb47b9b945c39ed7472af350e2cc4a6eaec272ee9dd9f1e3c2eed3/neon_solvers-0.0.2a1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-05-31 21:14:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "NeonGeckoCom",
    "github_project": "neon_solvers",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "neon-solvers"
}
        
Elapsed time: 0.52956s