most-client 1.0.9__tar.gz → 1.0.11__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: most-client
3
- Version: 1.0.9
3
+ Version: 1.0.11
4
4
  Summary: Most AI API for https://the-most.ai
5
5
  Home-page: https://github.com/the-most-ai/most-client
6
6
  Author: George Kasparyants
@@ -26,6 +26,7 @@ Requires-Dist: pytest
26
26
  Requires-Dist: tox
27
27
  Requires-Dist: twine
28
28
  Requires-Dist: httpx
29
+ Requires-Dist: bson
29
30
  Dynamic: author
30
31
  Dynamic: author-email
31
32
  Dynamic: classifier
@@ -27,4 +27,10 @@ print(results)
27
27
  }
28
28
  ]
29
29
  }
30
+
31
+ most.store_info(results['id'], {
32
+ "key1": "value1"
33
+ })
34
+
35
+ most.fetch_info(results['id'])
30
36
  ```
@@ -1,8 +1,8 @@
1
- from typing import List
1
+ from typing import List, Dict
2
2
  import json5
3
3
  import requests
4
4
  from adaptix import Retort
5
- from most.types import Audio, Result, Script, JobStatus, Text
5
+ from most.types import Audio, Result, Script, JobStatus, Text, StoredAudioData, is_valid_id
6
6
  from pathlib import Path
7
7
 
8
8
 
@@ -144,8 +144,9 @@ class MostClient(object):
144
144
  return self.retort.load(audio_list, List[Audio])
145
145
 
146
146
  def get_model_script(self) -> Script:
147
- if self.model_id is None:
148
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
147
+ if not is_valid_id(self.model_id):
148
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
149
+
149
150
  resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/model/{self.model_id}/script")
150
151
  return self.retort.load(resp.json(), Script)
151
152
 
@@ -155,45 +156,82 @@ class MostClient(object):
155
156
  for model in resp.json()]
156
157
 
157
158
  def apply(self, audio_id) -> Result:
158
- if self.model_id is None:
159
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
159
+ if not is_valid_id(self.model_id):
160
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
161
+
162
+ if not is_valid_id(audio_id):
163
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
164
+
160
165
  resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply")
161
166
  return self.retort.load(resp.json(), Result)
162
167
 
163
168
  def apply_later(self, audio_id) -> Result:
164
- if self.model_id is None:
165
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
169
+ if not is_valid_id(self.model_id):
170
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
171
+
172
+ if not is_valid_id(audio_id):
173
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
174
+
166
175
  resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply_async")
167
176
  return self.retort.load(resp.json(), Result)
168
177
 
169
178
  def get_job_status(self, audio_id) -> JobStatus:
170
- if self.model_id is None:
171
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
179
+ if not is_valid_id(self.model_id):
180
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
181
+
182
+ if not is_valid_id(audio_id):
183
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
184
+
172
185
  resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply_status")
173
186
  return self.retort.load(resp.json(), JobStatus)
174
187
 
175
188
  def fetch_results(self, audio_id) -> Result:
176
- if self.model_id is None:
177
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
189
+ if not is_valid_id(self.model_id):
190
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
191
+
192
+ if not is_valid_id(audio_id):
193
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
178
194
 
179
195
  resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/results")
180
196
  return self.retort.load(resp.json(), Result)
181
197
 
182
198
  def fetch_text(self, audio_id: str) -> Result:
183
- if self.model_id is None:
184
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
199
+ if not is_valid_id(self.model_id):
200
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
201
+
202
+ if not is_valid_id(audio_id):
203
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
185
204
 
186
205
  resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/text")
187
206
  return self.retort.load(resp.json(), Result)
188
207
 
189
208
  def export(self, audio_ids: List[str]) -> str:
190
- if self.model_id is None:
191
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
209
+ if not is_valid_id(self.model_id):
210
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
192
211
 
193
212
  resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/model/{self.model_id}/export",
194
213
  params={'audio_ids': ','.join(audio_ids)})
195
214
  return resp.url
196
215
 
216
+ def store_info(self,
217
+ audio_id: str,
218
+ data: Dict[str, str]):
219
+ if not is_valid_id(audio_id):
220
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
221
+
222
+ resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/info",
223
+ json={
224
+ "data": data,
225
+ })
226
+ return self.retort.load(resp.json(), StoredAudioData)
227
+
228
+ def fetch_info(self, audio_id: str) -> Dict[str, str]:
229
+ if not is_valid_id(audio_id):
230
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
231
+
232
+ resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/info")
233
+ return self.retort.load(resp.json(), StoredAudioData)
234
+
197
235
  def __call__(self, audio_path: Path):
198
236
  audio = self.upload_audio(audio_path)
199
237
  return self.apply(audio.id)
@@ -1,7 +1,7 @@
1
- from typing import List
1
+ from typing import List, Dict
2
2
  import json5
3
3
  from adaptix import Retort
4
- from most.types import Audio, Result, Script, JobStatus, Text
4
+ from most.types import Audio, Result, Script, JobStatus, Text, StoredAudioData, is_valid_id
5
5
  from pathlib import Path
6
6
  import httpx
7
7
 
@@ -72,6 +72,8 @@ class AsyncMostClient(object):
72
72
 
73
73
  def with_model(self, model_id):
74
74
  client = self.clone()
75
+ if not is_valid_id(self.model_id):
76
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
75
77
  client.model_id = model_id
76
78
  return client
77
79
 
@@ -151,8 +153,9 @@ class AsyncMostClient(object):
151
153
  return self.retort.load(audio_list, List[Audio])
152
154
 
153
155
  async def get_model_script(self) -> Script:
154
- if self.model_id is None:
155
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
156
+ if not is_valid_id(self.model_id):
157
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
158
+
156
159
  resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/model/{self.model_id}/script")
157
160
  return self.retort.load(resp.json(), Script)
158
161
 
@@ -162,45 +165,78 @@ class AsyncMostClient(object):
162
165
  for model in resp.json()]
163
166
 
164
167
  async def apply(self, audio_id) -> Result:
165
- if self.model_id is None:
166
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
168
+ if not is_valid_id(self.model_id):
169
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
170
+
171
+ if not is_valid_id(audio_id):
172
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
173
+
167
174
  resp = await self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply")
168
175
  return self.retort.load(resp.json(), Result)
169
176
 
170
177
  async def apply_later(self, audio_id):
171
- if self.model_id is None:
172
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
178
+ if not is_valid_id(self.model_id):
179
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
180
+
181
+ if not is_valid_id(audio_id):
182
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
183
+
173
184
  resp = await self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply_async")
174
185
  return self.retort.load(resp.json(), Result)
175
186
 
176
187
  async def get_job_status(self, audio_id) -> JobStatus:
177
- if self.model_id is None:
178
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
188
+ if not is_valid_id(self.model_id):
189
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
190
+
191
+ if not is_valid_id(audio_id):
192
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
193
+
179
194
  resp = await self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/apply_status")
180
195
  return self.retort.load(resp.json(), JobStatus)
181
196
 
182
197
  async def fetch_results(self, audio_id) -> Result:
183
- if self.model_id is None:
184
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
198
+ if not is_valid_id(self.model_id):
199
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
200
+
201
+ if not is_valid_id(audio_id):
202
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
185
203
 
186
204
  resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/results")
187
205
  return self.retort.load(resp.json(), Result)
188
206
 
189
207
  async def fetch_text(self, audio_id) -> Result:
190
- if self.model_id is None:
191
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
208
+ if not is_valid_id(self.model_id):
209
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
210
+
211
+ if not is_valid_id(audio_id):
212
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
192
213
 
193
214
  resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/text")
194
215
  return self.retort.load(resp.json(), Result)
195
216
 
196
217
  async def export(self, audio_ids: List[str]) -> str:
197
- if self.model_id is None:
198
- raise RuntimeError("Please choose a model to apply. [try list_models()]")
218
+ if not is_valid_id(self.model_id):
219
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
199
220
 
200
221
  resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/model/{self.model_id}/export",
201
222
  params={'audio_ids': ','.join(audio_ids)})
202
223
  return resp.next_request.url
203
224
 
225
+ async def store_info(self,
226
+ audio_id: str,
227
+ data: Dict[str, str]):
228
+ resp = await self.post(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/info",
229
+ json={
230
+ "data": data,
231
+ })
232
+ return self.retort.load(resp.json(), StoredAudioData)
233
+
234
+ async def fetch_info(self, audio_id: str) -> Dict[str, str]:
235
+ if not is_valid_id(audio_id):
236
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
237
+ resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/info")
238
+ return self.retort.load(resp.json(), StoredAudioData)
239
+
204
240
  async def __call__(self, audio_path: Path):
205
241
  audio = await self.upload_audio(audio_path)
206
242
  return await self.apply(audio.id)
@@ -1,6 +1,15 @@
1
1
  from dataclasses import dataclass
2
+
3
+ from bson import ObjectId
2
4
  from dataclasses_json import dataclass_json, DataClassJsonMixin
3
- from typing import Optional, List, Literal
5
+ from typing import Optional, List, Literal, Dict
6
+
7
+
8
+ @dataclass_json
9
+ @dataclass
10
+ class StoredAudioData(DataClassJsonMixin):
11
+ id: str
12
+ data: Dict[str, str]
4
13
 
5
14
 
6
15
  @dataclass_json
@@ -66,3 +75,13 @@ class Result(DataClassJsonMixin):
66
75
  subcolumns=[subcolumn_result.name
67
76
  for subcolumn_result in column_result.subcolumns])
68
77
  for column_result in self.results])
78
+
79
+
80
+ def is_valid_id(smth_id: Optional[str]) -> bool:
81
+ if smth_id is None:
82
+ return False
83
+ try:
84
+ ObjectId(smth_id)
85
+ return True
86
+ except:
87
+ return False
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: most-client
3
- Version: 1.0.9
3
+ Version: 1.0.11
4
4
  Summary: Most AI API for https://the-most.ai
5
5
  Home-page: https://github.com/the-most-ai/most-client
6
6
  Author: George Kasparyants
@@ -26,6 +26,7 @@ Requires-Dist: pytest
26
26
  Requires-Dist: tox
27
27
  Requires-Dist: twine
28
28
  Requires-Dist: httpx
29
+ Requires-Dist: bson
29
30
  Dynamic: author
30
31
  Dynamic: author-email
31
32
  Dynamic: classifier
@@ -12,3 +12,4 @@ pytest
12
12
  tox
13
13
  twine
14
14
  httpx
15
+ bson
@@ -12,3 +12,4 @@ pytest
12
12
  tox
13
13
  twine
14
14
  httpx
15
+ bson
@@ -8,7 +8,7 @@ with open('requirements.txt', 'r') as f:
8
8
 
9
9
  setup(
10
10
  name='most-client',
11
- version='1.0.9',
11
+ version='1.0.11',
12
12
  python_requires=f'>=3.6',
13
13
  description='Most AI API for https://the-most.ai',
14
14
  url='https://github.com/the-most-ai/most-client',
File without changes
File without changes