Package: neon-solvers
Neon SolversA framework for question answering, provides a unified conversational api for arbitrary data sourcesCreating a pluginA plugin can define the language it works in, eg, wolfram alpha only accepts english input at the time of this writingBidirectional translation will be handled behind the scenes for other languagesPlugins are expected to implement the get_xxx methods and leave the user facing equivalents alonefromneon_solversimportAbstractSolverclassMySolver(AbstractSolver):def__init__(self):# set the "internal" language, defined by dev, not user# this plugin only accepts and outputs englishconfig={"lang":"en"}super(MySolver,self).__init__(name="MySolver",priority=100,config=config)# expected solver methods to be implementeddefget_data(self,query,context):"""query assured to be in self.default_langreturn a dict response"""return{"error":"404 answer not found"}defget_image(self,query,context=None):"""query assured to be in self.default_langreturn path/url to a single image to acompany spoken_answer"""return"http://stock.image.jpg"defget_spoken_answer(self,query,context=None):"""query assured to be in self.default_langreturn a single sentence text response"""return"The full answer is XXX"defget_expanded_answer(self,query,context=None):"""query assured to be in self.default_langreturn 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"}]returnstepsUsing a pluginPlugins work with any language as long as you stick to the officially supported wrapper methods# user facing methods, user should only be calling thesedefsearch(self,query,context=None,lang=None):"""cache and auto translate query if neededreturns translated response from self.get_data"""defvisual_answer(self,query,context=None,lang=None):"""cache and auto translate query if neededreturns image that answers query"""defspoken_answer(self,query,context=None,lang=None):"""cache and auto translate query if neededreturns chunked and translated response from self.get_spoken_answer"""deflong_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 pluginsingle answerfromneon_solver_ddg_pluginimportDDGSolverd=DDGSolver()query="who is Isaac Newton"# full answerans=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"fromneon_solver_ddg_pluginimportDDGSolverd=DDGSolver()query="who is Isaac Newton"# chunked answerforsentenceind.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.jpgAuto translation, pass user language in contextfromneon_solver_ddg_pluginimportDDGSolverd=DDGSolver()# bidirectional auto translate by passing lang contextsentence=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