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/cli.py CHANGED
@@ -1,13 +1,16 @@
1
1
  #!/usr/bin/env python
2
2
  import argparse
3
+ import json
3
4
  import sys
4
5
  import time
6
+ import os
5
7
  from http import HTTPStatus
6
8
 
7
9
  import dashscope
8
10
  from dashscope.aigc import Generation
9
11
  from dashscope.common.constants import (DeploymentStatus, FilePurpose,
10
12
  TaskStatus)
13
+ from dashscope.utils.oss_utils import OssUtils
11
14
 
12
15
 
13
16
  def print_failed_message(rsp):
@@ -44,7 +47,10 @@ class FineTunes:
44
47
  params['learning_rate'] = args.learning_rate
45
48
  if args.prompt_loss is not None:
46
49
  params['prompt_loss'] = args.prompt_loss
47
- rsp = dashscope.FineTune.call(
50
+ if args.params:
51
+ params.update(args.params)
52
+
53
+ rsp = dashscope.FineTunes.call(
48
54
  model=args.model,
49
55
  training_file_ids=args.training_file_ids,
50
56
  validation_file_ids=args.validation_file_ids,
@@ -61,7 +67,7 @@ class FineTunes:
61
67
  def wait(cls, job_id):
62
68
  try:
63
69
  while True:
64
- rsp = dashscope.FineTune.get(job_id)
70
+ rsp = dashscope.FineTunes.get(job_id)
65
71
  if rsp.status_code == HTTPStatus.OK:
66
72
  if rsp.output['status'] == TaskStatus.FAILED:
67
73
  print('Fine-tune FAILED!')
@@ -90,7 +96,7 @@ class FineTunes:
90
96
 
91
97
  @classmethod
92
98
  def get(cls, args):
93
- rsp = dashscope.FineTune.get(args.job)
99
+ rsp = dashscope.FineTunes.get(args.job)
94
100
  if rsp.status_code == HTTPStatus.OK:
95
101
  if rsp.output['status'] == TaskStatus.FAILED:
96
102
  print('Fine-tune failed!')
@@ -106,8 +112,8 @@ class FineTunes:
106
112
 
107
113
  @classmethod
108
114
  def list(cls, args):
109
- rsp = dashscope.FineTune.list(page=args.start_page,
110
- page_size=args.page_size)
115
+ rsp = dashscope.FineTunes.list(page=args.start_page,
116
+ page_size=args.page_size)
111
117
  if rsp.status_code == HTTPStatus.OK:
112
118
  if rsp.output is not None:
113
119
  for job in rsp.output['jobs']:
@@ -128,7 +134,7 @@ class FineTunes:
128
134
  @classmethod
129
135
  def stream_events(cls, job_id):
130
136
  # check job status if job is completed, get log.
131
- rsp = dashscope.FineTune.get(job_id)
137
+ rsp = dashscope.FineTunes.get(job_id)
132
138
  if rsp.status_code == HTTPStatus.OK:
133
139
  if rsp.output['status'] in [
134
140
  TaskStatus.FAILED, TaskStatus.CANCELED,
@@ -143,7 +149,7 @@ class FineTunes:
143
149
  return
144
150
  # start streaming events.
145
151
  try:
146
- stream_events = dashscope.FineTune.stream_events(job_id)
152
+ stream_events = dashscope.FineTunes.stream_events(job_id)
147
153
  for rsp in stream_events:
148
154
  if rsp.status_code == HTTPStatus.OK:
149
155
  print(rsp.output)
@@ -163,7 +169,7 @@ class FineTunes:
163
169
  start = 1
164
170
  n_line = 1000 # 1000 line per request
165
171
  while True:
166
- rsp = dashscope.FineTune.logs(job_id, start, n_line)
172
+ rsp = dashscope.FineTunes.logs(job_id, offset=start, line=n_line)
167
173
  if rsp.status_code == HTTPStatus.OK:
168
174
  for line in rsp.output['logs']:
169
175
  print(line)
@@ -176,7 +182,7 @@ class FineTunes:
176
182
 
177
183
  @classmethod
178
184
  def cancel(cls, args):
179
- rsp = dashscope.FineTune.cancel(args.job)
185
+ rsp = dashscope.FineTunes.cancel(args.job)
180
186
  if rsp.status_code == HTTPStatus.OK:
181
187
  print('Cancel fine-tune job: %s success!')
182
188
  else:
@@ -184,19 +190,49 @@ class FineTunes:
184
190
 
185
191
  @classmethod
186
192
  def delete(cls, args):
187
- rsp = dashscope.FineTune.delete(args.job)
193
+ rsp = dashscope.FineTunes.delete(args.job)
188
194
  if rsp.status_code == HTTPStatus.OK:
189
195
  print('fine_tune job: %s delete success' % args.job)
190
196
  else:
191
197
  print_failed_message(rsp)
192
198
 
199
+ class Oss:
200
+ @classmethod
201
+ def upload(cls, args):
202
+ print('Start oss.upload: model=%s, file=%s, api_key=%s' % (args.model, args.file, args.api_key))
203
+ if not args.file or not args.model:
204
+ print('Please specify the model and file path')
205
+ return
206
+
207
+ file_path = os.path.expanduser(args.file)
208
+ if not os.path.exists(file_path):
209
+ print('File %s does not exist' % file_path)
210
+ return
211
+
212
+ api_key = os.environ.get('DASHSCOPE_API_KEY', args.api_key)
213
+ if not api_key:
214
+ print('Please set your DashScope API key as environment variable '
215
+ 'DASHSCOPE_API_KEY or pass it as argument by -k/--api_key')
216
+ return
217
+
218
+ oss_url, _ = OssUtils.upload(model=args.model,
219
+ file_path=file_path,
220
+ api_key=api_key,
221
+ base_address=args.base_url)
222
+
223
+ if not oss_url:
224
+ print('Failed to upload file: %s' % file_path)
225
+ return
226
+
227
+ print('Uploaded oss url: %s' % oss_url)
193
228
 
194
229
  class Files:
195
230
  @classmethod
196
231
  def upload(cls, args):
197
- rsp = dashscope.File.upload(file_path=args.file,
198
- purpose=args.purpose,
199
- description=args.description)
232
+ rsp = dashscope.Files.upload(file_path=args.file,
233
+ purpose=args.purpose,
234
+ description=args.description,
235
+ base_address=args.base_url)
200
236
  print(rsp)
201
237
  if rsp.status_code == HTTPStatus.OK:
202
238
  print('Upload success, file id: %s' %
@@ -206,32 +242,31 @@ class Files:
206
242
 
207
243
  @classmethod
208
244
  def get(cls, args):
209
- rsp = dashscope.File.get(file_id=args.id)
245
+ rsp = dashscope.Files.get(file_id=args.id, base_address=args.base_url)
210
246
  if rsp.status_code == HTTPStatus.OK:
211
- print('file_id: %s, name: %s, description: %s' %
212
- (rsp.output['file_id'], rsp.output['name'],
213
- rsp.output['description']))
247
+ if rsp.output:
248
+ print('file info:\n%s' % json.dumps(rsp.output, ensure_ascii=False, indent=4))
249
+ else:
250
+ print('There is no uploaded file.')
214
251
  else:
215
252
  print_failed_message(rsp)
216
253
 
217
254
  @classmethod
218
255
  def list(cls, args):
219
- rsp = dashscope.File.list(page=args.start_page,
220
- page_size=args.page_size)
256
+ rsp = dashscope.Files.list(page=args.start_page,
257
+ page_size=args.page_size,
258
+ base_address=args.base_url)
221
259
  if rsp.status_code == HTTPStatus.OK:
222
- if rsp.output is not None:
223
- for f in rsp.output['files']:
224
- print('file_id: %s, name: %s, description: %s, time: %s' %
225
- (f['file_id'], f['name'], f['description'],
226
- f['gmt_create']))
260
+ if rsp.output:
261
+ print('file list info:\n%s' % json.dumps(rsp.output, ensure_ascii=False, indent=4))
227
262
  else:
228
- print('There is no uploaded file.')
263
+ print('There is no uploaded files.')
229
264
  else:
230
265
  print_failed_message(rsp)
231
266
 
232
267
  @classmethod
233
268
  def delete(cls, args):
234
- rsp = dashscope.File.delete(args.id)
269
+ rsp = dashscope.Files.delete(args.id, base_address=args.base_url)
235
270
  if rsp.status_code == HTTPStatus.OK:
236
271
  print('Delete success')
237
272
  else:
@@ -241,15 +276,15 @@ class Files:
241
276
  class Deployments:
242
277
  @classmethod
243
278
  def call(cls, args):
244
- rsp = dashscope.Deployment.call(model=args.model,
245
- capacity=args.capacity,
246
- suffix=args.suffix)
279
+ rsp = dashscope.Deployments.call(model=args.model,
280
+ capacity=args.capacity,
281
+ suffix=args.suffix)
247
282
  if rsp.status_code == HTTPStatus.OK:
248
283
  deployed_model = rsp.output['deployed_model']
249
284
  print('Create model: %s deployment' % deployed_model)
250
285
  try:
251
286
  while True: # wait for deployment ok.
252
- status = dashscope.Deployment.get(deployed_model)
287
+ status = dashscope.Deployments.get(deployed_model)
253
288
  if status.status_code == HTTPStatus.OK:
254
289
  if status.output['status'] in [
255
290
  DeploymentStatus.PENDING,
@@ -273,7 +308,7 @@ class Deployments:
273
308
 
274
309
  @classmethod
275
310
  def get(cls, args):
276
- rsp = dashscope.Deployment.get(args.deploy)
311
+ rsp = dashscope.Deployments.get(args.deploy)
277
312
  if rsp.status_code == HTTPStatus.OK:
278
313
  print('Deployed model: %s capacity: %s status: %s' %
279
314
  (rsp.output['deployed_model'], rsp.output['capacity'],
@@ -283,11 +318,12 @@ class Deployments:
283
318
 
284
319
  @classmethod
285
320
  def list(cls, args):
286
- rsp = dashscope.Deployment.list(page_no=args.start_page,
287
- page_size=args.page_size)
321
+ rsp = dashscope.Deployments.list(page_no=args.start_page,
322
+ page_size=args.page_size)
288
323
  if rsp.status_code == HTTPStatus.OK:
289
324
  if rsp.output is not None:
290
- if 'deployments' not in rsp.output:
325
+ if 'deployments' not in rsp.output or len(
326
+ rsp.output['deployments']) == 0:
291
327
  print('There is no deployed model!')
292
328
  return
293
329
  for deployment in rsp.output['deployments']:
@@ -301,7 +337,7 @@ class Deployments:
301
337
 
302
338
  @classmethod
303
339
  def update(cls, args):
304
- rsp = dashscope.Deployment.update(args.deployed_model, args.version)
340
+ rsp = dashscope.Deployments.update(args.deployed_model, args.version)
305
341
  if rsp.status_code == HTTPStatus.OK:
306
342
  if rsp.output is not None:
307
343
  if 'deployments' not in rsp.output:
@@ -318,7 +354,7 @@ class Deployments:
318
354
 
319
355
  @classmethod
320
356
  def scale(cls, args):
321
- rsp = dashscope.Deployment.scale(args.deployed_model, args.capacity)
357
+ rsp = dashscope.Deployments.scale(args.deployed_model, args.capacity)
322
358
  if rsp.status_code == HTTPStatus.OK:
323
359
  if rsp.output is not None:
324
360
  print('Deployed_model: %s, model: %s, status: %s' %
@@ -331,13 +367,28 @@ class Deployments:
331
367
 
332
368
  @classmethod
333
369
  def delete(cls, args):
334
- rsp = dashscope.Deployment.delete(args.deploy)
370
+ rsp = dashscope.Deployments.delete(args.deploy)
335
371
  if rsp.status_code == HTTPStatus.OK:
336
372
  print('Deployed model: %s delete success' % args.deploy)
337
373
  else:
338
374
  print_failed_message(rsp)
339
375
 
340
376
 
377
+ # from: https://gist.github.com/vadimkantorov/37518ff88808af840884355c845049ea
378
+ class ParseKVAction(argparse.Action):
379
+ def __call__(self, parser, namespace, values, option_string=None):
380
+ setattr(namespace, self.dest, dict())
381
+ for each in values:
382
+ try:
383
+ key, value = each.split('=')
384
+ getattr(namespace, self.dest)[key] = value
385
+ except ValueError as ex:
386
+ message = '\nTraceback: {}'.format(ex)
387
+ message += "\nError on '{}' || It should be 'key=value'".format(
388
+ each)
389
+ raise argparse.ArgumentError(self, str(message))
390
+
391
+
341
392
  def main():
342
393
  parser = argparse.ArgumentParser(
343
394
  prog='dashscope', description='dashscope command line tools.')
@@ -409,6 +460,13 @@ def main():
409
460
  type=float,
410
461
  required=False,
411
462
  help='The fine-tune prompt loss.')
463
+ fine_tune_call.add_argument(
464
+ '--hyper_parameters',
465
+ nargs='+',
466
+ dest='params',
467
+ action=ParseKVAction,
468
+ help='Extra hyper parameters accepts by key1=value1 key2=value2',
469
+ metavar='KEY1=VALUE1')
412
470
  fine_tune_call.set_defaults(func=FineTunes.call)
413
471
  fine_tune_get = sub_parsers.add_parser('fine_tunes.get')
414
472
  fine_tune_get.add_argument('-j',
@@ -451,6 +509,37 @@ def main():
451
509
  help='The fine-tune job id.')
452
510
  fine_tune_cancel.set_defaults(func=FineTunes.cancel)
453
511
 
512
+ oss_upload = sub_parsers.add_parser('oss.upload')
513
+ oss_upload.add_argument(
514
+ '-f',
515
+ '--file',
516
+ type=str,
517
+ required=True,
518
+ help='The file path to upload',
519
+ )
520
+ oss_upload.add_argument(
521
+ '-m',
522
+ '--model',
523
+ type=str,
524
+ required=True,
525
+ help='The model name',
526
+ )
527
+ oss_upload.add_argument(
528
+ '-k',
529
+ '--api_key',
530
+ type=str,
531
+ required=False,
532
+ help='The dashscope api key',
533
+ )
534
+ oss_upload.add_argument(
535
+ '-u',
536
+ '--base_url',
537
+ type=str,
538
+ help='The base url.',
539
+ required=False,
540
+ )
541
+ oss_upload.set_defaults(func=Oss.upload)
542
+
454
543
  file_upload = sub_parsers.add_parser('files.upload')
455
544
  file_upload.add_argument(
456
545
  '-f',
@@ -475,21 +564,45 @@ def main():
475
564
  help='The file description.',
476
565
  required=False,
477
566
  )
567
+ file_upload.add_argument(
568
+ '-u',
569
+ '--base_url',
570
+ type=str,
571
+ help='The base url.',
572
+ required=False,
573
+ )
478
574
  file_upload.set_defaults(func=Files.upload)
575
+
479
576
  file_get = sub_parsers.add_parser('files.get')
480
577
  file_get.add_argument('-i',
481
578
  '--id',
482
579
  type=str,
483
580
  required=True,
484
581
  help='The file ID')
582
+ file_get.add_argument(
583
+ '-u',
584
+ '--base_url',
585
+ type=str,
586
+ help='The base url.',
587
+ required=False,
588
+ )
485
589
  file_get.set_defaults(func=Files.get)
590
+
486
591
  file_delete = sub_parsers.add_parser('files.delete')
487
592
  file_delete.add_argument('-i',
488
593
  '--id',
489
594
  type=str,
490
595
  required=True,
491
596
  help='The files ID')
597
+ file_delete.add_argument(
598
+ '-u',
599
+ '--base_url',
600
+ type=str,
601
+ help='The base url.',
602
+ required=False,
603
+ )
492
604
  file_delete.set_defaults(func=Files.delete)
605
+
493
606
  file_list = sub_parsers.add_parser('files.list')
494
607
  file_list.add_argument('-s',
495
608
  '--start_page',
@@ -501,6 +614,13 @@ def main():
501
614
  type=int,
502
615
  default=10,
503
616
  help='The page size, default 10')
617
+ file_list.add_argument(
618
+ '-u',
619
+ '--base_url',
620
+ type=str,
621
+ help='The base url.',
622
+ required=False,
623
+ )
504
624
  file_list.set_defaults(func=Files.list)
505
625
 
506
626
  deployments_call = sub_parsers.add_parser('deployments.call')