Google cloud platform 如何保存分数';是否与NLP API预测相关?

Google cloud platform 如何保存分数';是否与NLP API预测相关?,google-cloud-platform,google-cloud-firestore,google-cloud-functions,google-cloud-nl,Google Cloud Platform,Google Cloud Firestore,Google Cloud Functions,Google Cloud Nl,因此,目前我的扩展通过云函数向NLPAPI发送一段文本。对这段文本进行处理和预测,并根据预测分配分数(例如,一句话可以是0.33—“重要同意”)。我想知道是否有可能将这些句子及其各自的分数保存到Firestore中。目前,我只能保存句子,不能保存分数 我们真的希望Firestore数据库中有分数,因为我们使用的是阈值限制。如果没有分数,则阈值将过时 以下是云函数,以防万一: exports.queryAutoML = (req, res) => { const automl =

因此,目前我的扩展通过云函数向NLPAPI发送一段文本。对这段文本进行处理和预测,并根据预测分配分数(例如,一句话可以是0.33—“重要同意”)。我想知道是否有可能将这些句子及其各自的分数保存到Firestore中。目前,我只能保存句子,不能保存分数

我们真的希望Firestore数据库中有分数,因为我们使用的是阈值限制。如果没有分数,则阈值将过时

以下是云函数,以防万一:

  exports.queryAutoML = (req, res) => {

  const automl = require('@google-cloud/automl');

  const client = new automl.PredictionServiceClient();

  var formattedName = client.modelPath('*********', '**********', '*****************');
  var payload = {
    "textSnippet": {
       "content": req.body,
        "mime_type": "text/plain"
    },
  };
  var request = {
    name: formattedName,
    payload: payload,
  };
  client.predict(request)
    .then(responses => {
    console.log("in success");
    let title = responses[0].payload[0].displayName;
    let score = responses[0].payload[0].classification.score;
    output = [req.body, title, score];
    res.status(200).send(output);
  })
    .catch(err => {
    console.log("in error");
    console.error(err);
  });

将Frank van Puffelen的答案添加为comunnity wiki以提高可见性:


注释中提供的代码片段显示了如何创建文档并将其上载到Firestore集合。因此,您需要做的是使用NLP查询的结果作为字段来创建文档,然后使用Firebase SDK推送文档。

从云函数代码中调用Firestore API非常简单。云功能代码实验室甚至有一个例子:你尝试过什么吗?你能详细说明一下你在挣扎什么吗?嘿@Frankvanpoffelen,这样我就可以使用云函数将NLP的预测保存到Firestore了?是的,听起来这应该是可能的。去做吧,如果你有问题就报告。