Open AI API model 'Turbo-Instruct' unable to translate complete text

Input Prompt - Passing the below prompt along with the text does an incomplete translation
“input”: “Please translate this prompt to Russian language "Artificial Intelligence (AI) and Machine Learning (ML) are two rapidly evolving fields that have revolutionized various industries. AI refers to the development of computer systems capable of performing tasks that typically require human intelligence, such as learning, reasoning, problem-solving, perception, and language understanding. ML, a subset of AI, focuses on the development of algorithms and statistical models that enable computers to learn from and make predictions or decisions based on data, without being explicitly programmed to do so. AI can be classified into two categories: narrow AI and general AI. Narrow AI, also known as weak AI, is designed to perform specific tasks, such as facial recognition, language translation, or playing chess. It is focused on a single task and does not possess general intelligence. General AI, or strong AI, refers to a machine or system that exhibits human-like intelligence and can perform any intellectual task that a human can. While general AI remains a theoretical concept, narrow AI has seen significant advancements and applications in various fields. ML algorithms can be categorized into several types, including supervised learning, unsupervised learning, reinforcement learning, and deep learning. Supervised learning involves training a model on a labeled dataset, where the algorithm learns to map input data to the correct output based on labeled examples. Unsupervised learning, on the other hand, involves finding patterns or structures in unlabeled data. Reinforcement learning focuses on training a model to make sequences of decisions in order to achieve a goal, with the model receiving feedback in the form of rewards or penalties based on its actions. Deep learning, a subset of ML, uses artificial neural networks to model and solve complex problems, such as image and speech recognition. AI and ML have a wide range of applications across various industries, including healthcare, finance, marketing, and transportation. In healthcare, AI and ML are used for disease diagnosis, personalized treatment plans, and drug discovery. In finance, AI is used for fraud detection, risk assessment, and algorithmic trading. In marketing, AI is used for customer segmentation, personalized advertising, and recommendation systems. In transportation, AI is used for autonomous vehicles, traffic management, and route optimization. Despite their many benefits, AI and ML also raise ethical and societal concerns, such as bias in algorithms, privacy issues, and the impact on jobs and the economy. Addressing these challenges will be crucial to ensuring that AI and ML technologies are used responsibly and ethically to benefit society as a whole."”,

“output”: [
“\nИскусственный интеллект (ИИ) и машинное обучение (МО) - это две стремительно развивающиеся области, которые революционизировали различные отрасли. ИИ относится к разработке компьютерных систем, способных выполнять задачи, обычно требующие человеческого интеллекта, такие как обучение, рассуждение, решение проблем, восприятие и понимание языка. МО, подмножество ИИ, фокусируется на разработке алгоритмов и статистических моделей, позволяющих компьютерам учиться и прогнозировать или принимать решения на основе данных, без явного программирования. ИИ можно классифицировать на две категории: узкий И”,
“althcare, finance, transportation, and entertainment. While AI and ML have the potential to greatly improve efficiency and accuracy in many tasks, there are also concerns about the ethical implications and potential job displacement. As technology continues to advance, it is important for society to carefully consider the implications and ensure responsible development and usage of AI and ML.”,
“\nIn healthcare, AI and ML have the potential to revolutionize the way diseases are diagnosed and treated. With the help of advanced algorithms and machine learning techniques, doctors can analyze large amounts of patient data to identify patterns and make accurate diagnoses. This can lead to faster and more accurate diagnoses, resulting in better treatment outcomes for patients.\n\nAI and ML are also being used in personalized medicine, where treatment plans are tailored to an individual’s unique genetic makeup and medical history. This can improve the effectiveness of treatments and reduce the risk of adverse reactions.\n\nIn addition, AI and ML are being used in drug discovery, helping researchers to identify potential new treatments and accelerate the drug development process. This can lead to the development of new and more effective drugs, improving patient outcomes and reducing healthcare costs.\n\nIn the finance industry, AI and ML are being used to detect fraud and prevent financial crimes. By analyzing large amounts of financial data, AI algorithms can identify patterns and anomalies that could indicate fraudulent activity. This can help financial institutions to prevent fraud and protect their customers’ assets.\n\nAI is also being used in risk assessment, where it can analyze data and make predictions about potential risks, such as loan default or investment performance. This can help financial institutions make more informed decisions and mitigate risks.\n\nIn marketing,”

As you see above the output does not have the complete translated text

Python code:
Below is the actual python code calling the Open AI API

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

template = “”"

prompt = PromptTemplate(

app = Flask(name)

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)

return llm_output

@app.route(‘/api/<api_name>’, methods=[‘GET’])
def resolve_api(api_name):
allowed_apis = [‘translate’]
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

Hi @balajiramnathj - I just tested the prompt itself using gpt-3.5-turbo-instruct. It worked for me when I explicitly included the max_tokens parameter. I set it to 2000 for testing purposes and that always yielded a complete translation (note that I did not use your code itself, my focus was purely on the prompt and the associated parameters).

Thanks for the response but I did try to include max_tokens as provided in the below logic but am still end up with incomplete response

Can you please help me correcting the provided code

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, max_tokens=2000)

return llm_output