Spaces:
Runtime error
Runtime error
Starting some retreivals
Browse files
app.py
CHANGED
@@ -18,7 +18,7 @@ from prompts import rag_prompt_template
|
|
18 |
from defaults import default_llm
|
19 |
from operator import itemgetter
|
20 |
from langchain.schema.output_parser import StrOutputParser
|
21 |
-
|
22 |
|
23 |
|
24 |
|
@@ -93,9 +93,7 @@ async def on_chat_start():
|
|
93 |
)
|
94 |
|
95 |
text_chunks = text_splitter.split_text(extracted_text)
|
96 |
-
# print(f"Number of chunks: {len(text_chunks)} ")
|
97 |
document = [Document(page_content=chunk) for chunk in text_chunks]
|
98 |
-
# print(f"Length of document: {len(document)}")
|
99 |
|
100 |
msg = cl.Message(
|
101 |
content=f"""Splitting the text with a recursive character splitter.
|
@@ -110,10 +108,10 @@ async def on_chat_start():
|
|
110 |
|
111 |
qdrant_vectorstore = getVectorstore(document, file.name)
|
112 |
|
113 |
-
|
114 |
-
#
|
115 |
-
|
116 |
-
|
117 |
protocol_retriever = qdrant_vectorstore.as_retriever(
|
118 |
search_kwargs={
|
119 |
'filter': rest.Filter(
|
@@ -127,9 +125,6 @@ async def on_chat_start():
|
|
127 |
'k': 15,
|
128 |
}
|
129 |
)
|
130 |
-
# # protocol_retriever = qdrant_vectorstore.as_retriever()
|
131 |
-
|
132 |
-
# protocol_retriever = create_protocol_retriever(document_titles)
|
133 |
|
134 |
# Create prompt
|
135 |
rag_prompt = ChatPromptTemplate.from_template(prompts.rag_prompt_template)
|
@@ -159,4 +154,27 @@ async def on_chat_start():
|
|
159 |
)
|
160 |
|
161 |
await msg.send()
|
162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
from defaults import default_llm
|
19 |
from operator import itemgetter
|
20 |
from langchain.schema.output_parser import StrOutputParser
|
21 |
+
from datetime import date
|
22 |
|
23 |
|
24 |
|
|
|
93 |
)
|
94 |
|
95 |
text_chunks = text_splitter.split_text(extracted_text)
|
|
|
96 |
document = [Document(page_content=chunk) for chunk in text_chunks]
|
|
|
97 |
|
98 |
msg = cl.Message(
|
99 |
content=f"""Splitting the text with a recursive character splitter.
|
|
|
108 |
|
109 |
qdrant_vectorstore = getVectorstore(document, file.name)
|
110 |
|
111 |
+
# My vectorstore may have multiple protocols or documents that have been stored and persisted.
|
112 |
+
# But I only want the context of the current session to relate to a document that I just processed
|
113 |
+
# so I need to pass in the title of the document. This will act as a filter for the retrieved
|
114 |
+
# chunks.
|
115 |
protocol_retriever = qdrant_vectorstore.as_retriever(
|
116 |
search_kwargs={
|
117 |
'filter': rest.Filter(
|
|
|
125 |
'k': 15,
|
126 |
}
|
127 |
)
|
|
|
|
|
|
|
128 |
|
129 |
# Create prompt
|
130 |
rag_prompt = ChatPromptTemplate.from_template(prompts.rag_prompt_template)
|
|
|
154 |
)
|
155 |
|
156 |
await msg.send()
|
157 |
+
|
158 |
+
# Now let's test the application to make a consent document
|
159 |
+
start_time = time.time()
|
160 |
+
# Brute force method that just saves each generated section as string
|
161 |
+
summary = rag_chain.invoke({"question":summary_query()})
|
162 |
+
background = rag_chain.invoke({"question":background_query()})
|
163 |
+
number_of_participants = rag_chain.invoke({"question":number_of_participants_query()})
|
164 |
+
study_procedures = rag_chain.invoke({"question":study_procedures_query()})
|
165 |
+
alt_procedures = rag_chain.invoke({"question":alt_procedures_query()})
|
166 |
+
risks = rag_chain.invoke({"question":risks_query()})
|
167 |
+
benefits = rag_chain.invoke({"question":benefits_query()})
|
168 |
+
|
169 |
+
end_time = time.time()
|
170 |
+
execution_time = end_time - start_time
|
171 |
+
|
172 |
+
msg = cl.Message(
|
173 |
+
content=f"""
|
174 |
+
Brute force (sequential) execution time: {execution_time:.2f} seconds.
|
175 |
+
{summary}
|
176 |
+
"""
|
177 |
+
|
178 |
+
)
|
179 |
+
|
180 |
+
await msg.send()
|