Spaces:
Paused
Paused
angry-meow
commited on
Commit
•
28c2531
1
Parent(s):
9ae7d2a
url loading testing
Browse files- app.py +21 -23
- requirements.txt +1 -0
app.py
CHANGED
@@ -2,6 +2,7 @@ import chainlit as cl
|
|
2 |
from helper_functions import process_file, load_documents_from_url, add_to_qdrant
|
3 |
import models
|
4 |
import agents
|
|
|
5 |
|
6 |
@cl.on_chat_start
|
7 |
async def on_chat_start():
|
@@ -20,38 +21,35 @@ def rename(orig_author: str):
|
|
20 |
|
21 |
@cl.on_message
|
22 |
async def main(message: cl.Message):
|
23 |
-
await cl.Message(
|
24 |
-
content=f"Received: {message.content}",
|
25 |
-
).send()
|
26 |
if message.content.startswith("http://") or message.content.startswith("https://"):
|
27 |
message_type = "url"
|
28 |
else:
|
29 |
message_type = "question"
|
30 |
-
|
31 |
-
await cl.Message(
|
32 |
-
content=f"message_type: {message_type}",
|
33 |
-
).send()
|
34 |
|
35 |
if message_type == "url":
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
await cl.Message(content="split docs").send()
|
41 |
-
for i, doc in enumerate(splits):
|
42 |
-
doc.metadata["user_upload_source"] = f"source_{i}"
|
43 |
-
print(f"Processing {len(docs)} text chunks")
|
44 |
|
45 |
-
|
46 |
-
|
47 |
-
documents=splits
|
48 |
-
)
|
49 |
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
else:
|
53 |
-
|
54 |
-
await
|
|
|
55 |
|
56 |
res = await ask_action()
|
57 |
await handle_response(res)
|
|
|
2 |
from helper_functions import process_file, load_documents_from_url, add_to_qdrant
|
3 |
import models
|
4 |
import agents
|
5 |
+
import asyncio
|
6 |
|
7 |
@cl.on_chat_start
|
8 |
async def on_chat_start():
|
|
|
21 |
|
22 |
@cl.on_message
|
23 |
async def main(message: cl.Message):
|
|
|
|
|
|
|
24 |
if message.content.startswith("http://") or message.content.startswith("https://"):
|
25 |
message_type = "url"
|
26 |
else:
|
27 |
message_type = "question"
|
|
|
|
|
|
|
|
|
28 |
|
29 |
if message_type == "url":
|
30 |
+
try:
|
31 |
+
# Run the document loading and splitting in a thread
|
32 |
+
docs = await asyncio.to_thread(load_documents_from_url, message.content)
|
33 |
+
await cl.Message(content="loaded docs").send()
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
splits = await asyncio.to_thread(models.semanticChunker_tuned.split_documents, docs)
|
36 |
+
await cl.Message(content="split docs").send()
|
|
|
|
|
37 |
|
38 |
+
for i, doc in enumerate(splits):
|
39 |
+
doc.metadata["user_upload_source"] = f"source_{i}"
|
40 |
+
print(f"Processing {len(docs)} text chunks")
|
41 |
+
|
42 |
+
# Add to the qdrant_store asynchronously
|
43 |
+
await asyncio.to_thread(qdrant_store.add_documents, splits)
|
44 |
+
|
45 |
+
await cl.Message(f"Processing `{message.content}` done. You can now ask questions!").send()
|
46 |
+
|
47 |
+
except Exception as e:
|
48 |
+
await cl.Message(f"Error processing the document: {e}").send()
|
49 |
else:
|
50 |
+
# Handle the question as usual
|
51 |
+
response = await asyncio.to_thread(retrieval_augmented_qa_chain.invoke, {"question": message.content})
|
52 |
+
await cl.Message(content=response['content']).send()
|
53 |
|
54 |
res = await ask_action()
|
55 |
await handle_response(res)
|
requirements.txt
CHANGED
@@ -641,6 +641,7 @@ zipp==3.20.2
|
|
641 |
# -r requirements.in
|
642 |
# importlib-metadata
|
643 |
unstructured
|
|
|
644 |
|
645 |
# The following packages are considered to be unsafe in a requirements file:
|
646 |
# setuptools
|
|
|
641 |
# -r requirements.in
|
642 |
# importlib-metadata
|
643 |
unstructured
|
644 |
+
asyncio
|
645 |
|
646 |
# The following packages are considered to be unsafe in a requirements file:
|
647 |
# setuptools
|