drewgenai commited on
Commit
bf46458
·
1 Parent(s): 435783d

error handling wording changes

Browse files
Files changed (2) hide show
  1. app.py +46 -33
  2. 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
- config = {"configurable": {"thread_id": cl.context.session.id}}
 
 
749
 
750
- # For all messages, use the graph to handle the logic
 
 
 
 
751
  final_answer = cl.Message(content="")
752
 
753
- # Use astream instead of stream since we're using async functions
754
- async for msg_response, metadata in graph.astream(
755
- {"messages": [HumanMessage(content=msg.content)]},
756
- stream_mode="messages",
757
- config=config
758
- ):
759
- if (
760
- msg_response.content
761
- and not isinstance(msg_response, HumanMessage)
762
- and metadata["langgraph_node"] == "supervisor"
763
  ):
764
- await final_answer.stream_token(msg_response.content)
765
-
766
- await final_answer.send()
 
 
 
767
 
768
- # Check if we need to attach a CSV file
 
 
 
 
 
 
 
 
 
769
  csv_path = cl.user_session.get("csv_path")
770
- if csv_path:
771
- try:
772
- # Create a message with the CSV file
773
- file_message = cl.Message(content="Here's the CSV file with the analysis results:")
774
- await file_message.send()
775
-
776
- # Now attach the file to this message
777
- await cl.File(
778
- name="domain_analysis.csv",
779
- path=csv_path,
780
- display="inline"
781
- ).send(for_id=file_message.id)
782
-
783
- # Clear the path to avoid sending it multiple times
784
- cl.user_session.set("csv_path", None)
785
- except Exception as e:
786
- print(f"Error attaching CSV file: {str(e)}")
 
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
- # Document Comparison Tool
2
 
3
- Welcome to Heal Sync! This application will help you link protocols to HEAL CDE
4
 
5
  ## How to use:
6
- 1. Upload PDF file 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 question answering
12
- - Analyze what core domain instruments are used in the uploaded protocol
13
- - Export of comparison results to CSV
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