@@ -44,15 +44,25 @@ def list_deployment(api_key):
44
44
45
45
46
46
def get_workspace_usage (api_key , from_timestamp , to_timestamp ):
47
- url = f"{ DEDICATED_DEPLOYMENT_URL } /usage_workspace?api_key={ api_key } &from_timestamp={ from_timestamp .isoformat ()} &to_timestamp={ to_timestamp .isoformat ()} "
47
+ params = {"api_key" : api_key }
48
+ if from_timestamp is not None :
49
+ params ["from_timestamp" ] = from_timestamp .isoformat () # may contain + sign
50
+ if to_timestamp is not None :
51
+ params ["to_timestamp" ] = to_timestamp .isoformat () # may contain + sign
52
+ url = f"{ DEDICATED_DEPLOYMENT_URL } /usage_workspace?{ urllib .parse .urlencode (params )} "
48
53
response = requests .get (url )
49
54
if response .status_code != 200 :
50
55
return response .status_code , response .text
51
56
return response .status_code , response .json ()
52
57
53
58
54
59
def get_deployment_usage (api_key , deployment_name , from_timestamp , to_timestamp ):
55
- url = f"{ DEDICATED_DEPLOYMENT_URL } /usage_deployment?api_key={ api_key } &deployment_name={ deployment_name } &from_timestamp={ from_timestamp .isoformat ()} &to_timestamp={ to_timestamp .isoformat ()} "
60
+ params = {"api_key" : api_key , "deployment_name" : deployment_name }
61
+ if from_timestamp is not None :
62
+ params ["from_timestamp" ] = from_timestamp .isoformat () # may contain + sign
63
+ if to_timestamp is not None :
64
+ params ["to_timestamp" ] = to_timestamp .isoformat () # may contain + sign
65
+ url = f"{ DEDICATED_DEPLOYMENT_URL } /usage_deployment?{ urllib .parse .urlencode (params )} "
56
66
response = requests .get (url )
57
67
if response .status_code != 200 :
58
68
return response .status_code , response .text
0 commit comments