1717import requests
1818from tqdm import tqdm
1919
20+ from .. import constants
21+ from .. import exceptions as openlayer_exceptions
2022from . import base_model_runner
2123
2224
@@ -287,8 +289,8 @@ def __init__(
287289 ):
288290 super ().__init__ (logger , ** kwargs )
289291 if kwargs .get ("anthropic_api_key" ) is None :
290- raise ValueError (
291- "Anthropic API key must be provided. Please pass it as the "
292+ raise openlayer_exceptions . OpenlayerMissingLlmApiKey (
293+ "Please pass your Anthropic API key as the "
292294 "keyword argument 'anthropic_api_key'"
293295 )
294296
@@ -358,8 +360,8 @@ def __init__(
358360 ):
359361 super ().__init__ (logger , ** kwargs )
360362 if kwargs .get ("cohere_api_key" ) is None :
361- raise ValueError (
362- "Cohere API key must be provided. Please pass it as the "
363+ raise openlayer_exceptions . OpenlayerMissingLlmApiKey (
364+ "Please pass your Cohere API key as the "
363365 "keyword argument 'cohere_api_key'"
364366 )
365367
@@ -374,8 +376,8 @@ def _initialize_llm(self):
374376 api_key = self .cohere_api_key , check_api_key = True
375377 )
376378 except Exception as e :
377- raise ValueError (
378- "Cohere API key is invalid. Please pass a valid API key as the "
379+ raise openlayer_exceptions . OpenlayerInvalidLlmApiKey (
380+ "Please pass a valid Cohere API key as the "
379381 f"keyword argument 'cohere_api_key' \n Error message: { e } "
380382 ) from e
381383 if self .model_config .get ("model" ) is None :
@@ -441,8 +443,8 @@ def __init__(
441443 ):
442444 super ().__init__ (logger , ** kwargs )
443445 if kwargs .get ("openai_api_key" ) is None :
444- raise ValueError (
445- "OpenAI API key must be provided. Please pass it as the "
446+ raise openlayer_exceptions . OpenlayerMissingLlmApiKey (
447+ "Please pass your OpenAI API key as the "
446448 "keyword argument 'openai_api_key'"
447449 )
448450
@@ -459,8 +461,8 @@ def _initialize_llm(self):
459461 try :
460462 openai .Model .list ()
461463 except Exception as e :
462- raise ValueError (
463- "OpenAI API key is invalid. Please pass a valid API key as the "
464+ raise openlayer_exceptions . OpenlayerInvalidLlmApiKey (
465+ "Please pass a valid OpenAI API key as the "
464466 f"keyword argument 'openai_api_key' \n Error message: { e } "
465467 ) from e
466468 if self .model_config .get ("model" ) is None :
@@ -540,8 +542,7 @@ def _initialize_llm(self):
540542 """Initializes the self-hosted LL model."""
541543 # Check if API key is valid
542544 try :
543- # TODO: move request timeout to constants.py
544- requests .get (self .url , timeout = 10800 )
545+ requests .get (self .url , timeout = constants .REQUESTS_TIMEOUT )
545546 except Exception as e :
546547 raise ValueError (
547548 "URL is invalid. Please pass a valid URL as the "
@@ -574,8 +575,9 @@ def _make_request(self, llm_input: str) -> Dict[str, Any]:
574575 "Content-Type" : "application/json" ,
575576 }
576577 data = {self .input_key : llm_input }
577- # TODO: move request timeout to constants.py
578- response = requests .post (self .url , headers = headers , json = data , timeout = 10800 )
578+ response = requests .post (
579+ self .url , headers = headers , json = data , timeout = constants .REQUESTS_TIMEOUT
580+ )
579581 if response .status_code == 200 :
580582 response_data = response .json ()[0 ]
581583 return response_data
0 commit comments