Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -41,7 +41,7 @@ async def create_text_splitter(docs: List[langchain_core.documents.Document]):
|
|
41 |
docs = text_splitter.split_documents(docs) # split the documents into chunks
|
42 |
return docs
|
43 |
|
44 |
-
def create_faiss_vector_store(docs: List[langchain_core.documents.Document]) -> FAISS:
|
45 |
"""
|
46 |
Create a FAISS vector store or vector database from a list of documents
|
47 |
More Info: https://python.langchain.com/docs/integrations/vectorstores/faiss/
|
@@ -50,10 +50,13 @@ def create_faiss_vector_store(docs: List[langchain_core.documents.Document]) ->
|
|
50 |
Returns:
|
51 |
FAISS: A vector store containing the documents
|
52 |
"""
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
57 |
|
58 |
def create_bm25_retreiver(docs: List[langchain_core.documents.Document]) -> BM25Retriever:
|
59 |
"""
|
@@ -100,7 +103,7 @@ async def start():
|
|
100 |
await cl.Message(content="embedding model loaded").send()
|
101 |
youtube_link = await cl.AskUserMessage("Please provide the YouTube video link").send() # We can ask the user for input using cl.AskUserMessage().send() which does not affect cl.on_message()
|
102 |
# more on ask user message: https://docs.chainlit.io/api-reference/ask/ask-for-input
|
103 |
-
await cl.Message(content=f"youtube link: {youtube_link}").send() # display and double check to make sure the link is correct
|
104 |
youtube_docs = await create_youtube_transcription(youtube_link['content']) # create the youtube transcription
|
105 |
transcription = youtube_docs[0].page_content # get the transcription of the first document
|
106 |
await cl.Message(content=f"youtube docs: {transcription}").send() # display the transcription of the first document to show that we have the correct data
|
|
|
41 |
docs = text_splitter.split_documents(docs) # split the documents into chunks
|
42 |
return docs
|
43 |
|
44 |
+
async def create_faiss_vector_store(docs: List[langchain_core.documents.Document]) -> FAISS:
|
45 |
"""
|
46 |
Create a FAISS vector store or vector database from a list of documents
|
47 |
More Info: https://python.langchain.com/docs/integrations/vectorstores/faiss/
|
|
|
50 |
Returns:
|
51 |
FAISS: A vector store containing the documents
|
52 |
"""
|
53 |
+
try:
|
54 |
+
embedding = cl.user_session.get("embedding") # we can get the embedding model from the user session or pass as a parameter too!
|
55 |
+
vector_db = FAISS.from_documents(docs, embedding) # create the vector store
|
56 |
+
vector_db.k = 5 # we set k to 5, so we get 5 documents back
|
57 |
+
return vector_db
|
58 |
+
except Exception as e:
|
59 |
+
await cl.Message(content=f"failed to create vector db: {e}").send() # display the error if we failed to create the vector db
|
60 |
|
61 |
def create_bm25_retreiver(docs: List[langchain_core.documents.Document]) -> BM25Retriever:
|
62 |
"""
|
|
|
103 |
await cl.Message(content="embedding model loaded").send()
|
104 |
youtube_link = await cl.AskUserMessage("Please provide the YouTube video link").send() # We can ask the user for input using cl.AskUserMessage().send() which does not affect cl.on_message()
|
105 |
# more on ask user message: https://docs.chainlit.io/api-reference/ask/ask-for-input
|
106 |
+
await cl.Message(content=f"youtube link: {youtube_link['content']}").send() # display and double check to make sure the link is correct
|
107 |
youtube_docs = await create_youtube_transcription(youtube_link['content']) # create the youtube transcription
|
108 |
transcription = youtube_docs[0].page_content # get the transcription of the first document
|
109 |
await cl.Message(content=f"youtube docs: {transcription}").send() # display the transcription of the first document to show that we have the correct data
|