Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenAI API error: "openai.error.InvalidRequestError: The model `text-davinci-003` has been deprecated". Any alternative model to fix the code?

I developed a chatbot utilizing OpenAI's API for PDF question answering, relying on the text-davinci-003 model. However, following OpenAI's recent announcement about the deprecation of certain models, such as text-davinci-003, my chatbot encounters an error:

'openai.error.InvalidRequestError: The model text-davinci-003 has been deprecated'.

My chatbot is built in Python using Streamlit. I need some help figuring out how to modify my code to fix this and switch to a supported model. Any insights or assistance would be very much appreciated.

Here is my code:

from dotenv import load_dotenv
import streamlit as st
from PyPDF2 import PdfReader
from langchain.text_splitter import CharacterTextSplitter
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.vectorstores import FAISS
from langchain.chains.question_answering import load_qa_chain
from langchain.llms import OpenAI



def main():
    load_dotenv()
    st.set_page_config(page_title="Ask your pdf", layout="centered",initial_sidebar_state="auto")
    st.header("Ask your pdf(OpenAI) 🤓")
    
    # Uploading the file
    pdf = st.file_uploader("Upload your pdf", type="pdf")
    
    # Extracting the text
    if 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", # Defines a new line 
            chunk_size = 1000,
            chunk_overlap = 200,
            length_function = len
        )
        chunks = text_splitter.split_text(text)

        # Create embeddings
        embeddings = OpenAIEmbeddings()

        # Creating an object on which we will be able to search FAISS
        knowledge_base = FAISS.from_texts(chunks, embeddings)

        # show user input
        user_question = st.text_input("Ask a question about the PDF: ")

        if st.button("Refresh Page"):
            st.caching.clear_cache()
            
        if user_question:
            docs = knowledge_base.similarity_search(user_question)

            llm = OpenAI()
            chain = load_qa_chain(llm, chain_type="stuff")
            response = chain.run(input_documents=docs, question = user_question)

            st.write(response)

if __name__ == '__main__':
    main()
like image 890
Dismay Avatar asked Dec 29 '25 06:12

Dismay


1 Answers

On January 4, 2024, OpenAI deprecated a lot of models.

See the deprecated models and recommended replacements in the tables below.

In your case, change text-davinci-003 for gpt-3.5-turbo-instruct.

Instruct GPT models

SHUTDOWN DATE LEGACY MODEL RECOMMENDED REPLACEMENT
2024-01-04 text-ada-001 gpt-3.5-turbo-instruct
2024-01-04 text-babbage-001 gpt-3.5-turbo-instruct
2024-01-04 text-curie-001 gpt-3.5-turbo-instruct
2024-01-04 text-davinci-001 gpt-3.5-turbo-instruct
2024-01-04 text-davinci-002 gpt-3.5-turbo-instruct
2024-01-04 text-davinci-003 gpt-3.5-turbo-instruct

Base GPT models

SHUTDOWN DATE LEGACY MODEL RECOMMENDED REPLACEMENT
2024-01-04 ada babbage-002
2024-01-04 babbage babbage-002
2024-01-04 curie davinci-002
2024-01-04 davinci davinci-002
2024-01-04 code-davinci-002 gpt-3.5-turbo-instruct

Fine-tuning GPT models

SHUTDOWN DATE LEGACY MODEL RECOMMENDED REPLACEMENT
2024-01-04 ada babbage-002
2024-01-04 babbage babbage-002
2024-01-04 curie davinci-002
2024-01-04 davinci davinci-002, gpt-3.5-turbo, gpt-4

Edit models

SHUTDOWN DATE MODEL RECOMMENDED REPLACEMENT
2024-01-04 text-davinci-edit-001 gpt-4
2024-01-04 code-davinci-edit-001 gpt-4

Embedding models

SHUTDOWN DATE LEGACY MODEL RECOMMENDED REPLACEMENT
2024-01-04 text-similarity-ada-001 text-embedding-ada-002
2024-01-04 text-search-ada-doc-001 text-embedding-ada-002
2024-01-04 text-search-ada-query-001 text-embedding-ada-002
2024-01-04 code-search-ada-code-001 text-embedding-ada-002
2024-01-04 code-search-ada-text-001 text-embedding-ada-002
2024-01-04 text-similarity-babbage-001 text-embedding-ada-002
2024-01-04 text-search-babbage-doc-001 text-embedding-ada-002
2024-01-04 text-search-babbage-query-001 text-embedding-ada-002
2024-01-04 code-search-babbage-code-001 text-embedding-ada-002
2024-01-04 code-search-babbage-text-001 text-embedding-ada-002
2024-01-04 text-similarity-curie-001 text-embedding-ada-002
2024-01-04 text-search-curie-doc-001 text-embedding-ada-002
2024-01-04 text-search-curie-query-001 text-embedding-ada-002
2024-01-04 text-similarity-davinci-001 text-embedding-ada-002
2024-01-04 text-search-davinci-doc-001 text-embedding-ada-002
2024-01-04 text-search-davinci-query-001 text-embedding-ada-002
like image 53
Rok Benko Avatar answered Dec 30 '25 21:12

Rok Benko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!