From b1b60cce1d054329e99cee1ef323da4ea9876676 Mon Sep 17 00:00:00 2001 From: fuji44 Date: Tue, 15 Nov 2022 20:49:32 +0900 Subject: [PATCH 1/2] feat: Base URL can be changed --- fastlabel/api.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/fastlabel/api.py b/fastlabel/api.py index c8f187b..c05f5af 100644 --- a/fastlabel/api.py +++ b/fastlabel/api.py @@ -4,14 +4,15 @@ from .exceptions import FastLabelException, FastLabelInvalidException -FASTLABEL_ENDPOINT = "https://api.fastlabel.ai/v1/" - class Api: + base_url = "https://api.fastlabel.ai/v1/" access_token = None def __init__(self): + if os.environ.get("FASTLABEL_API_URL"): + self.base_url = os.environ.get("FASTLABEL_API_URL") if not os.environ.get("FASTLABEL_ACCESS_TOKEN"): raise ValueError("FASTLABEL_ACCESS_TOKEN is not configured.") self.access_token = "Bearer " + os.environ.get("FASTLABEL_ACCESS_TOKEN") @@ -27,7 +28,7 @@ def get_request(self, endpoint: str, params=None) -> dict: "Content-Type": "application/json", "Authorization": self.access_token, } - r = requests.get(FASTLABEL_ENDPOINT + endpoint, headers=headers, params=params) + r = requests.get(self.base_url + endpoint, headers=headers, params=params) if r.status_code == 200: return r.json() @@ -52,9 +53,7 @@ def delete_request(self, endpoint: str, params=None) -> dict: "Content-Type": "application/json", "Authorization": self.access_token, } - r = requests.delete( - FASTLABEL_ENDPOINT + endpoint, headers=headers, params=params - ) + r = requests.delete(self.base_url + endpoint, headers=headers, params=params) if r.status_code != 204: try: @@ -77,10 +76,12 @@ def post_request(self, endpoint, payload=None): "Content-Type": "application/json", "Authorization": self.access_token, } - r = requests.post(FASTLABEL_ENDPOINT + endpoint, json=payload, headers=headers) + r = requests.post(self.base_url + endpoint, json=payload, headers=headers) if r.status_code == 200: return r.json() + elif r.status_code == 204: + return else: try: error = r.json()["message"] @@ -102,7 +103,7 @@ def put_request(self, endpoint, payload=None): "Content-Type": "application/json", "Authorization": self.access_token, } - r = requests.put(FASTLABEL_ENDPOINT + endpoint, json=payload, headers=headers) + r = requests.put(self.base_url + endpoint, json=payload, headers=headers) if r.status_code == 200: return r.json() From 597a31c76701d586441442dbb42689368d2046e5 Mon Sep 17 00:00:00 2001 From: fuji44 Date: Tue, 15 Nov 2022 20:53:56 +0900 Subject: [PATCH 2/2] docs: fix descriptions and links --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index dc4922d..e5e7532 100644 --- a/README.md +++ b/README.md @@ -2115,7 +2115,7 @@ Create a new dataset. ```python dataset = client.create_dataset( name="Japanese Dogs", - slug="japanese_dogs", + slug="japanese-dogs", type="image" ) ``` @@ -2128,7 +2128,7 @@ See API docs for details. { 'id': 'YOUR_DATASET_ID', 'name': 'Japanese Dogs', - 'slug': 'japanese_dogs', + 'slug': 'japanese-dogs', 'type': 'image', 'createdAt': '2022-10-31T02:20:00.248Z', 'updatedAt': '2022-10-31T02:20:00.248Z' @@ -2164,7 +2164,7 @@ datasets = client.get_datasets( ) ``` -If you wish to retrieve more than 1000 data sets, please refer to the Task [sample code](#get%20tasks). +If you wish to retrieve more than 1000 data sets, please refer to the Task [sample code](#get-tasks). ### Update Dataset @@ -2250,7 +2250,7 @@ dataset_objects = client.get_dataset_objects( ) ``` -If you wish to retrieve more than 1000 data sets, please refer to the Task [sample code](#get%20tasks). +If you wish to retrieve more than 1000 data sets, please refer to the Task [sample code](#get-tasks). ### Delete Dataset Object