most-client 1.0.22__tar.gz → 1.0.24__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.22
3
+ Version: 1.0.24
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
@@ -18,7 +18,7 @@ from most.types import (
18
18
  Script,
19
19
  StoredAudioData,
20
20
  Text,
21
- is_valid_id, SearchParams, ScriptScoreMapping,
21
+ is_valid_id, SearchParams, ScriptScoreMapping, Dialog,
22
22
  )
23
23
 
24
24
 
@@ -114,6 +114,24 @@ class MostClient(object):
114
114
  raise RuntimeError(resp.json()['message'] if resp.headers.get("Content-Type") == "application/json" else "Something went wrong.")
115
115
  return resp
116
116
 
117
+ def put(self, url, **kwargs):
118
+ if self.access_token is None:
119
+ self.refresh_access_token()
120
+ headers = kwargs.pop("headers", {})
121
+ headers.update({"Authorization": "Bearer %s" % self.access_token})
122
+ resp = self.session.put(url,
123
+ headers=headers,
124
+ timeout=None,
125
+ **kwargs)
126
+ if resp.status_code == 401:
127
+ self.refresh_access_token()
128
+ return self.put(url,
129
+ headers=headers,
130
+ **kwargs)
131
+ if resp.status_code >= 400:
132
+ raise RuntimeError(resp.json()['message'] if resp.headers.get("Content-Type") == "application/json" else "Something went wrong.")
133
+ return resp
134
+
117
135
  def post(self, url,
118
136
  data=None,
119
137
  json=None,
@@ -144,6 +162,11 @@ class MostClient(object):
144
162
  files={"text": text})
145
163
  return self.retort.load(resp.json(), Text)
146
164
 
165
+ def upload_dialog(self, dialog: Dialog) -> DialogResult:
166
+ resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/upload_dialog",
167
+ json={"dialog": dialog})
168
+ return self.retort.load(resp.json(), DialogResult)
169
+
147
170
  def upload_audio(self, audio_path) -> Audio:
148
171
  with open(audio_path, 'rb') as f:
149
172
  resp = self.post(f"https://api.the-most.ai/api/external/{self.client_id}/upload",
@@ -302,6 +325,17 @@ class MostClient(object):
302
325
  resp = self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/dialog")
303
326
  return self.retort.load(resp.json(), DialogResult)
304
327
 
328
+ def update_dialog(self, audio_id, dialog: Dialog) -> DialogResult:
329
+ if not is_valid_id(self.model_id):
330
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
331
+
332
+ if not is_valid_id(audio_id):
333
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
334
+
335
+ resp = self.put(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/dialog",
336
+ json={"dialog": dialog.to_dict()})
337
+ return self.retort.load(resp.json(), DialogResult)
338
+
305
339
  def export(self, audio_ids: List[str],
306
340
  aggregated_by: Optional[str] = None,
307
341
  aggregation_title: Optional[str] = None) -> str:
@@ -18,7 +18,7 @@ from most.types import (
18
18
  Script,
19
19
  StoredAudioData,
20
20
  Text,
21
- is_valid_id, SearchParams, ScriptScoreMapping,
21
+ is_valid_id, SearchParams, ScriptScoreMapping, Dialog,
22
22
  )
23
23
 
24
24
 
@@ -122,6 +122,24 @@ class AsyncMostClient(object):
122
122
  "Content-Type") == "application/json" else "Something went wrong.")
123
123
  return resp
124
124
 
125
+ async def put(self, url, **kwargs):
126
+ if self.access_token is None:
127
+ await self.refresh_access_token()
128
+ headers = kwargs.pop("headers", {})
129
+ headers.update({"Authorization": "Bearer %s" % self.access_token})
130
+ resp = await self.session.put(url,
131
+ headers=headers,
132
+ timeout=None,
133
+ **kwargs)
134
+ if resp.status_code == 401:
135
+ await self.refresh_access_token()
136
+ return await self.put(url,
137
+ headers=headers,
138
+ **kwargs)
139
+ if resp.status_code >= 400:
140
+ raise RuntimeError(resp.json()['message'] if resp.headers.get("Content-Type") == "application/json" else "Something went wrong.")
141
+ return resp
142
+
125
143
  async def post(self, url,
126
144
  data=None,
127
145
  json=None,
@@ -170,6 +188,11 @@ class AsyncMostClient(object):
170
188
  json={"text": text})
171
189
  return self.retort.load(resp.json(), Text)
172
190
 
191
+ async def upload_dialog(self, dialog: Dialog) -> DialogResult:
192
+ resp = await self.post(f"https://api.the-most.ai/api/external/{self.client_id}/upload_dialog",
193
+ json={"dialog": dialog})
194
+ return self.retort.load(resp.json(), DialogResult)
195
+
173
196
  async def upload_audio_url(self, audio_url) -> Audio:
174
197
  resp = await self.post(f"https://api.the-most.ai/api/external/{self.client_id}/upload_url",
175
198
  json={"audio_url": audio_url})
@@ -311,6 +334,17 @@ class AsyncMostClient(object):
311
334
  resp = await self.get(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/dialog")
312
335
  return self.retort.load(resp.json(), DialogResult)
313
336
 
337
+ async def update_dialog(self, audio_id, dialog: Dialog) -> DialogResult:
338
+ if not is_valid_id(self.model_id):
339
+ raise RuntimeError("Please choose valid model to apply. [try list_models()]")
340
+
341
+ if not is_valid_id(audio_id):
342
+ raise RuntimeError("Please use valid audio_id. [try audio.id from list_audios()]")
343
+
344
+ resp = await self.put(f"https://api.the-most.ai/api/external/{self.client_id}/audio/{audio_id}/model/{self.model_id}/dialog",
345
+ json={"dialog": dialog.to_dict()})
346
+ return self.retort.load(resp.json(), DialogResult)
347
+
314
348
  async def export(self, audio_ids: List[str],
315
349
  aggregated_by: Optional[str] = None,
316
350
  aggregation_title: Optional[str] = None) -> str:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: most-client
3
- Version: 1.0.22
3
+ Version: 1.0.24
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
@@ -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.22',
11
+ version='1.0.24',
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
File without changes
File without changes