Incomplete response from open AI API

Am trying to generate a response using open AI API to perform a grammar check and expect the output to be in the following JSON format but am not getting a complete output response

Prompt:
Note: The content provided in the “text” field is the input for this prompt

Please highlight all the grammatical errors, missing punctuation marks, removing repetitive words and replacing confusing words based on the input provided in the “text” section and generate an output in the following json format - {
“replacements”: [
{
"value ": “<>”,
"phrase ": “<>”,
“corrective_text”: “<>”,
“corrective_text_phrase”: “<>”,
“type_of_error”: “<>”,
“justification”: “<>”
}
]
},“text” : “<<Travelling cross-country in India offers a vibrant mosaic of cultures, climates and landscapes. From the soaring Himalayas in the North, where majestic mountains rise to the sunny beaches in the South, the diversity amaze. The bustling cities pulse with with energy, while serene villages echo tradition. Temples, palaces, and bustling markets dot the land, showcasing it rich heritage. Sampling aromatic spices and indulging in local cuisines heightens the experience. Despite challenges, navigating India vastness, the warmth of its people and the kaleidoscope of experiences promises an unforgettable journey, leaving impressions that lasts a lifetime.>>”

Output Response:
[
“\n{\n "replacements": [\n {\n "value": "Travelling",\n "phrase": "Travelling cross-country",\n "corrective_text": "Traveling",\n "corrective_text_phrase": "Traveling cross-country",\n "type_of_error": "Spelling",\n "justification": "The correct spelling of the word is ‘Traveling’."\n },\n {\n "value": "cross-country",\n "phrase": "Travelling cross-country",\n "corrective_text": "across the country",\n "corrective_text_phrase": "Traveling across the country",\n "type_of_error": "Grammatical",\n "justification": "The phrase ‘across the country’ is more grammatically correct than ‘cross-country’."\n },\n {\n "value": "India",\n "phrase": "in India",\n "corrective_text": "India",\n "corrective_text_phrase": "in India",\n "type_of_error": "Repetitive",\n "justification": "The word ‘India’ is already mentioned in the previous sentence, so it is not necessary to repeat it."\n },\n {\n "value": "soaring",\n”, INCOMPLETE*
“\nIndia is a country of contrasts, where ancient traditions coexist with modern innovations. From the snow-capped peaks of the Himalayas in the North, to the palm-fringed beaches of the South, the landscape is as diverse as its people. The bustling cities are a melting pot of cultures, with a vibrant energy that is contagious. But amidst the chaos, there is also a sense of serenity in the quiet villages, where time seems to stand still.\n\nThe country’s rich history is evident in its many temples, palaces, and monuments, each one a testament to its glorious past. The Taj Mahal, a symbol of eternal love, stands tall in all its grandeur, while the majestic forts of Rajasthan tell tales of battles and conquests. The bustling markets, filled with colorful spices, fabrics, and handicrafts, are a feast for the senses and a reflection of India’s diverse heritage.\n\nBut India is not just about sightseeing. It is also a culinary paradise, with each region offering its own unique flavors and dishes. From the fiery curries of the North to the fragrant biryanis of the South, every meal is a journey in itself. And no trip to India is complete without trying the street food, where the flavors are bold”
]
}

What model are you using? Settings?

Might want to give it a one-shot example of your desired output if it’s 3.5…

Am using gpt 3.5 Turbo instruct with the following setting

llm = OpenAI(model_name=“gpt-3.5-turbo-instruct”, openai_api_key=openai_api_key, temperature=0.2)

Python logic for your reference:
def process_text(input_text):
chunk_size = 1000 # Adjust the chunk size based on your requirements
chunks = [input_text[i:i + chunk_size] for i in range(0, len(input_text), chunk_size)]
llm_output =

for chunk in chunks:
    final_prompt = prompt.format(input=chunk)
    chunk_output = llm(final_prompt)
    llm_output.append(chunk_output)

return llm_output

@app.route(‘/api/<api_name>’, methods=[‘GET’])
def resolve_api(api_name):
try:
allowed_apis = [‘correct-grammar’]
if api_name not in allowed_apis:
return jsonify({“error”: f"Invalid API route. Allowed routes: {', '.join(allowed_apis)}"}), 400

    input_text = request.args.get('input_text', '')
    llm_output = process_text(input_text)

    response = {
        "input": input_text,
        "output": llm_output
    }
    return jsonify(response)
except Exception as e:
    # Log any exceptions
    root_logger.exception("An error occurred: %s", e)
    return jsonify({"error": "An error occurred while processing the request."}), 500