error handling wording changes
Browse files- app.py +46 -33
- chainlit.md +6 -8
app.py
CHANGED
|
@@ -745,42 +745,55 @@ Please let me know which option you'd like to proceed with, or feel free to ask
|
|
| 745 |
|
| 746 |
@cl.on_message
|
| 747 |
async def on_message(msg: cl.Message):
|
| 748 |
-
|
|
|
|
|
|
|
| 749 |
|
| 750 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 751 |
final_answer = cl.Message(content="")
|
| 752 |
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
| 757 |
-
|
| 758 |
-
):
|
| 759 |
-
if (
|
| 760 |
-
msg_response.content
|
| 761 |
-
and not isinstance(msg_response, HumanMessage)
|
| 762 |
-
and metadata["langgraph_node"] == "supervisor"
|
| 763 |
):
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
|
|
|
|
|
|
|
|
|
| 767 |
|
| 768 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 769 |
csv_path = cl.user_session.get("csv_path")
|
| 770 |
-
if csv_path:
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
|
|
|
|
| 745 |
|
| 746 |
@cl.on_message
|
| 747 |
async def on_message(msg: cl.Message):
|
| 748 |
+
# Show a thinking indicator
|
| 749 |
+
with cl.Step("Heal-Sync to process your request"):
|
| 750 |
+
final_answer = await process_message(msg.content)
|
| 751 |
|
| 752 |
+
await final_answer.send()
|
| 753 |
+
await handle_file_attachments()
|
| 754 |
+
|
| 755 |
+
async def process_message(content: str):
|
| 756 |
+
config = {"configurable": {"thread_id": cl.context.session.id}}
|
| 757 |
final_answer = cl.Message(content="")
|
| 758 |
|
| 759 |
+
try:
|
| 760 |
+
async for msg_response, metadata in graph.astream(
|
| 761 |
+
{"messages": [HumanMessage(content=content)]},
|
| 762 |
+
stream_mode="messages",
|
| 763 |
+
config=config
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 764 |
):
|
| 765 |
+
# Process response
|
| 766 |
+
if should_stream_response(msg_response, metadata):
|
| 767 |
+
await final_answer.stream_token(msg_response.content)
|
| 768 |
+
except Exception as e:
|
| 769 |
+
# Handle graph processing errors gracefully
|
| 770 |
+
await final_answer.stream_token(f"\n\nI encountered an error: {str(e)}")
|
| 771 |
|
| 772 |
+
return final_answer
|
| 773 |
+
|
| 774 |
+
def should_stream_response(msg_response, metadata):
|
| 775 |
+
return (
|
| 776 |
+
msg_response.content
|
| 777 |
+
and not isinstance(msg_response, HumanMessage)
|
| 778 |
+
and metadata["langgraph_node"] == "supervisor"
|
| 779 |
+
)
|
| 780 |
+
|
| 781 |
+
async def handle_file_attachments():
|
| 782 |
csv_path = cl.user_session.get("csv_path")
|
| 783 |
+
if not csv_path:
|
| 784 |
+
return
|
| 785 |
+
|
| 786 |
+
try:
|
| 787 |
+
file_message = cl.Message(content="Here's the CSV file with the analysis results:")
|
| 788 |
+
await file_message.send()
|
| 789 |
+
|
| 790 |
+
await cl.File(
|
| 791 |
+
name="domain_analysis.csv",
|
| 792 |
+
path=csv_path,
|
| 793 |
+
display="inline"
|
| 794 |
+
).send(for_id=file_message.id)
|
| 795 |
+
|
| 796 |
+
# Clear the path to avoid sending it multiple times
|
| 797 |
+
cl.user_session.set("csv_path", None)
|
| 798 |
+
except Exception as e:
|
| 799 |
+
print(f"Error attaching CSV file: {str(e)}")
|
chainlit.md
CHANGED
|
@@ -1,15 +1,13 @@
|
|
| 1 |
-
#
|
| 2 |
|
| 3 |
-
|
| 4 |
|
| 5 |
## How to use:
|
| 6 |
-
1. Upload
|
| 7 |
2. Ask questions about the document or request a comparison
|
| 8 |
3. Download comparison results as needed
|
| 9 |
|
| 10 |
## Features:
|
| 11 |
-
- Document analysis and
|
| 12 |
-
- Analyze what core domain instruments are used in the uploaded protocol
|
| 13 |
-
-
|
| 14 |
-
|
| 15 |
-
Upload your documents to get started!
|
|
|
|
| 1 |
+
# HEAL SYNC
|
| 2 |
|
| 3 |
+
This system will read, extract, and present HEAL CDE information to your screen and in a downloadable crosswalk.
|
| 4 |
|
| 5 |
## How to use:
|
| 6 |
+
1. Upload your Protocol PDFs file(s) when prompted
|
| 7 |
2. Ask questions about the document or request a comparison
|
| 8 |
3. Download comparison results as needed
|
| 9 |
|
| 10 |
## Features:
|
| 11 |
+
- Document analysis and Interactive interface
|
| 12 |
+
- Analyze what core domain instruments are used in the uploaded protocol(s)
|
| 13 |
+
- Downloadloadable crosswalk
|
|
|
|
|
|