Skip to content

Commit 41b9bb3

Browse files
committed
fix: added _sub_module_name
1 parent a493be1 commit 41b9bb3

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

ai21/clients/studio/resources/studio_library.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616

1717

1818
class StudioLibrary(StudioResource):
19-
_module_name = "library"
19+
_module_name = "library/files"
2020

2121
def __init__(self, client: AI21HTTPClient):
2222
super().__init__(client)
2323
self.files = LibraryFiles(client)
2424

2525

2626
class LibraryFiles(StudioResource):
27-
_module_name = "library"
27+
_module_name = "library/files"
28+
_sub_module_name = "library"
2829

2930
def create(
3031
self,
@@ -50,15 +51,15 @@ def create(
5051
if body.get("batch_id"):
5152
body["upload_mode"] = UploadMode.BATCH
5253

53-
raw_response = self._post(path=f"/{self._module_name}/files", files=files, body=body, response_cls=dict)
54+
raw_response = self._post(path=f"/{self._module_name}", files=files, body=body, response_cls=dict)
5455

5556
return raw_response["fileId"]
5657

5758
def get(self, file_id: str) -> FileResponse:
58-
return self._get(path=f"/{self._module_name}/files/{file_id}", response_cls=FileResponse)
59+
return self._get(path=f"/{self._module_name}/{file_id}", response_cls=FileResponse)
5960

6061
def get_batch_status(self, batch_id: str) -> BatchStatusResponse:
61-
return self._get(path=f"/{self._module_name}/batches/{batch_id}/status", response_cls=BatchStatusResponse)
62+
return self._get(path=f"/{self._sub_module_name}/batches/{batch_id}/status", response_cls=BatchStatusResponse)
6263

6364
def list(
6465
self,
@@ -69,7 +70,7 @@ def list(
6970
) -> List[FileResponse]:
7071
params = remove_not_given({"offset": offset, "limit": limit})
7172

72-
return self._get(path=f"/{self._module_name}/files", params=params, response_cls=List[FileResponse])
73+
return self._get(path=f"/{self._module_name}", params=params, response_cls=List[FileResponse])
7374

7475
def update(
7576
self,
@@ -86,22 +87,23 @@ def update(
8687
**kwargs,
8788
}
8889
)
89-
self._put(path=f"/{self._module_name}/files/{file_id}", body=body)
90+
self._put(path=f"/{self._module_name}/{file_id}", body=body)
9091

9192
def delete(self, file_id: str) -> None:
92-
self._delete(path=f"/{self._module_name}/files/{file_id}")
93+
self._delete(path=f"/{self._module_name}/{file_id}")
9394

9495

9596
class AsyncStudioLibrary(AsyncStudioResource):
96-
_module_name = "library"
97+
_module_name = "library/files"
9798

9899
def __init__(self, client: AsyncAI21HTTPClient):
99100
super().__init__(client)
100101
self.files = AsyncLibraryFiles(client)
101102

102103

103104
class AsyncLibraryFiles(AsyncStudioResource):
104-
_module_name = "library"
105+
_module_name = "library/files"
106+
_sub_module_name = "library"
105107

106108
async def create(
107109
self,
@@ -127,15 +129,17 @@ async def create(
127129
if body.get("batch_id"):
128130
body["upload_mode"] = UploadMode.BATCH
129131

130-
raw_response = await self._post(path=f"/{self._module_name}/files", files=files, body=body, response_cls=dict)
132+
raw_response = await self._post(path=f"/{self._module_name}", files=files, body=body, response_cls=dict)
131133

132134
return raw_response["fileId"]
133135

134136
async def get(self, file_id: str) -> FileResponse:
135-
return await self._get(path=f"/{self._module_name}/files/{file_id}", response_cls=FileResponse)
137+
return await self._get(path=f"/{self._module_name}/{file_id}", response_cls=FileResponse)
136138

137139
async def get_batch_status(self, batch_id: str) -> BatchStatusResponse:
138-
return await self._get(path=f"/{self._module_name}/batches/{batch_id}/status", response_cls=BatchStatusResponse)
140+
return await self._get(
141+
path=f"/{self._sub_module_name}/batches/{batch_id}/status", response_cls=BatchStatusResponse
142+
)
139143

140144
async def list(
141145
self,
@@ -146,7 +150,7 @@ async def list(
146150
) -> List[FileResponse]:
147151
params = remove_not_given({"offset": offset, "limit": limit})
148152

149-
return await self._get(path=f"/{self._module_name}/files", params=params, response_cls=List[FileResponse])
153+
return await self._get(path=f"/{self._module_name}", params=params, response_cls=List[FileResponse])
150154

151155
async def update(
152156
self,
@@ -163,7 +167,7 @@ async def update(
163167
**kwargs,
164168
}
165169
)
166-
await self._put(path=f"/{self._module_name}/files/{file_id}", body=body)
170+
await self._put(path=f"/{self._module_name}/{file_id}", body=body)
167171

168172
async def delete(self, file_id: str) -> None:
169-
await self._delete(path=f"/{self._module_name}/files/{file_id}")
173+
await self._delete(path=f"/{self._module_name}/{file_id}")

0 commit comments

Comments
 (0)