rdune71 commited on
Commit
1c03f5e
Β·
1 Parent(s): 81d8a95

Update context handling: provide weather/space weather only when relevant to query

Browse files
Files changed (1) hide show
  1. app.py +20 -4
app.py CHANGED
@@ -149,6 +149,7 @@ async def research_assistant(query, history):
149
  history[-1] = (query, "πŸ” Gathering context...")
150
  yield history
151
 
 
152
  weather_task = asyncio.create_task(add_weather_context())
153
  space_weather_task = asyncio.create_task(add_space_weather_context())
154
  search_task = asyncio.create_task(asyncio.to_thread(perform_search, validated_query))
@@ -173,7 +174,22 @@ async def research_assistant(query, history):
173
  elif result.get("type") == "source":
174
  search_content += f"Source: {result['content']}\n\n"
175
 
176
- enriched_input = f"{validated_query}\n\n{answer_content}Weather: {weather_data}\nSpace Weather: {space_weather_data}\n\nSearch Results:\n{search_content}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
 
178
  server_status = server_monitor.check_server_status()
179
  if not server_status["available"]:
@@ -315,7 +331,7 @@ with gr.Blocks(
315
 
316
  gr.Markdown("# 🧠 AI Research Assistant")
317
  gr.Markdown("This advanced AI assistant combines web search with contextual awareness to answer complex questions. "
318
- "It incorporates current weather and space weather data for richer context.")
319
 
320
  with gr.Tabs():
321
  with gr.TabItem("πŸ’¬ Chat"):
@@ -334,8 +350,8 @@ with gr.Blocks(
334
 
335
  ## Features
336
  - πŸ” Web search integration
337
- - 🌀️ Weather context
338
- - 🌌 Space weather context
339
  - πŸ“š Real-time citations
340
  - ⚑ Streaming output
341
  """)
 
149
  history[-1] = (query, "πŸ” Gathering context...")
150
  yield history
151
 
152
+ # Get weather and space weather context (but don't include in prompt yet)
153
  weather_task = asyncio.create_task(add_weather_context())
154
  space_weather_task = asyncio.create_task(add_space_weather_context())
155
  search_task = asyncio.create_task(asyncio.to_thread(perform_search, validated_query))
 
174
  elif result.get("type") == "source":
175
  search_content += f"Source: {result['content']}\n\n"
176
 
177
+ # Only include context if it seems relevant to the query
178
+ context_section = ""
179
+ lower_query = validated_query.lower()
180
+
181
+ # Check if weather might be relevant
182
+ weather_keywords = ["weather", "temperature", "climate", "rain", "snow", "sun", "storm", "wind", "humidity"]
183
+ if any(keyword in lower_query for keyword in weather_keywords):
184
+ context_section += f"\nCurrent Weather Context: {weather_data}"
185
+
186
+ # Check if space weather might be relevant
187
+ space_keywords = ["space", "solar", "sun", "satellite", "astronomy", "cosmic", "radiation", "flare"]
188
+ if any(keyword in lower_query for keyword in space_keywords):
189
+ context_section += f"\nSpace Weather Context: {space_weather_data}"
190
+
191
+ # Build the enriched input with context only when needed
192
+ enriched_input = f"{validated_query}\n\n{answer_content}Search Results:\n{search_content}{context_section}"
193
 
194
  server_status = server_monitor.check_server_status()
195
  if not server_status["available"]:
 
331
 
332
  gr.Markdown("# 🧠 AI Research Assistant")
333
  gr.Markdown("This advanced AI assistant combines web search with contextual awareness to answer complex questions. "
334
+ "It provides weather and space weather context only when relevant to your query.")
335
 
336
  with gr.Tabs():
337
  with gr.TabItem("πŸ’¬ Chat"):
 
350
 
351
  ## Features
352
  - πŸ” Web search integration
353
+ - 🌀️ Context-aware weather data (only when relevant)
354
+ - 🌌 Context-aware space weather data (only when relevant)
355
  - πŸ“š Real-time citations
356
  - ⚑ Streaming output
357
  """)