@@ -61,6 +61,9 @@ class OpenlayerClient(object):
61
61
Your API key. You can find your workspace API key in your
62
62
`account settings <https://docs.openlayer.com/documentation/how-to-guides/find-your-api-key>`_
63
63
settings page.
64
+ verbose : bool, default True
65
+ Whether to print out success messages to the console. E.g., when data is
66
+ successfully uploaded, a resource is staged, etc.
64
67
65
68
Examples
66
69
--------
@@ -73,8 +76,9 @@ class OpenlayerClient(object):
73
76
>>> client = openlayer.OpenlayerClient('YOUR_API_KEY_HERE')
74
77
"""
75
78
76
- def __init__ (self , api_key : str = None ):
79
+ def __init__ (self , api_key : str = None , verbose : bool = True ):
77
80
self .api = api .Api (api_key )
81
+ self .verbose = verbose
78
82
79
83
if not os .path .exists (constants .OPENLAYER_DIR ):
80
84
os .makedirs (constants .OPENLAYER_DIR )
@@ -164,9 +168,10 @@ def create_project(
164
168
project_dir = os .path .join (constants .OPENLAYER_DIR , f"{ project .id } /staging" )
165
169
os .makedirs (project_dir )
166
170
167
- print (
168
- f"Created your project. Navigate to { project .links ['app' ]} to see it."
169
- )
171
+ if self .verbose :
172
+ print (
173
+ f"Created your project. Navigate to { project .links ['app' ]} to see it."
174
+ )
170
175
return project
171
176
172
177
def load_project (self , name : str ) -> Project :
@@ -216,7 +221,8 @@ def load_project(self, name: str) -> Project:
216
221
if not os .path .exists (project_dir ):
217
222
os .makedirs (project_dir )
218
223
219
- print (f"Found your project. Navigate to { project .links ['app' ]} to see it." )
224
+ if self .verbose :
225
+ print (f"Found your project. Navigate to { project .links ['app' ]} to see it." )
220
226
return project
221
227
222
228
def create_or_load_project (
@@ -581,7 +587,8 @@ def commit(self, message: str, project_id: str, force: bool = False):
581
587
with open (f"{ project_dir } /commit.yaml" , "w" , encoding = "UTF-8" ) as commit_file :
582
588
yaml .dump (commit , commit_file )
583
589
584
- print ("Committed!" )
590
+ if self .verbose :
591
+ print ("Committed!" )
585
592
586
593
def _check_llm_and_no_outputs (self , project_dir : str ) -> bool :
587
594
"""Checks if the project's staging area contains an LLM and no outputs."""
@@ -638,7 +645,10 @@ def push(self, project_id: str, task_type: TaskType) -> Optional[ProjectVersion]
638
645
project_version = ProjectVersion (json = response_body , client = self )
639
646
640
647
self ._post_push_cleanup (project_dir = project_dir )
641
- print ("Pushed!" )
648
+
649
+ if self .verbose :
650
+ print ("Pushed!" )
651
+
642
652
return project_version
643
653
644
654
def _ready_for_push (self , project_dir : str , task_type : TaskType ) -> bool :
@@ -802,7 +812,8 @@ def _stage_resource(
802
812
803
813
shutil .copytree (resource_dir , project_dir + "/" + resource_name )
804
814
805
- print (f"Staged the `{ resource_name } ` resource!" )
815
+ if self .verbose :
816
+ print (f"Staged the `{ resource_name } ` resource!" )
806
817
807
818
def load_project_version (self , version_id : str ) -> Project :
808
819
"""Loads an existing project version from the Openlayer platform. Can be used
@@ -957,10 +968,11 @@ def create_inference_pipeline(
957
968
inference_pipeline_data , self .api .upload , self , task_type
958
969
)
959
970
960
- print (
961
- "Created your inference pipeline. Navigate to"
962
- f" { inference_pipeline .links ['app' ]} to see it."
963
- )
971
+ if self .verbose :
972
+ print (
973
+ "Created your inference pipeline. Navigate to"
974
+ f" { inference_pipeline .links ['app' ]} to see it."
975
+ )
964
976
return inference_pipeline
965
977
966
978
def load_inference_pipeline (
@@ -982,10 +994,11 @@ def load_inference_pipeline(
982
994
inference_pipeline_data ["items" ][0 ], self .api .upload , self , task_type
983
995
)
984
996
985
- print (
986
- "Found your inference pipeline."
987
- f" Navigate to { inference_pipeline .links ['app' ]} to see it."
988
- )
997
+ if self .verbose :
998
+ print (
999
+ "Found your inference pipeline."
1000
+ f" Navigate to { inference_pipeline .links ['app' ]} to see it."
1001
+ )
989
1002
return inference_pipeline
990
1003
991
1004
def upload_reference_dataset (
@@ -1047,7 +1060,8 @@ def upload_reference_dataset(
1047
1060
storage_uri_key = "referenceDatasetUri" ,
1048
1061
method = "PUT" ,
1049
1062
)
1050
- print ("Reference dataset uploaded!" )
1063
+ if self .verbose :
1064
+ print ("Reference dataset uploaded!" )
1051
1065
1052
1066
def upload_reference_dataframe (
1053
1067
self ,
@@ -1111,7 +1125,8 @@ def stream_data(
1111
1125
body = body ,
1112
1126
include_metadata = False ,
1113
1127
)
1114
- print ("Stream published!" )
1128
+ if self .verbose :
1129
+ print ("Stream published!" )
1115
1130
1116
1131
def _strip_read_only_fields (self , config : Dict [str , any ]) -> Dict [str , any ]:
1117
1132
"""Strips read-only fields from the config."""
@@ -1187,7 +1202,8 @@ def publish_batch_data(
1187
1202
),
1188
1203
presigned_url_query_params = presigned_url_query_params ,
1189
1204
)
1190
- print ("Data published!" )
1205
+ if self .verbose :
1206
+ print ("Data published!" )
1191
1207
1192
1208
def _validate_production_data_and_load_config (
1193
1209
self ,
@@ -1316,4 +1332,5 @@ def publish_ground_truths(
1316
1332
presigned_url_endpoint = f"inference-pipelines/{ inference_pipeline_id } /presigned-url" ,
1317
1333
presigned_url_query_params = presigned_url_query_params ,
1318
1334
)
1319
- print ("Ground truths published!" )
1335
+ if self .verbose :
1336
+ print ("Ground truths published!" )
0 commit comments