5353st .sidebar .header ("⚙️ Configuration" )
5454user_id = st .sidebar .text_input ("User ID" , value = "demo_user" )
5555stream_mode = st .sidebar .radio ("Response Mode" , ["Streaming" , "Standard" ], index = 0 )
56+ # Testing option: Bypass cache to go directly to retrieval + LLM
57+ bypass_cache = st .sidebar .checkbox ("🚫 Bypass Cache (Testing)" , value = False , help = "Skip cache check and go directly to retrieval + LLM" )
5658
5759# Initialize backend models (cached - runs only once)
5860@st .cache_resource
@@ -164,7 +166,7 @@ def init_backend_models():
164166 st .info (f"💡 Follow-up: { msg ['metadata' ]['follow_up' ]} " )
165167
166168# Helper to run async pipeline
167- async def process_message_streaming (user_id : str , message : str ):
169+ async def process_message_streaming (user_id : str , message : str , bypass_cache : bool = False ):
168170 """Process message with streaming support."""
169171 # Create background tasks container to capture tasks
170172 # CRITICAL: FastAPI BackgroundTasks don't execute automatically outside FastAPI request context
@@ -179,9 +181,21 @@ def add_task(self, func, *args, **kwargs):
179181
180182 background_tasks = BackgroundTasksContainer ()
181183
184+ # TESTING: Bypass cache if enabled
185+ original_cache_system = None
186+ if bypass_cache :
187+ print ("[STREAMLIT_STANDALONE] ⚠️ CACHE BYPASS ENABLED - Skipping cache check for testing" )
188+ original_cache_system = backend .cache_system
189+ backend .cache_system = None # Temporarily disable cache
190+
182191 # Run the full pipeline (it will add tasks to our container)
183192 result = await medical_pipeline_api (user_id , message , background_tasks )
184193
194+ # Restore cache system after pipeline
195+ if bypass_cache and original_cache_system is not None :
196+ backend .cache_system = original_cache_system
197+ print ("[STREAMLIT_STANDALONE] Cache system restored" )
198+
185199 # MANUALLY EXECUTE background tasks since FastAPI context doesn't exist in Streamlit
186200 # This is critical - without this, history is never saved and follow-ups can't work
187201 if background_tasks .tasks :
@@ -199,7 +213,7 @@ def add_task(self, func, *args, **kwargs):
199213
200214 return result
201215
202- async def process_message_standard (user_id : str , message : str ):
216+ async def process_message_standard (user_id : str , message : str , bypass_cache : bool = False ):
203217 """Process message in standard mode."""
204218 # Create background tasks container to capture tasks
205219 # CRITICAL: FastAPI BackgroundTasks don't execute automatically outside FastAPI request context
@@ -214,8 +228,20 @@ def add_task(self, func, *args, **kwargs):
214228
215229 background_tasks = BackgroundTasksContainer ()
216230
231+ # TESTING: Bypass cache if enabled
232+ original_cache_system = None
233+ if bypass_cache :
234+ print ("[STREAMLIT_STANDALONE] ⚠️ CACHE BYPASS ENABLED - Skipping cache check for testing" )
235+ original_cache_system = backend .cache_system
236+ backend .cache_system = None # Temporarily disable cache
237+
217238 result = await medical_pipeline_api (user_id , message , background_tasks )
218239
240+ # Restore cache system after pipeline
241+ if bypass_cache and original_cache_system is not None :
242+ backend .cache_system = original_cache_system
243+ print ("[STREAMLIT_STANDALONE] Cache system restored" )
244+
219245 # MANUALLY EXECUTE background tasks since FastAPI context doesn't exist in Streamlit
220246 # This is critical - without this, history is never saved and follow-ups can't work
221247 if background_tasks .tasks :
@@ -267,9 +293,9 @@ def add_task(self, func, *args, **kwargs):
267293 # For streaming, we'll use the standard pipeline but display progressively
268294 # Note: True streaming requires the streaming endpoint, but for standalone
269295 # we'll simulate it with progressive display
270- result = loop .run_until_complete (process_message_streaming (user_id , prompt ))
296+ result = loop .run_until_complete (process_message_streaming (user_id , prompt , bypass_cache ))
271297 else :
272- result = loop .run_until_complete (process_message_standard (user_id , prompt ))
298+ result = loop .run_until_complete (process_message_standard (user_id , prompt , bypass_cache ))
273299
274300 total_time = time .time () - request_start
275301 full_response = result .get ('answer' , '' )
0 commit comments