27
27
logger = logging .getLogger (__name__ )
28
28
29
29
API_URL = "https://codification-ape-graph-rag-api.lab.sspcloud.fr"
30
+ TIMEOUT = 3600
30
31
31
32
32
33
async def evaluate_method (
@@ -49,7 +50,6 @@ async def evaluate_method(
49
50
elapsed_td = datetime .timedelta (seconds = elapsed_seconds )
50
51
51
52
response .raise_for_status ()
52
-
53
53
preds = process_response (response .json ())
54
54
preds_levels = get_all_levels (preds , df_naf , "code_ape" )
55
55
save_predictions (preds , method )
@@ -66,8 +66,22 @@ async def evaluate_method(
66
66
logger .info (f"✅ Finished evaluation for '{ method } '" )
67
67
return preds_levels
68
68
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
+
69
83
except Exception as e :
70
- logger .error (f"❌ Error during '{ method } ': { e } " )
84
+ logger .error (f"❌ Unexpected error during '{ method } ': { type ( e ). __name__ } - { e } " )
71
85
return pd .DataFrame ()
72
86
73
87
@@ -77,7 +91,7 @@ async def evaluate_all(
77
91
df_naf : pd .DataFrame ,
78
92
ground_truth : pd .DataFrame ,
79
93
) -> List [pd .DataFrame ]:
80
- async with httpx .AsyncClient () as client :
94
+ async with httpx .AsyncClient (timeout = httpx . Timeout ( TIMEOUT ) ) as client :
81
95
tasks = [evaluate_method (client , method , queries , df_naf , ground_truth ) for method in methods ]
82
96
return await asyncio .gather (* tasks )
83
97
@@ -108,7 +122,7 @@ async def evaluate_all(
108
122
else :
109
123
110
124
async def eval_single ():
111
- async with httpx .AsyncClient () as client :
125
+ async with httpx .AsyncClient (timeout = httpx . Timeout ( TIMEOUT ) ) as client :
112
126
return await evaluate_method (client , methods [0 ], queries , df_naf , ground_truth )
113
127
114
128
asyncio .run (eval_single ())
0 commit comments