'Receiving "Request body must be present." when trying to use Go with the Azure Cognitive Services Text Summarization

As the title states, I get the error 'Request body must be present.' when trying to call the Cognitive Services API on Azure for text summarization. I have most likely narrowed down the cause of the error to the following line of code:

r := strings.NewReader("{\"analysisInput\":{\"documents\":" + string(documents) + "},\"tasks\":{\"extractiveSummarizationTasks\":{\"parameters\":" + string(tasks) + "}}}")

which is required to match the following JSON:

  "analysisInput": {
    "documents": [
      {
        "language": "en",
        "id": "1",
        "text": "At Microsoft, we have been on a quest to advance AI beyond existing techniques, by taking a more holistic, human-centric approach to learning and understanding. As Chief Technology Officer of Azure AI Cognitive Services, I have been working with a team of amazing scientists and engineers to turn this quest into a reality. In my role, I enjoy a unique perspective in viewing the relationship among three attributes of human cognition: monolingual text (X), audio or visual sensory signals, (Y) and multilingual (Z). At the intersection of all three, there’s magic—what we call XYZ-code as illustrated in Figure 1—a joint representation to create more powerful AI that can speak, hear, see, and understand humans better. We believe XYZ-code will enable us to fulfill our long-term vision: cross-domain transfer learning, spanning modalities and languages. The goal is to have pretrained models that can jointly learn representations to support a broad range of downstream AI tasks, much in the way humans do today. Over the past five years, we have achieved human performance on benchmarks in conversational speech recognition, machine translation, conversational question answering, machine reading comprehension, and image captioning. These five breakthroughs provided us with strong signals toward our more ambitious aspiration to produce a leap in AI capabilities, achieving multisensory and multilingual learning that is closer in line with how humans learn and understand. I believe the joint XYZ-code is a foundational component of this aspiration, if grounded with external knowledge sources in the downstream AI tasks."
      }
    ]
  },
  "tasks": {
    "extractiveSummarizationTasks": [
      {
        "parameters": {
          "model-version": "latest",
          "sentenceCount": 3,
          "sortBy": "Offset"
        }
      }
    ]
  }
}

Everything else in the code seems to be correct and not throwing any errors, though here it is if needed: https://gist.github.com/redrover9/c1135a66ff40dd2877071ccb3749fb32.

r is the following:

&{{"analysisInput":{"documents":[{"id":"1","language":"en","text":"Sentence one. Sentence two. Sentence three. Sentence four. Sentence five."}]},"tasks":{"extractiveSummarizationTasks":{"parameters":[{"model-version":"latest","sentenceCount":"3","sortBy":"Offset"}]}}} 0 -1}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source