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
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import os
2
4
  from typing import Optional
3
5
 
@@ -0,0 +1,135 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
3
+ import dataclasses
4
+ from dataclasses import dataclass
5
+ from typing import Any, List
6
+
7
+ import dashscope
8
+
9
+
10
+ def get_object_type(name: str):
11
+ dashscope_objects = {
12
+ 'assistant': dashscope.Assistant,
13
+ 'assistant.deleted': dashscope.DeleteResponse,
14
+ 'thread.message': dashscope.ThreadMessage,
15
+ 'thread.run': dashscope.Run,
16
+ 'thread.run.step': dashscope.RunStep,
17
+ 'thread.message.file': dashscope.MessageFile,
18
+ 'assistant.file': dashscope.AssistantFile,
19
+ 'thread': dashscope.Thread,
20
+ }
21
+ return dashscope_objects.get(name, None)
22
+
23
+
24
+ @dataclass(init=False)
25
+ class BaseObjectMixin(object):
26
+ __slots__ = ()
27
+
28
+ def __init__(self, **kwargs):
29
+ field_type_map = self._get_fields_type()
30
+ for k, v in kwargs.items():
31
+ field = field_type_map.get(k, None)
32
+ if field and v is not None:
33
+ if dataclasses.is_dataclass(field.type): # process dataclasses
34
+ self.__setattr__(k, field.type(**v))
35
+ continue
36
+
37
+ if isinstance(v, dict):
38
+ object_name = v.get('object', None)
39
+ if object_name:
40
+ object_type = get_object_type(object_name)
41
+ if object_type:
42
+ self.__setattr__(k, object_type(**v))
43
+ else:
44
+ self.__setattr__(k, v)
45
+ else:
46
+ self.__setattr__(k, v)
47
+ elif isinstance(v, list):
48
+ obj_list = self._init_list_element_recursive(field, v)
49
+ self.__setattr__(k, obj_list)
50
+ else:
51
+ self.__setattr__(k, v)
52
+
53
+ def _init_list_element_recursive(self, field, items: list) -> List[Any]:
54
+ obj_list = []
55
+ for item in items:
56
+ if field:
57
+ # current only support List[cls_name],
58
+ # not support List[cls_nam1, cls_name2]
59
+ element_type = field.type.__args__[0]
60
+ if dataclasses.is_dataclass(element_type):
61
+ obj_list.append(element_type(**item))
62
+ continue
63
+
64
+ if isinstance(item, dict):
65
+ object_name = item.get('object', None)
66
+ if object_name:
67
+ object_type = get_object_type(object_name)
68
+ if object_type:
69
+ obj_list.append(object_type(**item))
70
+ else:
71
+ obj_list.append(item)
72
+ else:
73
+ obj_list.append(item)
74
+ elif isinstance(item, list):
75
+ obj_list.append(self._init_list_element_recursive(item))
76
+ else:
77
+ obj_list.append(item)
78
+ return obj_list
79
+
80
+ def _get_fields_type(self):
81
+ field_type_map = {}
82
+ if dataclasses.is_dataclass(self):
83
+ for field in dataclasses.fields(self):
84
+ field_type_map[field.name] = field
85
+ return field_type_map
86
+
87
+ def __setitem__(self, __key: Any, __value: Any) -> None:
88
+ return self.__setattr__(__key, __value)
89
+
90
+ def __getitem__(self, __key: Any) -> Any:
91
+ return self.__getattribute__(__key)
92
+
93
+ def __contains__(self, item):
94
+ return hasattr(self, item)
95
+
96
+ def __delitem__(self, key):
97
+ self.__delattr__(key)
98
+
99
+ def _recursive_to_str__(self, input_object) -> Any:
100
+ if isinstance(input_object, list):
101
+ output_object = []
102
+ for item in input_object:
103
+ output_object.append(self._recursive_to_str__(item))
104
+ return output_object
105
+ elif dataclasses.is_dataclass(input_object):
106
+ output_object = {}
107
+ for field in dataclasses.fields(input_object):
108
+ if hasattr(input_object, field.name):
109
+ output_object[field.name] = self._recursive_to_str__(
110
+ getattr(input_object, field.name))
111
+ return output_object
112
+ else:
113
+ return input_object
114
+
115
+ def __str__(self) -> str:
116
+ real_dict = self.__dict__
117
+ self_fields = dataclasses.fields(self)
118
+ for field in self_fields:
119
+ if hasattr(self, field.name):
120
+ real_dict[field.name] = getattr(self, field.name)
121
+ output_object = {}
122
+ for key, value in real_dict.items():
123
+ output_object[key] = self._recursive_to_str__(value)
124
+ return str(output_object)
125
+
126
+
127
+ @dataclass(init=False)
128
+ class BaseList(BaseObjectMixin):
129
+ status_code: int
130
+ has_more: bool
131
+ last_id: str
132
+ first_id: str
133
+
134
+ def __init__(self, **kwargs):
135
+ super().__init__(**kwargs)
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  from http import HTTPStatus
2
4
  from pathlib import Path
3
5
 
@@ -23,11 +25,21 @@ NEGATIVE_PROMPT = 'negative_prompt'
23
25
  HISTORY = 'history'
24
26
  CUSTOMIZED_MODEL_ID = 'customized_model_id'
25
27
  IMAGES = 'images'
28
+ REFERENCE_VIDEO_URLS = 'reference_video_urls'
26
29
  TEXT_EMBEDDING_INPUT_KEY = 'texts'
27
30
  SERVICE_503_MESSAGE = 'Service temporarily unavailable, possibly overloaded or not ready.' # noqa E501
28
31
  WEBSOCKET_ERROR_CODE = 44
29
32
  SSE_CONTENT_TYPE = 'text/event-stream'
30
33
  DEPRECATED_MESSAGE = 'history and auto_history are deprecated for qwen serial models and will be remove in future, use messages' # noqa E501
34
+ SCENE = 'scene'
35
+ MESSAGE = 'message'
36
+ REQUEST_CONTENT_TEXT = 'text'
37
+ REQUEST_CONTENT_IMAGE = 'image'
38
+ REQUEST_CONTENT_AUDIO = 'audio'
39
+ FILE_PATH_SCHEMA = 'file://'
40
+
41
+ ENCRYPTION_AES_SECRET_KEY_BYTES = 32
42
+ ENCRYPTION_AES_IV_LENGTH = 12
31
43
 
32
44
  REPEATABLE_STATUS = [
33
45
  HTTPStatus.SERVICE_UNAVAILABLE, HTTPStatus.GATEWAY_TIMEOUT
@@ -36,22 +48,7 @@ REPEATABLE_STATUS = [
36
48
 
37
49
  class FilePurpose:
38
50
  fine_tune = 'fine_tune'
39
-
40
-
41
- class StreamResultMode:
42
- """Stream result mode.
43
- examples(I like apple)
44
- accumulate: will output
45
- I
46
- I like
47
- I like apple
48
- divide: will output
49
- I
50
- like
51
- apple
52
- """
53
- ACCUMULATE = 'accumulate'
54
- DIVIDE = 'divide'
51
+ assistants = 'assistants'
55
52
 
56
53
 
57
54
  class DeploymentStatus:
dashscope/common/env.py CHANGED
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import os
2
4
 
3
5
  from dashscope.common.constants import (DASHSCOPE_API_KEY_ENV,
dashscope/common/error.py CHANGED
@@ -1,61 +1,89 @@
1
- class AuthenticationError(Exception):
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
3
+
4
+ class DashScopeException(Exception):
5
+ pass
6
+
7
+
8
+ class AuthenticationError(DashScopeException):
2
9
  pass
3
10
 
4
11
 
5
- class InvalidParameter(Exception):
12
+ class InvalidParameter(DashScopeException):
6
13
  pass
7
14
 
8
15
 
9
- class InvalidTask(Exception):
16
+ class InvalidTask(DashScopeException):
10
17
  pass
11
18
 
12
19
 
13
- class UnsupportedModel(Exception):
20
+ class UnsupportedModel(DashScopeException):
14
21
  pass
15
22
 
16
23
 
17
- class UnsupportedTask(Exception):
24
+ class UnsupportedTask(DashScopeException):
18
25
  pass
19
26
 
20
27
 
21
- class ModelRequired(Exception):
28
+ class ModelRequired(DashScopeException):
22
29
  pass
23
30
 
24
31
 
25
- class InvalidModel(Exception):
32
+ class InvalidModel(DashScopeException):
26
33
  pass
27
34
 
28
35
 
29
- class InvalidInput(Exception):
36
+ class InvalidInput(DashScopeException):
30
37
  pass
31
38
 
32
39
 
33
- class InvalidFileFormat(Exception):
40
+ class InvalidFileFormat(DashScopeException):
34
41
  pass
35
42
 
36
43
 
37
- class UnsupportedApiProtocol(Exception):
44
+ class UnsupportedApiProtocol(DashScopeException):
38
45
  pass
39
46
 
40
47
 
41
- class NotImplemented(Exception):
48
+ class NotImplemented(DashScopeException):
42
49
  pass
43
50
 
44
51
 
45
- class MultiInputsWithBinaryNotSupported(Exception):
52
+ class MultiInputsWithBinaryNotSupported(DashScopeException):
46
53
  pass
47
54
 
48
55
 
49
- class UnexpectedMessageReceived(Exception):
56
+ class UnexpectedMessageReceived(DashScopeException):
50
57
  pass
51
58
 
52
59
 
53
- class UnsupportedData(Exception):
60
+ class UnsupportedData(DashScopeException):
54
61
  pass
55
62
 
56
63
 
64
+ class AssistantError(DashScopeException):
65
+ def __init__(self, **kwargs):
66
+ self.message = None
67
+ self.code = None
68
+ self.request_id = None
69
+ if 'message' in kwargs:
70
+ import json
71
+ msg = json.loads(kwargs['message'])
72
+ if 'request_id' in msg:
73
+ self.request_id = msg['request_id']
74
+ if 'code' in msg:
75
+ self.code = msg['code']
76
+ if 'message' in msg:
77
+ self.message = msg['message']
78
+
79
+ def __str__(self):
80
+ msg = 'Request failed, request_id: %s, code: %s, message: %s' % ( # noqa E501
81
+ self.request_id, self.code, self.message)
82
+ return msg
83
+
84
+
57
85
  # for server send generation or inference error.
58
- class RequestFailure(Exception):
86
+ class RequestFailure(DashScopeException):
59
87
  def __init__(self,
60
88
  request_id=None,
61
89
  message=None,
@@ -72,29 +100,37 @@ class RequestFailure(Exception):
72
100
  return msg
73
101
 
74
102
 
75
- class UnknownMessageReceived(Exception):
103
+ class UnknownMessageReceived(DashScopeException):
104
+ pass
105
+
106
+
107
+ class InputDataRequired(DashScopeException):
108
+ pass
109
+
110
+
111
+ class InputRequired(DashScopeException):
76
112
  pass
77
113
 
78
114
 
79
- class InputDataRequired(Exception):
115
+ class UnsupportedDataType(DashScopeException):
80
116
  pass
81
117
 
82
118
 
83
- class InputRequired(Exception):
119
+ class ServiceUnavailableError(DashScopeException):
84
120
  pass
85
121
 
86
122
 
87
- class UnsupportedDataType(Exception):
123
+ class UnsupportedHTTPMethod(DashScopeException):
88
124
  pass
89
125
 
90
126
 
91
- class ServiceUnavailableError(Exception):
127
+ class AsyncTaskCreateFailed(DashScopeException):
92
128
  pass
93
129
 
94
130
 
95
- class UnsupportedHTTPMethod(Exception):
131
+ class UploadFileException(DashScopeException):
96
132
  pass
97
133
 
98
134
 
99
- class AsyncTaskCreateFailed(Exception):
135
+ class TimeoutException(DashScopeException):
100
136
  pass
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  import logging
2
4
  import os
3
5
 
@@ -1,3 +1,5 @@
1
+ # Copyright (c) Alibaba, Inc. and its affiliates.
2
+
1
3
  from collections import deque
2
4
  from typing import List
3
5