问题描述
我正在编写基于受过训练的AutoMl多标签分类器进行预测的代码。如果我在本地运行该功能,则可以运行该功能,但是,一旦我将相同的代码上传到GCP上的Cloud Functions(我知道通常可以正常运行的进程)后,就会为我提供此错误
TypeError:predict()接受1到2个位置参数,但给出了4个
这是我的代码示例,直接从AutoMl文档中进行了一些细微调整。
def get_sentiment(content):
"""
Returns a google cloud platform payload class containing the sentiment score given by our NLP sentiment analyser.
:param content: STRING (UTF-8 encoded,ASCII)
:return: <class 'google.cloud.automl.types.PredictResponse'>
"""
options = ClientOptions(api_endpoint='automl.googleapis.com')
prediction_client = automl_v1beta1.PredictionServiceClient(client_options=options)
name = model_sentiment
payload = {'text_snippet': {'content': content,'mime_type': 'text/plain'}}
params = {}
request = prediction_client.predict(name,payload,params)
return request
我尝试从预测中删除params变量,并用内容替换有效负载,唯一的变化是我得到了错误:
TypeError:predict()接受1到2个位置参数,但给出了3个
此外,我将automl_v1beta1替换为automl和automl_v1。再一次,虽然两者都在本地工作,但它们不能在Google Cloud上工作。
感谢您的任何建议或帮助
解决方法
更新,显然在最新版本的AutoML中存在一些错误,并且该错误已通过在其先前版本上运行代码而得到修复。特别是在我的情况下v0.9.0