我正在尝试在云功能中运行烧瓶助手代码。代码在我的本地机器上工作正常,但它不能用作云功能。我正在使用http触发器。每次触发时,该功能都会崩溃。
from flask import Flask
from flask_assistant import Assistant, ask, tell
app = Flask(__name__)
assist = Assistant(app, route='/')
@assist.action('TotalSales')
def greet_and_start(request):
app.run
speech = "Hey! 1500?"
return ask(speech)
if __name__ == '__main__':
app.run(debug=True)
当您在Python中编写Google Cloud Function时,您需要编写的所有内容都是处理请求的函数。例如:
def hello_get(request)
return 'Hello World!'
Cloud Functions处理创建Flask环境和处理传入请求的所有工作。您需要做的就是提供处理程序来处理。这是提供“无服务器”基础架构的云功能背后的核心。实际运行的服务器的数量和存在将从您的世界中删除,您只能专注于您希望逻辑执行的操作。毫不奇怪,您的示例程序无法正常运行,因为它试图做太多。以下是Python的Google Cloud Functions教程的链接,该教程演示了一个简单的示例。
https://cloud.google.com/functions/docs/tutorials/http
我建议您研究此处的云功能以及相关文档:
https://cloud.google.com/functions/docs/
其他好的参考包括: