dashscope 1.8.0__py3-none-any.whl → 1.25.6__py3-none-any.whl

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.
Files changed (110) hide show
  1. dashscope/__init__.py +61 -14
  2. dashscope/aigc/__init__.py +10 -3
  3. dashscope/aigc/chat_completion.py +282 -0
  4. dashscope/aigc/code_generation.py +145 -0
  5. dashscope/aigc/conversation.py +71 -12
  6. dashscope/aigc/generation.py +288 -16
  7. dashscope/aigc/image_synthesis.py +473 -31
  8. dashscope/aigc/multimodal_conversation.py +299 -14
  9. dashscope/aigc/video_synthesis.py +610 -0
  10. dashscope/api_entities/aiohttp_request.py +8 -5
  11. dashscope/api_entities/api_request_data.py +4 -2
  12. dashscope/api_entities/api_request_factory.py +68 -20
  13. dashscope/api_entities/base_request.py +20 -3
  14. dashscope/api_entities/chat_completion_types.py +344 -0
  15. dashscope/api_entities/dashscope_response.py +243 -15
  16. dashscope/api_entities/encryption.py +179 -0
  17. dashscope/api_entities/http_request.py +216 -62
  18. dashscope/api_entities/websocket_request.py +43 -34
  19. dashscope/app/__init__.py +5 -0
  20. dashscope/app/application.py +203 -0
  21. dashscope/app/application_response.py +246 -0
  22. dashscope/assistants/__init__.py +16 -0
  23. dashscope/assistants/assistant_types.py +175 -0
  24. dashscope/assistants/assistants.py +311 -0
  25. dashscope/assistants/files.py +197 -0
  26. dashscope/audio/__init__.py +4 -2
  27. dashscope/audio/asr/__init__.py +17 -1
  28. dashscope/audio/asr/asr_phrase_manager.py +203 -0
  29. dashscope/audio/asr/recognition.py +167 -27
  30. dashscope/audio/asr/transcription.py +107 -14
  31. dashscope/audio/asr/translation_recognizer.py +1006 -0
  32. dashscope/audio/asr/vocabulary.py +177 -0
  33. dashscope/audio/qwen_asr/__init__.py +7 -0
  34. dashscope/audio/qwen_asr/qwen_transcription.py +189 -0
  35. dashscope/audio/qwen_omni/__init__.py +11 -0
  36. dashscope/audio/qwen_omni/omni_realtime.py +524 -0
  37. dashscope/audio/qwen_tts/__init__.py +5 -0
  38. dashscope/audio/qwen_tts/speech_synthesizer.py +77 -0
  39. dashscope/audio/qwen_tts_realtime/__init__.py +10 -0
  40. dashscope/audio/qwen_tts_realtime/qwen_tts_realtime.py +355 -0
  41. dashscope/audio/tts/__init__.py +2 -0
  42. dashscope/audio/tts/speech_synthesizer.py +5 -0
  43. dashscope/audio/tts_v2/__init__.py +12 -0
  44. dashscope/audio/tts_v2/enrollment.py +179 -0
  45. dashscope/audio/tts_v2/speech_synthesizer.py +886 -0
  46. dashscope/cli.py +157 -37
  47. dashscope/client/base_api.py +652 -87
  48. dashscope/common/api_key.py +2 -0
  49. dashscope/common/base_type.py +135 -0
  50. dashscope/common/constants.py +13 -16
  51. dashscope/common/env.py +2 -0
  52. dashscope/common/error.py +58 -22
  53. dashscope/common/logging.py +2 -0
  54. dashscope/common/message_manager.py +2 -0
  55. dashscope/common/utils.py +276 -46
  56. dashscope/customize/__init__.py +0 -0
  57. dashscope/customize/customize_types.py +192 -0
  58. dashscope/customize/deployments.py +146 -0
  59. dashscope/customize/finetunes.py +234 -0
  60. dashscope/embeddings/__init__.py +5 -1
  61. dashscope/embeddings/batch_text_embedding.py +208 -0
  62. dashscope/embeddings/batch_text_embedding_response.py +65 -0
  63. dashscope/embeddings/multimodal_embedding.py +118 -10
  64. dashscope/embeddings/text_embedding.py +13 -1
  65. dashscope/{file.py → files.py} +19 -4
  66. dashscope/io/input_output.py +2 -0
  67. dashscope/model.py +11 -2
  68. dashscope/models.py +43 -0
  69. dashscope/multimodal/__init__.py +20 -0
  70. dashscope/multimodal/dialog_state.py +56 -0
  71. dashscope/multimodal/multimodal_constants.py +28 -0
  72. dashscope/multimodal/multimodal_dialog.py +648 -0
  73. dashscope/multimodal/multimodal_request_params.py +313 -0
  74. dashscope/multimodal/tingwu/__init__.py +10 -0
  75. dashscope/multimodal/tingwu/tingwu.py +80 -0
  76. dashscope/multimodal/tingwu/tingwu_realtime.py +579 -0
  77. dashscope/nlp/__init__.py +0 -0
  78. dashscope/nlp/understanding.py +64 -0
  79. dashscope/protocol/websocket.py +3 -0
  80. dashscope/rerank/__init__.py +0 -0
  81. dashscope/rerank/text_rerank.py +69 -0
  82. dashscope/resources/qwen.tiktoken +151643 -0
  83. dashscope/threads/__init__.py +26 -0
  84. dashscope/threads/messages/__init__.py +0 -0
  85. dashscope/threads/messages/files.py +113 -0
  86. dashscope/threads/messages/messages.py +220 -0
  87. dashscope/threads/runs/__init__.py +0 -0
  88. dashscope/threads/runs/runs.py +501 -0
  89. dashscope/threads/runs/steps.py +112 -0
  90. dashscope/threads/thread_types.py +665 -0
  91. dashscope/threads/threads.py +212 -0
  92. dashscope/tokenizers/__init__.py +7 -0
  93. dashscope/tokenizers/qwen_tokenizer.py +111 -0
  94. dashscope/tokenizers/tokenization.py +125 -0
  95. dashscope/tokenizers/tokenizer.py +45 -0
  96. dashscope/tokenizers/tokenizer_base.py +32 -0
  97. dashscope/utils/__init__.py +0 -0
  98. dashscope/utils/message_utils.py +838 -0
  99. dashscope/utils/oss_utils.py +243 -0
  100. dashscope/utils/param_utils.py +29 -0
  101. dashscope/version.py +3 -1
  102. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/METADATA +53 -50
  103. dashscope-1.25.6.dist-info/RECORD +112 -0
  104. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/WHEEL +1 -1
  105. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/entry_points.txt +0 -1
  106. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info/licenses}/LICENSE +2 -4
  107. dashscope/deployment.py +0 -129
  108. dashscope/finetune.py +0 -149
  109. dashscope-1.8.0.dist-info/RECORD +0 -49
  110. {dashscope-1.8.0.dist-info → dashscope-1.25.6.dist-info}/top_level.txt +0 -0
dashscope/common/utils.py CHANGED
@@ -1,7 +1,12 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import asyncio
2
4
  import json
3
5
  import os
4
6
  import platform
7
+ import queue
8
+ import threading
9
+ from dataclasses import dataclass
5
10
  from http import HTTPStatus
6
11
  from typing import Dict
7
12
  from urllib.parse import urlparse
@@ -11,11 +16,13 @@ import requests
11
16
 
12
17
  from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
13
18
  from dashscope.common.api_key import get_default_api_key
19
+ from dashscope.common.constants import SSE_CONTENT_TYPE
20
+ from dashscope.common.logging import logger
14
21
  from dashscope.version import __version__
15
22
 
16
23
 
17
24
  def is_validate_fine_tune_file(file_path):
18
- with open(file_path) as f:
25
+ with open(file_path, encoding='utf-8') as f:
19
26
  for line in f:
20
27
  try:
21
28
  json.loads(line)
@@ -72,7 +79,8 @@ def is_url(url: str):
72
79
  return False
73
80
 
74
81
 
75
- def iter_over_async(ait, loop):
82
+ def iter_over_async(ait):
83
+ loop = asyncio.get_event_loop_policy().new_event_loop()
76
84
  ait = ait.__aiter__()
77
85
 
78
86
  async def get_next():
@@ -82,20 +90,54 @@ def iter_over_async(ait, loop):
82
90
  except StopAsyncIteration:
83
91
  return True, None
84
92
 
93
+ def iter_thread(loop, message_queue):
94
+ while True:
95
+ try:
96
+ done, obj = loop.run_until_complete(get_next())
97
+ if done:
98
+ message_queue.put((True, None, None))
99
+ break
100
+ message_queue.put((False, None, obj))
101
+ except BaseException as e: # noqa E722
102
+ logger.exception(e)
103
+ message_queue.put((True, e, None))
104
+ break
105
+
106
+ message_queue = queue.Queue()
107
+ x = threading.Thread(target=iter_thread,
108
+ args=(loop, message_queue),
109
+ name='iter_async_thread')
110
+ x.start()
85
111
  while True:
86
- done, obj = loop.run_until_complete(get_next())
87
- if done:
112
+ finished, error, obj = message_queue.get()
113
+ if finished:
114
+ if error is not None:
115
+ yield DashScopeAPIResponse(
116
+ -1,
117
+ '',
118
+ 'Unknown',
119
+ message='Error type: %s, message: %s' %
120
+ (type(error), error))
88
121
  break
89
- yield obj
122
+ else:
123
+ yield obj
90
124
 
91
125
 
92
126
  def async_to_sync(async_generator):
93
- loop = asyncio.get_event_loop_policy().new_event_loop()
94
- asyncio.set_event_loop(loop)
95
- for message in iter_over_async(async_generator, loop):
127
+ for message in iter_over_async(async_generator):
96
128
  yield message
97
129
 
98
130
 
131
+ def get_user_agent():
132
+ ua = 'dashscope/%s; python/%s; platform/%s; processor/%s' % (
133
+ __version__,
134
+ platform.python_version(),
135
+ platform.platform(),
136
+ platform.processor(),
137
+ )
138
+ return ua
139
+
140
+
99
141
  def default_headers(api_key: str = None) -> Dict[str, str]:
100
142
  ua = 'dashscope/%s; python/%s; platform/%s; processor/%s' % (
101
143
  __version__,
@@ -116,7 +158,8 @@ def join_url(base_url, *args):
116
158
  base_url = base_url + '/'
117
159
  url = base_url
118
160
  for arg in args:
119
- url += arg + '/'
161
+ if arg is not None:
162
+ url += arg + '/'
120
163
  return url[:-1]
121
164
 
122
165
 
@@ -151,58 +194,245 @@ async def _handle_aiohttp_response(response: aiohttp.ClientResponse):
151
194
  message=msg)
152
195
 
153
196
 
154
- def _handle_http_failed_response(
155
- response: requests.Response) -> DashScopeAPIResponse:
156
- msg = ''
197
+ @dataclass
198
+ class SSEEvent:
199
+ id: str
200
+ eventType: str
201
+ data: str
202
+
203
+ def __init__(self, id: str, type: str, data: str):
204
+ self.id = id
205
+ self.eventType = type
206
+ self.data = data
207
+
208
+
209
+ def _handle_stream(response: requests.Response):
210
+ # TODO define done message.
211
+ is_error = False
212
+ status_code = HTTPStatus.BAD_REQUEST
213
+ event = SSEEvent(None, None, None)
214
+ eventType = None
215
+ for line in response.iter_lines():
216
+ if line:
217
+ line = line.decode('utf8')
218
+ line = line.rstrip('\n').rstrip('\r')
219
+ if line.startswith('id:'):
220
+ id = line[len('id:'):]
221
+ event.id = id.strip()
222
+ elif line.startswith('event:'):
223
+ eventType = line[len('event:'):]
224
+ event.eventType = eventType.strip()
225
+ if eventType == 'error':
226
+ is_error = True
227
+ elif line.startswith('status:'):
228
+ status_code = line[len('status:'):]
229
+ status_code = int(status_code.strip())
230
+ elif line.startswith('data:'):
231
+ line = line[len('data:'):]
232
+ event.data = line.strip()
233
+ if eventType is not None and eventType == 'done':
234
+ continue
235
+ yield (is_error, status_code, event)
236
+ if is_error:
237
+ break
238
+ else:
239
+ continue # ignore heartbeat...
240
+
241
+
242
+ def _handle_error_message(error, status_code, flattened_output):
157
243
  code = None
244
+ msg = ''
245
+ request_id = ''
246
+ if flattened_output:
247
+ error['status_code'] = status_code
248
+ return error
249
+ if 'message' in error:
250
+ msg = error['message']
251
+ if 'msg' in error:
252
+ msg = error['msg']
253
+ if 'code' in error:
254
+ code = error['code']
255
+ if 'request_id' in error:
256
+ request_id = error['request_id']
257
+ return DashScopeAPIResponse(request_id=request_id,
258
+ status_code=status_code,
259
+ code=code,
260
+ message=msg)
261
+
262
+
263
+ def _handle_http_failed_response(
264
+ response: requests.Response,
265
+ flattened_output: bool = False) -> DashScopeAPIResponse:
158
266
  request_id = ''
159
267
  if 'application/json' in response.headers.get('content-type', ''):
160
268
  error = response.json()
161
- if 'message' in error:
162
- msg = error['message']
163
- if 'msg' in error:
164
- msg = error['msg']
165
- if 'code' in error:
166
- code = error['code']
167
- if 'request_id' in error:
168
- request_id = error['request_id']
269
+ return _handle_error_message(error, response.status_code,
270
+ flattened_output)
271
+ elif SSE_CONTENT_TYPE in response.headers.get('content-type', ''):
272
+ msgs = response.content.decode('utf-8').split('\n')
273
+ for msg in msgs:
274
+ if msg.startswith('data:'):
275
+ error = json.loads(msg.replace('data:', '').strip())
276
+ return _handle_error_message(error, response.status_code,
277
+ flattened_output)
169
278
  return DashScopeAPIResponse(request_id=request_id,
170
279
  status_code=response.status_code,
171
- code=code,
172
- message=msg)
280
+ code='Unknown',
281
+ message=msgs)
173
282
  else:
174
283
  msg = response.content.decode('utf-8')
284
+ if flattened_output:
285
+ return {'status_code': response.status_code, 'message': msg}
175
286
  return DashScopeAPIResponse(request_id=request_id,
176
287
  status_code=response.status_code,
177
288
  code='Unknown',
178
289
  message=msg)
179
290
 
180
291
 
181
- def _handle_http_response(response: requests.Response):
292
+ async def _handle_aio_stream(response):
293
+ # TODO define done message.
294
+ is_error = False
295
+ status_code = HTTPStatus.BAD_REQUEST
296
+ async for line in response.content:
297
+ if line:
298
+ line = line.decode('utf8')
299
+ line = line.rstrip('\n').rstrip('\r')
300
+ if line.startswith('event:error'):
301
+ is_error = True
302
+ elif line.startswith('status:'):
303
+ status_code = line[len('status:'):]
304
+ status_code = int(status_code.strip())
305
+ elif line.startswith('data:'):
306
+ line = line[len('data:'):]
307
+ yield (is_error, status_code, line)
308
+ if is_error:
309
+ break
310
+ else:
311
+ continue # ignore heartbeat...
312
+
313
+
314
+ async def _handle_aiohttp_failed_response(
315
+ response: requests.Response,
316
+ flattened_output: bool = False) -> DashScopeAPIResponse:
182
317
  request_id = ''
183
- if response.status_code == HTTPStatus.OK:
184
- output = None
185
- usage = None
186
- code = None
187
- msg = ''
188
- json_content = response.json()
189
- if 'data' in json_content:
190
- output = json_content['data']
191
- if 'code' in json_content:
192
- code = json_content['code']
193
- if 'message' in json_content:
194
- msg = json_content['message']
195
- if 'output' in json_content:
196
- output = json_content['output']
197
- if 'usage' in json_content:
198
- usage = json_content['usage']
199
- if 'request_id' in json_content:
200
- request_id = json_content['request_id']
318
+ if 'application/json' in response.content_type:
319
+ error = await response.json()
320
+ return _handle_error_message(error, response.status, flattened_output)
321
+ elif SSE_CONTENT_TYPE in response.content_type:
322
+ async for _, _, data in _handle_aio_stream(response):
323
+ error = json.loads(data)
324
+ return _handle_error_message(error, response.status, flattened_output)
325
+ else:
326
+ msg = response.content.decode('utf-8')
327
+ if flattened_output:
328
+ return {'status_code': response.status, 'message': msg}
201
329
  return DashScopeAPIResponse(request_id=request_id,
202
- status_code=response.status_code,
203
- code=code,
204
- output=output,
205
- usage=usage,
330
+ status_code=response.status,
331
+ code='Unknown',
206
332
  message=msg)
333
+
334
+
335
+ def _handle_http_response(response: requests.Response,
336
+ flattened_output: bool = False):
337
+ response = _handle_http_stream_response(response, flattened_output)
338
+ _, output = next(response)
339
+ try:
340
+ next(response)
341
+ except StopIteration:
342
+ pass
343
+ return output
344
+
345
+
346
+ def _handle_http_stream_response(response: requests.Response,
347
+ flattened_output: bool = False):
348
+ request_id = ''
349
+ if (response.status_code == HTTPStatus.OK
350
+ and SSE_CONTENT_TYPE in response.headers.get('content-type', '')):
351
+ for is_error, status_code, event in _handle_stream(response):
352
+ if not is_error:
353
+ try:
354
+ output = None
355
+ usage = None
356
+ msg = json.loads(event.data)
357
+ if flattened_output:
358
+ msg['status_code'] = response.status_code
359
+ yield event.eventType, msg
360
+ else:
361
+ logger.debug('Stream message: %s' % msg)
362
+ if not is_error:
363
+ if 'output' in msg:
364
+ output = msg['output']
365
+ if 'usage' in msg:
366
+ usage = msg['usage']
367
+ if 'request_id' in msg:
368
+ request_id = msg['request_id']
369
+ yield event.eventType, DashScopeAPIResponse(
370
+ request_id=request_id,
371
+ status_code=HTTPStatus.OK,
372
+ output=output,
373
+ usage=usage)
374
+ except json.JSONDecodeError as e:
375
+ if flattened_output:
376
+ yield event.eventType, {
377
+ 'status_code': response.status_code,
378
+ 'message': e.message
379
+ }
380
+ else:
381
+ yield event.eventType, DashScopeAPIResponse(
382
+ request_id=request_id,
383
+ status_code=HTTPStatus.BAD_REQUEST,
384
+ output=None,
385
+ code='Unknown',
386
+ message=event.data)
387
+ continue
388
+ else:
389
+ if flattened_output:
390
+ yield event.eventType, {
391
+ 'status_code': status_code,
392
+ 'message': event.data
393
+ }
394
+ else:
395
+ msg = json.loads(event.eventType)
396
+ yield event.eventType, DashScopeAPIResponse(
397
+ request_id=request_id,
398
+ status_code=status_code,
399
+ output=None,
400
+ code=msg['code']
401
+ if 'code' in msg else None, # noqa E501
402
+ message=msg['message']
403
+ if 'message' in msg else None) # noqa E501
404
+ elif response.status_code == HTTPStatus.OK or response.status_code == HTTPStatus.CREATED:
405
+ json_content = response.json()
406
+ if flattened_output:
407
+ json_content['status_code'] = response.status_code
408
+ yield None, json_content
409
+ else:
410
+ output = None
411
+ usage = None
412
+ code = None
413
+ msg = ''
414
+ if 'data' in json_content:
415
+ output = json_content['data']
416
+ if 'code' in json_content:
417
+ code = json_content['code']
418
+ if 'message' in json_content:
419
+ msg = json_content['message']
420
+ if 'output' in json_content:
421
+ output = json_content['output']
422
+ if 'usage' in json_content:
423
+ usage = json_content['usage']
424
+ if 'request_id' in json_content:
425
+ request_id = json_content['request_id']
426
+ json_content.pop('request_id', None)
427
+
428
+ if 'data' not in json_content and 'output' not in json_content:
429
+ output = json_content
430
+
431
+ yield None, DashScopeAPIResponse(request_id=request_id,
432
+ status_code=response.status_code,
433
+ code=code,
434
+ output=output,
435
+ usage=usage,
436
+ message=msg)
207
437
  else:
208
- return _handle_http_failed_response(response)
438
+ yield None, _handle_http_failed_response(response, flattened_output)
File without changes
@@ -0,0 +1,192 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
3
+ from dataclasses import dataclass
4
+ from http import HTTPStatus
5
+ from typing import Dict, List
6
+
7
+ from dashscope.common.base_type import BaseObjectMixin
8
+
9
+ __all__ = ['Deployment', 'FineTune', 'DeploymentList', 'FineTuneList']
10
+
11
+
12
+ @dataclass(init=False)
13
+ class DashScopeBaseList(BaseObjectMixin):
14
+ page_no: int
15
+ page_size: int
16
+ total: int
17
+
18
+ def __init__(self, **kwargs):
19
+ super().__init__(**kwargs)
20
+
21
+
22
+ @dataclass(init=False)
23
+ class DashScopeBase(BaseObjectMixin):
24
+ status_code: int
25
+ request_id: str
26
+ code: str
27
+ message: str
28
+
29
+ def __init__(self, **kwargs):
30
+ super().__init__(**kwargs)
31
+
32
+
33
+ @dataclass(init=False)
34
+ class FineTuneOutput(BaseObjectMixin):
35
+ job_id: str
36
+ job_name: str
37
+ status: str
38
+ model: str
39
+ base_model: str
40
+ finetuned_output: str
41
+ training_file_ids: List[str]
42
+ validation_file_ids: List[str]
43
+ hyper_parameters: Dict
44
+ training_type: str
45
+ create_time: str
46
+ end_time: str
47
+ user_identity: str
48
+ modifier: str
49
+ creator: str
50
+ group: str
51
+ usage: int
52
+
53
+ def __init__(self, **kwargs):
54
+ super().__init__(**kwargs)
55
+
56
+
57
+ @dataclass(init=False)
58
+ class FineTune(DashScopeBase):
59
+ output: FineTuneOutput
60
+ usage: Dict
61
+
62
+ def __init__(self, **kwargs):
63
+ status_code = kwargs.get('status_code', None)
64
+ if status_code == HTTPStatus.OK:
65
+ self.output = FineTuneOutput(**kwargs.pop('output', {}))
66
+ super().__init__(**kwargs)
67
+
68
+
69
+ @dataclass(init=False)
70
+ class FineTuneListOutput(DashScopeBaseList):
71
+ jobs: List[FineTuneOutput]
72
+
73
+ def __init__(self, **kwargs):
74
+ self.jobs = []
75
+ for job in kwargs.pop('jobs', []):
76
+ self.jobs.append(FineTuneOutput(**job))
77
+ super().__init__(**kwargs)
78
+
79
+
80
+ @dataclass(init=False)
81
+ class FineTuneList(DashScopeBase):
82
+ output: FineTuneListOutput
83
+
84
+ def __init__(self, **kwargs):
85
+ status_code = kwargs.get('status_code', None)
86
+ if status_code == HTTPStatus.OK:
87
+ self.output = FineTuneListOutput(**kwargs.pop('output', {}))
88
+ super().__init__(**kwargs)
89
+
90
+
91
+ @dataclass(init=False)
92
+ class CancelDeleteStatus(BaseObjectMixin):
93
+ status: str
94
+
95
+
96
+ @dataclass(init=False)
97
+ class FineTuneCancel(DashScopeBase):
98
+ output: CancelDeleteStatus
99
+
100
+ def __init__(self, **kwargs):
101
+ status_code = kwargs.get('status_code', None)
102
+ if status_code == HTTPStatus.OK:
103
+ self.output = CancelDeleteStatus(**kwargs.pop('output', {}))
104
+ super().__init__(**kwargs)
105
+
106
+
107
+ @dataclass(init=False)
108
+ class FineTuneDelete(DashScopeBase):
109
+ output: CancelDeleteStatus
110
+
111
+ def __init__(self, **kwargs):
112
+ status_code = kwargs.get('status_code', None)
113
+ if status_code == HTTPStatus.OK:
114
+ self.output = CancelDeleteStatus(**kwargs.pop('output', {}))
115
+ super().__init__(**kwargs)
116
+
117
+
118
+ @dataclass(init=False)
119
+ class FineTuneEvent(DashScopeBase):
120
+ output: str
121
+
122
+ def __init__(self, **kwargs):
123
+ status_code = kwargs.get('status_code', None)
124
+ if status_code == HTTPStatus.OK:
125
+ self.output = kwargs.pop('output', {})
126
+ super().__init__(**kwargs)
127
+
128
+
129
+ @dataclass(init=False)
130
+ class DeploymentOutput(BaseObjectMixin):
131
+ deployed_model: str
132
+ gmt_create: str
133
+ gmt_modified: str
134
+ status: str
135
+ model_name: str
136
+ base_model: str
137
+ base_capacity: int
138
+ capacity: int
139
+ ready_capacity: int
140
+ workspace_id: str
141
+ charge_type: str
142
+ modifier: str
143
+ creator: str
144
+
145
+ def __init__(self, **kwargs):
146
+ super().__init__(**kwargs)
147
+
148
+
149
+ @dataclass(init=False)
150
+ class Deployment(DashScopeBase):
151
+ output: DeploymentOutput
152
+
153
+ def __init__(self, **kwargs):
154
+ output = kwargs.pop('output', {})
155
+ if output:
156
+ self.output = DeploymentOutput(**output)
157
+ else:
158
+ self.output = None
159
+ super().__init__(**kwargs)
160
+
161
+
162
+ @dataclass(init=False)
163
+ class DeploymentListOutput(DashScopeBaseList):
164
+ deployments: List[DeploymentOutput]
165
+
166
+ def __init__(self, **kwargs):
167
+ self.deployments = []
168
+ for job in kwargs.pop('deployments', []):
169
+ self.deployments.append(DeploymentOutput(**job))
170
+ super().__init__(**kwargs)
171
+
172
+
173
+ @dataclass(init=False)
174
+ class DeploymentList(BaseObjectMixin):
175
+ output: DeploymentListOutput
176
+
177
+ def __init__(self, **kwargs):
178
+ status_code = kwargs.get('status_code', None)
179
+ if status_code == HTTPStatus.OK:
180
+ self.output = DeploymentListOutput(**kwargs.pop('output', {}))
181
+ super().__init__(**kwargs)
182
+
183
+
184
+ @dataclass(init=False)
185
+ class DeploymentDelete(DashScopeBase):
186
+ output: CancelDeleteStatus
187
+
188
+ def __init__(self, **kwargs):
189
+ status_code = kwargs.get('status_code', None)
190
+ if status_code == HTTPStatus.OK:
191
+ self.output = CancelDeleteStatus(**kwargs.pop('output', {}))
192
+ super().__init__(**kwargs)