Complete response when I make a query to the gpt chat api

Hello

I am using gpt chat api.

I wish that when the API answers the questions I ask it, it gives me the complete answer.

Now, having a certain maximum amount of tokens, it shows me the response in said amount.

I want you to give me the complete answer and not incomplete.

Hi,

Simply remove the max_tokens parameter from your API call, then the maximum available reply will be used.

I applied the change in the code, quite the max_tokens but it gives me the same error, even the response appears shorter.

Can you please post your API calling code?

This is my code:

from flask import Flask, render_template, request
import openai
import os
import fitz # PyMuPDF

app = Flask(name)

Configura tu clave de API de OpenAI

openai.api_key = os.getenv(“OPENAI_API_KEY”)

Ruta al archivo PDF en el servidor

pdf_path = “/opt/openai-quickstart-python/cmw3.pdf”

def extraer_texto_desde_pdf(archivo_pdf):
doc = fitz.open(archivo_pdf)
texto = “”
for pagina in doc:
texto += pagina.get_text()
return texto

def generar_respuesta(texto_entrada):
response = openai.Completion.create(
engine=“text-davinci-003”,
prompt=texto_entrada,
#max_tokens=50
)
return response.choices[0].text.strip()

@app.route(‘/’)
def index():
return render_template(‘index.html’)

@app.route(‘/chat’, methods=[‘POST’])
def chat():
usuario_entrada = request.form[‘usuario_entrada’]

# Leer el contenido del archivo PDF
texto_pdf = extraer_texto_desde_pdf(pdf_path)

# Generar una respuesta basada en el contenido del PDF y la entrada del usuario
respuesta = generar_respuesta(texto_pdf + usuario_entrada)

return respuesta

if name == ‘main’:
app.run(debug=True)