小编dev*_*sha的帖子

从 python 中运行交互式程序

我想实现与非常相似的目标。

\n\n

我的实际目标是从 python 中运行 Rasa。\n取自 Rasa\ 的站点:

\n\n
\n

Rasa 是一个用于构建会话软件的框架:Messenger/Slack 机器人、Alexa 技能等。我们\xe2\x80\x99ll 在本文档中将其缩写为机器人。

\n
\n\n

它基本上是一个在命令提示符下运行的聊天机器人。这就是它在 cmd 上的工作方式:\n在此输入图像描述

\n\n

现在我想从 python 运行 Rasa,以便可以将其与基于 Django 的网站集成。即我想继续从用户那里获取输入,将其传递给rasa,rasa处理文本并给我一个输出,然后将其显示给用户。

\n\n

我已经尝试过这个(到目前为止从cmd运行它)

\n\n
import 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)

python subprocess python-multithreading rasa-nlu

4
推荐指数
1
解决办法
7135
查看次数