Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,7 @@ def get_text_chunk(text):
|
|
| 33 |
return chunks
|
| 34 |
|
| 35 |
#embedding using openAI embedding. Warn: This will cost you money
|
|
|
|
| 36 |
def get_vectorstore_openAI(text_chunks):
|
| 37 |
embeddings = OpenAIEmbeddings()
|
| 38 |
vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
|
|
@@ -46,7 +47,8 @@ def get_vectorstore(text_chunks):
|
|
| 46 |
return vectorstore
|
| 47 |
|
| 48 |
def get_conversation_chain(vectorstore):
|
| 49 |
-
llm = ChatOpenAI()
|
|
|
|
| 50 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
| 51 |
conversation_chain = ConversationalRetrievalChain.from_llm(
|
| 52 |
llm=llm,
|
|
@@ -68,8 +70,8 @@ def handle_userinput(user_question):
|
|
| 68 |
def main():
|
| 69 |
##############################################################################
|
| 70 |
#load openai api_key from .evn
|
| 71 |
-
load_dotenv()
|
| 72 |
-
|
| 73 |
|
| 74 |
##############################################################################
|
| 75 |
#set up basic page
|
|
@@ -105,7 +107,7 @@ def main():
|
|
| 105 |
print('text_chunks are generated')
|
| 106 |
|
| 107 |
#create vector store
|
| 108 |
-
vectorstore =
|
| 109 |
print('vectorstore is created')
|
| 110 |
|
| 111 |
#create converstion chain
|
|
|
|
| 33 |
return chunks
|
| 34 |
|
| 35 |
#embedding using openAI embedding. Warn: This will cost you money
|
| 36 |
+
|
| 37 |
def get_vectorstore_openAI(text_chunks):
|
| 38 |
embeddings = OpenAIEmbeddings()
|
| 39 |
vectorstore = FAISS.from_texts(texts=text_chunks, embedding=embeddings)
|
|
|
|
| 47 |
return vectorstore
|
| 48 |
|
| 49 |
def get_conversation_chain(vectorstore):
|
| 50 |
+
# llm = ChatOpenAI()
|
| 51 |
+
llm =
|
| 52 |
memory = ConversationBufferMemory(memory_key='chat_history', return_messages=True)
|
| 53 |
conversation_chain = ConversationalRetrievalChain.from_llm(
|
| 54 |
llm=llm,
|
|
|
|
| 70 |
def main():
|
| 71 |
##############################################################################
|
| 72 |
#load openai api_key from .evn
|
| 73 |
+
# load_dotenv()
|
| 74 |
+
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 75 |
|
| 76 |
##############################################################################
|
| 77 |
#set up basic page
|
|
|
|
| 107 |
print('text_chunks are generated')
|
| 108 |
|
| 109 |
#create vector store
|
| 110 |
+
vectorstore = get_vectorstore_openAI(text_chunks)
|
| 111 |
print('vectorstore is created')
|
| 112 |
|
| 113 |
#create converstion chain
|