How to use Tinq in Google Sheets

How to use Tinq in Google Sheets

Tinq AI is a production-ready NLP toolkit wrapped into a REST API. It allows you to perform various NLP tasks such as summarization, paraphrasing, named-entity recognition, sentiment analysis, and much more. All that without the hassle of training models.

If you don't feel like reading, you can watch this video here:

Thanks to the REST API that Tinq offers, you are able to use it in pretty much any product and create your own custom integrations.

Today, we will use the paraphrase API in order to write a custom function that paraphrases content in Google Sheets.

So let’s get started. First of all, you will need a Tinq AI account, that will give you access to the NLP API for free. After you have registered, you will have your API keys ready. But let's keep that on the side for the moment and let's create our google sheet document.

Once we create it, let's add some rows to it. The rows will be the data that we will pass to our function.

Note that depending on your Tinq plan, you may be limited to a certain number of characters per request & a maximum of requests.

Now that we have our data, we are going to create our paraphrasing function using the Google App script. For that, we have to click on “Tools”, then go on “Script editor”. This will take us to the script editor where we can write our code in order to create our paraphrasing function.

But before doing that, Let’s head on to the Tinq API documentation so we can see how the API works. For the documentation, you just need to click on the link in your dashboard. Each tool has its own API documentation for your convenience. We can see here that there are mandatory parameters:

  • API username and API key
  • Text (the text to paraphrase)
  • We can also set entropy which tells the API how different we want the output to be.

Now that we know how the API works, let's go ahead and write our function. If you know JavaScript, you should not have any issue with the code below.

function tinqParaphrase(text = "This is a very good tool for paraphrasing") {

  var formData = {
    'text': text,
    'api_key': '{YOUR_API_KEY}',
    'username': '{YOUR_USERNAME}',
    'changes_level': 30
  }

  var options = {
    'method': 'post',
    'payload': formData
  }

  var response = UrlFetchApp.fetch('https://tinq.ai/api/v1/rewrite', options);

  var data = JSON.parse(response.getContentText());

  return data.paraphrases;

}

If this is the first time that you are doing it, you will be asked to grant authorization to the script to access your Google Sheet document. Once you authorize the app, you can run it in the console or in your Goole Sheet document.

And voilà! That’s it. Now we can go on to our google sheet and use our function just like we would with any native function from google sheet.

tinqParaphrase(A1) // to paraphrase the content in the cell A1
tinqParaphrase(A2) // to paraphrase the content in the cell A2
...
tinqParaphrase(N) // to paraphrase the content in the cell N