Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2115,7 +2115,7 @@ Create a new dataset.
```python
dataset = client.create_dataset(
name="Japanese Dogs",
slug="japanese_dogs",
slug="japanese-dogs",
type="image"
)
```
Expand All @@ -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'
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
17 changes: 9 additions & 8 deletions fastlabel/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()
Expand All @@ -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:
Expand All @@ -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
Comment on lines +83 to +84
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

戻りのペイロードがないPOSTレスポンスでAPI側が204を返却するための対策

else:
try:
error = r.json()["message"]
Expand All @@ -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()
Expand Down