Spaces:
Runtime error
Runtime error
fix
Browse files- app/main.py +7 -7
- app/rag.py +6 -2
app/main.py
CHANGED
@@ -25,21 +25,21 @@ files_dir = os.path.expanduser("~/wtp_be_files/")
|
|
25 |
session_assistant = ChatPDF()
|
26 |
# session_messages = []
|
27 |
|
28 |
-
# async def stream_generator()
|
|
|
|
|
|
|
29 |
|
30 |
@app.get("/query")
|
31 |
async def process_input(text: str):
|
32 |
if text and len(text.strip()) > 0:
|
33 |
text = text.strip()
|
34 |
print("PRINTING STREAM")
|
35 |
-
agent_text_stream = session_assistant.ask(text)
|
36 |
-
print(agent_text_stream)
|
37 |
-
for text in agent_text_stream:
|
38 |
-
print(text)
|
39 |
-
# yield text
|
40 |
# session_messages.append((text, True))
|
41 |
# session_messages.append((agent_text, False))
|
42 |
-
return StreamingResponse(
|
43 |
|
44 |
|
45 |
@app.post("/upload")
|
|
|
25 |
session_assistant = ChatPDF()
|
26 |
# session_messages = []
|
27 |
|
28 |
+
# async def stream_generator(agent_text_stream):
|
29 |
+
# for text in agent_text_stream:
|
30 |
+
# print(text)
|
31 |
+
# yield text
|
32 |
|
33 |
@app.get("/query")
|
34 |
async def process_input(text: str):
|
35 |
if text and len(text.strip()) > 0:
|
36 |
text = text.strip()
|
37 |
print("PRINTING STREAM")
|
38 |
+
# agent_text_stream = session_assistant.ask(text)
|
39 |
+
# print(agent_text_stream)
|
|
|
|
|
|
|
40 |
# session_messages.append((text, True))
|
41 |
# session_messages.append((agent_text, False))
|
42 |
+
return StreamingResponse(session_assistant.ask(text), media_type='text/event-stream')
|
43 |
|
44 |
|
45 |
@app.post("/upload")
|
app/rag.py
CHANGED
@@ -156,14 +156,18 @@ class ChatPDF:
|
|
156 |
# similarity_top_k=6,
|
157 |
)
|
158 |
|
159 |
-
def ask(self, query: str):
|
160 |
if not self.query_engine:
|
161 |
return "Please, add a PDF document first."
|
162 |
|
163 |
logger.info("retrieving the response to the query")
|
164 |
# response = self.query_engine.query(str_or_query_bundle=query)
|
165 |
streaming_response = self.query_engine.query(query)
|
166 |
-
|
|
|
|
|
|
|
|
|
167 |
|
168 |
def clear(self):
|
169 |
self.query_engine = None
|
|
|
156 |
# similarity_top_k=6,
|
157 |
)
|
158 |
|
159 |
+
async def ask(self, query: str):
|
160 |
if not self.query_engine:
|
161 |
return "Please, add a PDF document first."
|
162 |
|
163 |
logger.info("retrieving the response to the query")
|
164 |
# response = self.query_engine.query(str_or_query_bundle=query)
|
165 |
streaming_response = self.query_engine.query(query)
|
166 |
+
print(streaming_response)
|
167 |
+
# return streaming_response.response_gen
|
168 |
+
for text in streaming_response.response_gen:
|
169 |
+
print(text)
|
170 |
+
yield text
|
171 |
|
172 |
def clear(self):
|
173 |
self.query_engine = None
|