Spaces:
Sleeping
Sleeping
Sam
commited on
Commit
·
655e2c9
1
Parent(s):
e159a2b
Reverting to non-streaming version
Browse files
app.py
CHANGED
@@ -157,31 +157,15 @@ async def start_chat():
|
|
157 |
# (2) Invokes the RAG chain with the user's message
|
158 |
# (3) Extracts the content from the response and sends it back to the user
|
159 |
|
160 |
-
@cl.on_message
|
161 |
async def handle_message(message: cl.Message):
|
162 |
settings = cl.user_session.get("settings")
|
163 |
|
164 |
-
|
165 |
-
stream_msg = cl.Message(content="")
|
166 |
-
await stream_msg.send() # Send initial empty message to start the stream
|
167 |
|
168 |
-
# Create a generator from the RAG chain
|
169 |
-
response_generator = retrieval_augmented_qa_chain.stream({"question": message.content})
|
170 |
|
171 |
-
#
|
172 |
-
|
173 |
-
|
174 |
-
chunk_content = response_chunk.get("response", {}).get("content", "")
|
175 |
-
if chunk_content:
|
176 |
-
# Stream the chunk to Chainlit
|
177 |
-
await stream_msg.stream_token(chunk_content)
|
178 |
|
179 |
-
|
180 |
-
# response = retrieval_augmented_qa_chain.invoke({"question": message.content})
|
181 |
-
|
182 |
-
|
183 |
-
## # Extracting and sending just the content
|
184 |
-
## content = response["response"].content
|
185 |
-
## pretty_content = content.strip() # Remove any leading/trailing whitespace
|
186 |
-
|
187 |
-
## await cl.Message(content=pretty_content).send()
|
|
|
157 |
# (2) Invokes the RAG chain with the user's message
|
158 |
# (3) Extracts the content from the response and sends it back to the user
|
159 |
|
160 |
+
@cl.on_message
|
161 |
async def handle_message(message: cl.Message):
|
162 |
settings = cl.user_session.get("settings")
|
163 |
|
164 |
+
response = retrieval_augmented_qa_chain.invoke({"question": message.content})
|
|
|
|
|
165 |
|
|
|
|
|
166 |
|
167 |
+
# Extracting and sending just the content
|
168 |
+
content = response["response"].content
|
169 |
+
pretty_content = content.strip() # Remove any leading/trailing whitespace
|
|
|
|
|
|
|
|
|
170 |
|
171 |
+
await cl.Message(content=pretty_content).send()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|