11"""Provider validation utilities for testing API keys and models during onboarding."""
22
33import json
4+
45import httpx
6+
57from utils .container_utils import transform_localhost_url
68from utils .logging_config import get_logger
79from utils .watsonx_retry import request_with_retry
@@ -270,7 +272,7 @@ async def _test_openai_lightweight_health(api_key: str) -> None:
270272
271273 except httpx .TimeoutException :
272274 logger .error ("OpenAI lightweight health check timed out" )
273- raise Exception ("OpenAI API request timed out" )
275+ raise Exception ("OpenAI API request timed out" ) from None
274276 except Exception as e :
275277 logger .error (f"OpenAI lightweight health check failed: { str (e )} " )
276278 raise
@@ -340,7 +342,7 @@ async def _test_openai_completion_with_tools(api_key: str, llm_model: str) -> No
340342
341343 except httpx .TimeoutException :
342344 logger .error ("OpenAI completion test timed out" )
343- raise Exception ("Request timed out" )
345+ raise Exception ("Request timed out" ) from None
344346 except Exception as e :
345347 logger .error (f"OpenAI completion test failed: { str (e )} " )
346348 raise
@@ -382,7 +384,7 @@ async def _test_openai_embedding(api_key: str, embedding_model: str) -> None:
382384
383385 except httpx .TimeoutException :
384386 logger .error ("OpenAI embedding test timed out" )
385- raise Exception ("Request timed out" )
387+ raise Exception ("Request timed out" ) from None
386388 except Exception as e :
387389 logger .error (f"OpenAI embedding test failed: { str (e )} " )
388390 raise
@@ -425,7 +427,7 @@ async def _test_watsonx_lightweight_health(api_key: str, endpoint: str, project_
425427
426428 except httpx .TimeoutException :
427429 logger .error ("WatsonX lightweight health check timed out" )
428- raise Exception ("WatsonX API request timed out" )
430+ raise Exception ("WatsonX API request timed out" ) from None
429431 except Exception as e :
430432 logger .error (f"WatsonX lightweight health check failed: { str (e )} " )
431433 raise
@@ -516,7 +518,7 @@ async def _test_watsonx_completion_with_tools(
516518
517519 except httpx .TimeoutException :
518520 logger .error ("IBM Watson completion test timed out" )
519- raise Exception ("Request timed out" )
521+ raise Exception ("Request timed out" ) from None
520522 except Exception as e :
521523 logger .error (f"IBM Watson completion test failed: { str (e )} " )
522524 # If the error message contains JSON, parse it to extract just the message
@@ -525,7 +527,7 @@ async def _test_watsonx_completion_with_tools(
525527 json_part = error_str .split ("IBM Watson API error: " , 1 )[1 ]
526528 parsed_message = _parse_json_error_message (json_part )
527529 if parsed_message != json_part :
528- raise Exception (f"IBM Watson API error: { parsed_message } " )
530+ raise Exception (f"IBM Watson API error: { parsed_message } " ) from e
529531 raise
530532
531533
@@ -601,7 +603,7 @@ async def _test_watsonx_embedding(
601603
602604 except httpx .TimeoutException :
603605 logger .error ("IBM Watson embedding test timed out" )
604- raise Exception ("Request timed out" )
606+ raise Exception ("Request timed out" ) from None
605607 except Exception as e :
606608 logger .error (f"IBM Watson embedding test failed: { str (e )} " )
607609 # If the error message contains JSON, parse it to extract just the message
@@ -610,7 +612,7 @@ async def _test_watsonx_embedding(
610612 json_part = error_str .split ("IBM Watson API error: " , 1 )[1 ]
611613 parsed_message = _parse_json_error_message (json_part )
612614 if parsed_message != json_part :
613- raise Exception (f"IBM Watson API error: { parsed_message } " )
615+ raise Exception (f"IBM Watson API error: { parsed_message } " ) from e
614616 raise
615617
616618
@@ -640,7 +642,7 @@ async def _test_ollama_lightweight_health(endpoint: str) -> None:
640642
641643 except httpx .TimeoutException :
642644 logger .error ("Ollama lightweight health check timed out" )
643- raise Exception ("Ollama endpoint timed out" )
645+ raise Exception ("Ollama endpoint timed out" ) from None
644646 except Exception as e :
645647 logger .error (f"Ollama lightweight health check failed: { str (e )} " )
646648 raise
@@ -692,7 +694,7 @@ async def _test_ollama_completion_with_tools(llm_model: str, endpoint: str) -> N
692694
693695 except httpx .TimeoutException :
694696 logger .error ("Ollama completion test timed out" )
695- raise httpx .TimeoutException ("Ollama is busy or model inference timed out" )
697+ raise httpx .TimeoutException ("Ollama is busy or model inference timed out" ) from None
696698 except Exception as e :
697699 logger .error (f"Ollama completion test failed: { str (e )} " )
698700 raise
@@ -731,7 +733,7 @@ async def _test_ollama_embedding(embedding_model: str, endpoint: str) -> None:
731733
732734 except httpx .TimeoutException :
733735 logger .error ("Ollama embedding test timed out" )
734- raise httpx .TimeoutException ("Ollama is busy or embedding generation timed out" )
736+ raise httpx .TimeoutException ("Ollama is busy or embedding generation timed out" ) from None
735737 except Exception as e :
736738 logger .error (f"Ollama embedding test failed: { str (e )} " )
737739 raise
@@ -769,7 +771,7 @@ async def _test_anthropic_lightweight_health(api_key: str) -> None:
769771
770772 except httpx .TimeoutException :
771773 logger .error ("Anthropic lightweight health check timed out" )
772- raise Exception ("Anthropic API request timed out" )
774+ raise Exception ("Anthropic API request timed out" ) from None
773775 except Exception as e :
774776 logger .error (f"Anthropic lightweight health check failed: { str (e )} " )
775777 raise
@@ -823,7 +825,7 @@ async def _test_anthropic_completion_with_tools(api_key: str, llm_model: str) ->
823825
824826 except httpx .TimeoutException :
825827 logger .error ("Anthropic completion test timed out" )
826- raise Exception ("Request timed out" )
828+ raise Exception ("Request timed out" ) from None
827829 except Exception as e :
828830 logger .error (f"Anthropic completion test failed: { str (e )} " )
829831 raise
0 commit comments