Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Why is chatgpt api sending an incomplete response and using less tokens than the 4096 token limit?

$
0
0

I'm working on a Python application that utilizes the OpenAI API to process and generate responses based on the text extracted from PDF documents.

def main():load_dotenv()st.set_page_config(page_title="Ask your PDF")st.header("Ask your PDF 💬")# upload filepdf = st.file_uploader("Upload your PDF", type="pdf")# extract the textif pdf is not None:    pdf_reader = PdfReader(pdf)    text = ""    for page in pdf_reader.pages:        text += page.extract_text()    # split into chunks    text_splitter = CharacterTextSplitter(        separator="\n",        chunk_size=1000,        chunk_overlap=200,        length_function=len    )    chunks = text_splitter.split_text(text)    # create embeddings    embeddings = OpenAIEmbeddings()    knowledge_base = FAISS.from_texts(chunks, embeddings)    # show user input    user_question = 'Write a cover letter using file'    if user_question:        docs = knowledge_base.similarity_search(user_question)        llm = OpenAI()        chain = load_qa_chain(llm, chain_type="stuff")        with get_openai_callback() as cb:            response = chain.run(input_documents=docs, question=user_question)            print(cb)        st.write(response)        print(response)if __name__ == '__main__':main()

I was under the impression that the token limit for a single request to the OpenAI API (including both the input and the response) is 4096 tokens. However, I noticed that the responses I'm getting are incomplete and capped at 1074 tokens, which seems to be significantly under the limit.

Incomplete OutputTokens Used


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>