@@ -147,6 +147,9 @@ async def ask_question(
147147 # Step 3: Execute query
148148 query_result = query_planner .execute_query (intent , sources )
149149 logger .info (f"[{ request_id } ] Query executed, got { len (query_result .get ('results' , []))} results" )
150+ logger .info (f"[{ request_id } ] Query result keys: { list (query_result .keys ())} " )
151+ logger .info (f"[{ request_id } ] Data source used: { query_result .get ('data_source' , 'unknown' )} " )
152+ logger .info (f"[{ request_id } ] Metric detected: { query_result .get ('metric' , 'unknown' )} " )
150153
151154 # Step 4: Synthesize answer
152155 response = answer_synthesizer .synthesize_answer (intent , query_result , sources )
@@ -343,6 +346,40 @@ async def get_raw_data(dataset_id: str):
343346 query = "SELECT * FROM agri_production LIMIT 10"
344347 elif dataset_id .startswith ('climate' ):
345348 query = "SELECT * FROM climate_obs LIMIT 10"
349+ elif dataset_id .startswith ('live' ):
350+ # For live datasets, return sample structure with mock data
351+ if 'live-1' in dataset_id :
352+ # Market prices structure
353+ sample_data = {
354+ 'state' : ['Maharashtra' , 'Punjab' , 'Gujarat' ],
355+ 'district' : ['Mumbai' , 'Ludhiana' , 'Ahmedabad' ],
356+ 'commodity' : ['Rice' , 'Wheat' , 'Cotton' ],
357+ 'modal_price' : [2500 , 2200 , 5500 ],
358+ 'arrival_date' : ['2024-01-15' , '2024-01-15' , '2024-01-15' ]
359+ }
360+ else :
361+ # Production structure
362+ sample_data = {
363+ 'state' : ['Maharashtra' , 'Punjab' , 'Gujarat' ],
364+ 'crop' : ['Rice' , 'Wheat' , 'Cotton' ],
365+ 'season' : ['Kharif' , 'Rabi' , 'Kharif' ],
366+ 'area' : [1000 , 1200 , 800 ],
367+ 'production' : [2500 , 2800 , 1600 ]
368+ }
369+
370+ results = pd .DataFrame (sample_data )
371+ conn .close ()
372+
373+ return {
374+ "dataset_id" : dataset_id ,
375+ "dataset_title" : dataset_row .iloc [0 ]['dataset_title' ],
376+ "resource_url" : dataset_row .iloc [0 ]['resource_url' ],
377+ "sample_rows" : results .to_dict ('records' ),
378+ "total_sample_rows" : len (results ),
379+ "query_used" : "Live API sample data structure" ,
380+ "timestamp" : datetime .now ().isoformat (),
381+ "note" : "This is sample data structure. Actual data comes from live API."
382+ }
346383 else :
347384 raise HTTPException (status_code = 404 , detail = "No sample data available" )
348385
0 commit comments