Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -89,17 +89,20 @@ async def stream_or_async_response(messages: Union[Iterable[ResponseChunk], Asyn
|
|
89 |
layer_outputs.clear()
|
90 |
return message['delta']
|
91 |
|
92 |
-
#
|
93 |
if hasattr(messages, "__aiter__"): # Asynchronous iterable
|
94 |
async for message in messages:
|
95 |
-
|
|
|
96 |
elif hasattr(messages, "__iter__"): # Synchronous iterable
|
97 |
for message in messages:
|
98 |
-
|
|
|
99 |
else:
|
100 |
raise TypeError("'messages' must be an Iterable or AsyncIterable.")
|
101 |
|
102 |
|
|
|
103 |
# Set up the MOAgent
|
104 |
def set_moa_agent(
|
105 |
main_model: str = default_config['main_model'],
|
@@ -269,7 +272,12 @@ if query := st.chat_input("Ask a question"):
|
|
269 |
# Stream and display responses from `stream_or_async_response`
|
270 |
final_response = ""
|
271 |
async for response in stream_or_async_response(messages):
|
272 |
-
|
|
|
|
|
|
|
|
|
|
|
273 |
message_placeholder.markdown(final_response)
|
274 |
|
275 |
# Save the final response to session state
|
@@ -281,6 +289,7 @@ if query := st.chat_input("Ask a question"):
|
|
281 |
asyncio.run(handle_query())
|
282 |
|
283 |
|
|
|
284 |
# Add acknowledgment at the bottom
|
285 |
st.markdown("---")
|
286 |
st.markdown("""
|
|
|
89 |
layer_outputs.clear()
|
90 |
return message['delta']
|
91 |
|
92 |
+
# Check if the input is an async or sync iterable
|
93 |
if hasattr(messages, "__aiter__"): # Asynchronous iterable
|
94 |
async for message in messages:
|
95 |
+
resolved_message = await process_message(message)
|
96 |
+
yield resolved_message
|
97 |
elif hasattr(messages, "__iter__"): # Synchronous iterable
|
98 |
for message in messages:
|
99 |
+
resolved_message = process_message(message) # Do not `await` sync messages
|
100 |
+
yield resolved_message
|
101 |
else:
|
102 |
raise TypeError("'messages' must be an Iterable or AsyncIterable.")
|
103 |
|
104 |
|
105 |
+
|
106 |
# Set up the MOAgent
|
107 |
def set_moa_agent(
|
108 |
main_model: str = default_config['main_model'],
|
|
|
272 |
# Stream and display responses from `stream_or_async_response`
|
273 |
final_response = ""
|
274 |
async for response in stream_or_async_response(messages):
|
275 |
+
# Await the response if it's a coroutine
|
276 |
+
if asyncio.iscoroutine(response):
|
277 |
+
response = await response
|
278 |
+
|
279 |
+
# Accumulate and display the response
|
280 |
+
final_response += response
|
281 |
message_placeholder.markdown(final_response)
|
282 |
|
283 |
# Save the final response to session state
|
|
|
289 |
asyncio.run(handle_query())
|
290 |
|
291 |
|
292 |
+
|
293 |
# Add acknowledgment at the bottom
|
294 |
st.markdown("---")
|
295 |
st.markdown("""
|