treasuremars commited on
Commit
8e32863
·
verified ·
1 Parent(s): 699d994

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -5
app.py CHANGED
@@ -69,16 +69,32 @@ rag_chain = (
69
 
70
  import gradio as gr
71
 
72
- # Function to stream responses
73
- def rag_memory_stream(message, history):
 
 
 
 
 
 
 
 
 
 
 
74
  partial_text = ""
75
- for new_text in rag_chain.stream(message): # Assuming rag_chain is pre-defined
 
 
 
 
76
  partial_text += new_text
 
77
  yield partial_text
78
 
79
  examples = [
80
- "What are the side effects of aspirin?",
81
- "What is the disease for constant fatigue and muscle weakness?"
82
  ]
83
 
84
  # Title and description for the app
 
69
 
70
  import gradio as gr
71
 
72
+ # # Function to stream responses
73
+ # def rag_memory_stream(message, history):
74
+ # partial_text = ""
75
+ # for new_text in rag_chain.stream(message): # Assuming rag_chain is pre-defined
76
+ # partial_text += new_text
77
+ # yield partial_text
78
+
79
+ # Example rag_memory_stream function with history handling
80
+ def rag_memory_stream(messages, history=[]):
81
+ """
82
+ A generator-based function that processes messages, maintains history,
83
+ and streams responses for interaction with the chatbot.
84
+ """
85
  partial_text = ""
86
+ user_message = messages[-1]["content"] # Extract the latest user message
87
+ history.append({"user": user_message, "bot": ""}) # Add to history
88
+
89
+ # Simulate response generation (replace with actual rag_chain logic)
90
+ for new_text in rag_chain.stream(user_message): # Assuming rag_chain is pre-defined
91
  partial_text += new_text
92
+ history[-1]["bot"] = partial_text # Update bot response in history
93
  yield partial_text
94
 
95
  examples = [
96
+ [{"role": "user", "content": "What are the side effects of aspirin?"}],
97
+ [{"role": "user", "content": "Can ibuprofen cause dizziness?"}],
98
  ]
99
 
100
  # Title and description for the app