Open ai api use problem

i have sucessfully imported the api key but when i am trying to pass it as a parameter in openai embedding function the application is throwing an import error open ai not found please install openai. But i have open ai on my system and also i have not used any openai methods. please help!!

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
from langchain.callbacks import get_openai_callback
import os

headers = {
“authorization”: st.secrets[“auth_token”],
“content-type”: “application/json”

#using 1 pdf
def main():
st.set_page_config(page_title=“chatPdf”, page_icon=“:ice_cube:”)
st.header(“Ask your PDF :speech_balloon:”)
st.write(“Secret Key”, st.secrets[“auth_token”])
“Has environment variables been set:”,
os.environ[“auth_token”] == st.secrets[“auth_token”],
key = st.secrets[“auth_token”]
apikey = os.getenv(“OPENAI_API_KEY”)
# upload file
st.subheader(“Upload a document”)
pdf = st.file_uploader(“”)
if pdf is not None:

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(
    chunks = text_splitter.split_text(text)

    # create embeddings
    embeddings = OpenAIEmbeddings(openai_api_key=apikey)
    knowledge_base = FAISS.from_texts(chunks, embeddings)

    # show user input
    user_question = st.text_input("Ask a question about your PDF:")
    if user_question:
        docs = knowledge_base.similarity_search(user_question)

        llm = OpenAI(openai_api_key=apikey)
        chain = load_qa_chain(llm, chain_type="stuff")
        with get_openai_callback() as cb:
            response =, question=user_question)


if name == ‘main’:

Streamlit Cloud knows nothing about your system. You need to install it in your Streamlit Cloud environment.

actually if u see i have not used openai package so i dont think i need to mention the pakage in the requirement.txt file i have mentioned all the pakages that are used in the script. But even when i am trying to mention openai 0.27.8 in the txt file the log is throwing error.
ERROR: Invalid requirement: ‘openai 0.27.8’ (from line 5 of /app/streamlit/requirements.txt)

langchain.embeddings.openai.OpenAIEmbeddings depends on openai. If installing langchain doesn’t automatically install openai then you have to install it explicitly, as the error message says.

Indeed openai 0.27.8 is not a valid requirement. Try openai==0.27.8 if you are sure that is the version you need.


thank you for the help. :blush:

did you fix it? I’m struggling with the same thing