我想实现与此非常相似的目标。
\n\n我的实际目标是从 python 中运行 Rasa。\n取自 Rasa\ 的站点:
\n\n\n\n\nRasa 是一个用于构建会话软件的框架:Messenger/Slack 机器人、Alexa 技能等。我们\xe2\x80\x99ll 在本文档中将其缩写为机器人。
\n
它基本上是一个在命令提示符下运行的聊天机器人。这就是它在 cmd 上的工作方式:\n
现在我想从 python 运行 Rasa,以便可以将其与基于 Django 的网站集成。即我想继续从用户那里获取输入,将其传递给rasa,rasa处理文本并给我一个输出,然后将其显示给用户。
\n\n我已经尝试过这个(到目前为止从cmd运行它)
\n\nimport sys\nimport subprocess\nfrom threading import Thread\nfrom queue import Queue, Empty # python 3.x\n\n\ndef enqueue_output(out, queue):\n for line in iter(out.readline, b\'\'):\n queue.put(line)\n out.close()\n\n\ndef getOutput(outQueue):\n outStr = \'\'\n try:\n while True: #Adds output from the Queue until it is empty\n outStr+=outQueue.get_nowait()\n except Empty:\n return outStr\n\np = subprocess.Popen(\'command_to_run_rasa\', \n stdin=subprocess.PIPE, \n …Run Code Online (Sandbox Code Playgroud)