Fix grammar errors in submitted text

Overview

Suggests changes to grammatical errors found by the model in the submitted string.

Calling syntax

import os
from ai21 import AI21Client
client = AI21Client()

def grammatical_error_correction():
    response = client.gec.create(
        text="jazzz is a great stile off music"
    )
    print(response)
    
# Response
GECResponse(id='3b6dee3d-c206-ea34-8d33-091faaf244b9', corrections=[
  Correction(suggestion='Jazz', start_index=0, end_index=5, original_text='jazzz', correction_type=<CorrectionType.SPELLING: 'Spelling'>), 
  Correction(suggestion='style of', start_index=17, end_index=26, original_text='stile off', correction_type=<CorrectionType.SPELLING: 'Spelling'>)])
ROOT_URL = "https://api.ai21.com/studio/v1/"

def grammatical_error_correction():
  url = ROOT_URL + "gec"
  response = requests.post(
      url,
      headers={"Authorization": f"Bearer {AI21_API_KEY}"}, 
      json={
         "text": "jazzz is a great stile off music"
      }   
  )
  print(response.json())
 
# Response
{'id': 'b92b9259-d4e3-2b4b-6ea2-ee3a56bd7ec5',
 'corrections': [
    {'suggestion': 'Jazz', 'startIndex': 0, 'endIndex': 5, 'originalText': 'jazzz', 'correctionType': 'Spelling'}, 
    {'suggestion': 'style of', 'startIndex': 17, 'endIndex': 26, 'originalText': 'stile off', 'correctionType': 'Spelling'}]}
Language
Authorization
Header
Click Try It! to start a request and see the response here!