Forum Discussion

martynhale's avatar
martynhale
Frequent Visitor
9 years ago
Solved

How to disable an api call?

Hi all,

 

I've created a data model which uses a function to call the Microsoft Sentiment Analysis api - everything works really well.

 

What I want to do is somehow disable the call where records have already been allocated a sentiment score from a previous call. This is because there's a cost per call - once I have a score, I don't need to recall the api.

 

 

Below is the function called Sentiment:

 

let
Sentiment = (inputtext) =>

let
Source = OData.Feed("https://api.datamarket.azure.com/data.ashx/amla/text-analytics/v1/GetSentiment?text="&inputtext),
ToTable = Record.ToTable(Source)

in
ToTable

in
Sentiment

 

Can anyone advise on the best way to do this?

Best wishes,

Martyn

6 Replies

  • Greg_Deckler's avatar
    Greg_Deckler
    Community Champion

    Probably an ImkeF type question, but I would imagine that you would need to store your scores in something accessible by M, pull that into your query, merge/join your data sources to filter out those already scored and call your API then use the result of that plus your original scored data, append those two together and feed that to the data model.

    • ImkeF's avatar
      ImkeF
      Community Champion

      Hi Martyn,

      I'm not familiar with these sorts of calls, so one question here:

      The values that should possibly be excluded: Where do they come from? Is this some sort of recursive operation here?

      Do the values come from one result of the api-call itself - & shall then be checked against all values that have been called so far?

      Or is it "just" the list/table that feeds into the function itself? (Then we would only need to remove duplicates)

       

      Also could you please give the full code you have so far, for how this function is called?  

      • martynhale's avatar
        martynhale
        Frequent Visitor

        Hi Imke,

         

        Many thanks for getting in touch.

         

        I have a table that contains a field called 'Reviews' - this field contains text received from a customer survey. What I'm doing is to call the Azure Sentiment API pushing the 'Review' text via the api - I then get a sentiment score back from the api which I store in another field in the same table called 'Sentiment Score'. I have created a function for the purpose of calling the api. In simple terms that's it - it works really well.

         

        However, my Azure account allows me 10K api calls a month for free - after that I have to pay, so I don't want to use up free api calls to re-score 'Reviews' that have already been scored. 

         

        So I'm trying to find a way whereby I only submit new records to the api, new records being those that haven't got a sentiment score, rather than submitting all of the records in the table when there may only have a handful of new records.

         

        I hope this makes things a bit clearer?

         

        Best wishes,

        Martyn

         

         

         

        When I get a new 'Review' in the database I have to call the api again to get a score for it.