2727logger = logging .getLogger (__name__ )
2828
2929API_URL = "https://codification-ape-graph-rag-api.lab.sspcloud.fr"
30+ TIMEOUT = 3600
3031
3132
3233async def evaluate_method (
@@ -49,7 +50,6 @@ async def evaluate_method(
4950 elapsed_td = datetime .timedelta (seconds = elapsed_seconds )
5051
5152 response .raise_for_status ()
52-
5353 preds = process_response (response .json ())
5454 preds_levels = get_all_levels (preds , df_naf , "code_ape" )
5555 save_predictions (preds , method )
@@ -66,8 +66,22 @@ async def evaluate_method(
6666 logger .info (f"✅ Finished evaluation for '{ method } '" )
6767 return preds_levels
6868
69+ except httpx .TimeoutException :
70+ logger .error (
71+ f"⏳ Timeout during '{ method } ': Request took more than { humanize .precisedelta (datetime .timedelta (seconds = TIMEOUT ))} "
72+ )
73+ return pd .DataFrame ()
74+
75+ except httpx .HTTPStatusError as http_exc :
76+ logger .error (f"🚨 HTTP error during '{ method } ': { http_exc .response .status_code } - { http_exc .response .text } " )
77+ return pd .DataFrame ()
78+
79+ except httpx .RequestError as req_exc :
80+ logger .error (f"📡 Network error during '{ method } ': { type (req_exc ).__name__ } - { req_exc } " )
81+ return pd .DataFrame ()
82+
6983 except Exception as e :
70- logger .error (f"❌ Error during '{ method } ': { e } " )
84+ logger .error (f"❌ Unexpected error during '{ method } ': { type ( e ). __name__ } - { e } " )
7185 return pd .DataFrame ()
7286
7387
@@ -77,7 +91,7 @@ async def evaluate_all(
7791 df_naf : pd .DataFrame ,
7892 ground_truth : pd .DataFrame ,
7993) -> List [pd .DataFrame ]:
80- async with httpx .AsyncClient () as client :
94+ async with httpx .AsyncClient (timeout = httpx . Timeout ( TIMEOUT ) ) as client :
8195 tasks = [evaluate_method (client , method , queries , df_naf , ground_truth ) for method in methods ]
8296 return await asyncio .gather (* tasks )
8397
@@ -108,7 +122,7 @@ async def evaluate_all(
108122 else :
109123
110124 async def eval_single ():
111- async with httpx .AsyncClient () as client :
125+ async with httpx .AsyncClient (timeout = httpx . Timeout ( TIMEOUT ) ) as client :
112126 return await evaluate_method (client , methods [0 ], queries , df_naf , ground_truth )
113127
114128 asyncio .run (eval_single ())
0 commit comments