@@ -29,28 +29,67 @@ def __init__(
2929 openlayer_inference_pipeline_id : Optional [str ] = None ,
3030 publish : bool = False ,
3131 ) -> None :
32- self .openlayer_api_key = openlayer_api_key or utils .get_env_variable (
32+ self ._openlayer_api_key = openlayer_api_key or utils .get_env_variable (
3333 "OPENLAYER_API_KEY"
3434 )
35- self .openlayer_project_name = openlayer_project_name or utils .get_env_variable (
35+ self ._openlayer_project_name = openlayer_project_name or utils .get_env_variable (
3636 "OPENLAYER_PROJECT_NAME"
3737 )
38- self .openlayer_inference_pipeline_name = (
38+ self ._openlayer_inference_pipeline_name = (
3939 openlayer_inference_pipeline_name
4040 or utils .get_env_variable ("OPENLAYER_INFERENCE_PIPELINE_NAME" )
4141 or "production"
4242 )
43- self .openlayer_inference_pipeline_id = (
43+ self ._openlayer_inference_pipeline_id = (
4444 openlayer_inference_pipeline_id
4545 or utils .get_env_variable ("OPENLAYER_INFERENCE_PIPELINE_ID" )
4646 )
4747 self .publish = publish
4848
49- self ._validate_attributes ()
50-
5149 # Lazy load the inference pipeline
5250 self .inference_pipeline = None
5351
52+ @property
53+ def openlayer_api_key (self ) -> Optional [str ]:
54+ """The Openlayer API key."""
55+ return self ._get_openlayer_attribute ("_openlayer_api_key" , "OPENLAYER_API_KEY" )
56+
57+ @property
58+ def openlayer_project_name (self ) -> Optional [str ]:
59+ """The name of the project on Openlayer."""
60+ return self ._get_openlayer_attribute (
61+ "_openlayer_project_name" , "OPENLAYER_PROJECT_NAME"
62+ )
63+
64+ @property
65+ def openlayer_inference_pipeline_name (self ) -> Optional [str ]:
66+ """The name of the inference pipeline on Openlayer."""
67+ return self ._get_openlayer_attribute (
68+ "_openlayer_inference_pipeline_name" , "OPENLAYER_INFERENCE_PIPELINE_NAME"
69+ )
70+
71+ @property
72+ def openlayer_inference_pipeline_id (self ) -> Optional [str ]:
73+ """The id of the inference pipeline on Openlayer."""
74+ return self ._get_openlayer_attribute (
75+ "_openlayer_inference_pipeline_id" , "OPENLAYER_INFERENCE_PIPELINE_ID"
76+ )
77+
78+ def _get_openlayer_attribute (
79+ self , attribute_name : str , env_variable : str
80+ ) -> Optional [str ]:
81+ """A helper method to fetch an Openlayer attribute value.
82+
83+ Args:
84+ attribute_name: The name of the attribute in this class.
85+ env_variable: The name of the environment variable to fetch.
86+ """
87+ attribute_value = getattr (self , attribute_name , None )
88+ if not attribute_value :
89+ attribute_value = utils .get_env_variable (env_variable )
90+ setattr (self , attribute_name , attribute_value )
91+ return attribute_value
92+
5493 def _validate_attributes (self ) -> None :
5594 """Granular validation of the arguments."""
5695 if self .publish :
@@ -97,6 +136,7 @@ def stream_data(self, data: Dict[str, any], config: Dict[str, any]) -> None:
97136 config: The configuration for the data stream.
98137 """
99138
139+ self ._validate_attributes ()
100140 self ._check_inference_pipeline_ready ()
101141 self .inference_pipeline .stream_data (stream_data = data , stream_config = config )
102142 logger .info ("Data streamed to Openlayer." )
0 commit comments