dashscope 1.20.13__py3-none-any.whl → 1.20.14__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.

Potentially problematic release.


This version of dashscope might be problematic. Click here for more details.

@@ -4,14 +4,17 @@
4
4
  @Date : 2024-02-24
5
5
  @Desc : Application calls for both http and http sse
6
6
  """
7
- from typing import Generator, Union
7
+ import copy
8
+ from typing import Generator, Union, List
8
9
 
9
10
  from dashscope.api_entities.api_request_factory import _build_api_request
10
11
  from dashscope.app.application_response import ApplicationResponse
11
12
  from dashscope.client.base_api import BaseApi
12
13
  from dashscope.common.api_key import get_default_api_key
13
- from dashscope.common.constants import HISTORY, PROMPT
14
+ from dashscope.common.constants import HISTORY, PROMPT, DEPRECATED_MESSAGE, MESSAGES
14
15
  from dashscope.common.error import InputRequired, InvalidInput
16
+ from dashscope.api_entities.dashscope_response import Message, Role
17
+ from dashscope.common.logging import logger
15
18
 
16
19
 
17
20
  class Application(BaseApi):
@@ -20,6 +23,7 @@ class Application(BaseApi):
20
23
  """API for app completion calls.
21
24
 
22
25
  """
26
+
23
27
  class DocReferenceType:
24
28
  """ doc reference type for rag completion """
25
29
 
@@ -31,21 +35,23 @@ class Application(BaseApi):
31
35
  def _validate_params(cls, api_key, app_id):
32
36
  if api_key is None:
33
37
  api_key = get_default_api_key()
38
+
34
39
  if app_id is None or not app_id:
35
40
  raise InputRequired('App id is required!')
41
+
36
42
  return api_key, app_id
37
43
 
38
44
  @classmethod
39
45
  def call(
40
- cls,
41
- app_id: str,
42
- prompt: str,
43
- history: list = None,
44
- workspace: str = None,
45
- api_key: str = None,
46
- **kwargs
47
- ) -> Union[ApplicationResponse, Generator[ApplicationResponse, None,
48
- None]]:
46
+ cls,
47
+ app_id: str,
48
+ prompt: str = None,
49
+ history: list = None,
50
+ workspace: str = None,
51
+ api_key: str = None,
52
+ messages: List[Message] = None,
53
+ **kwargs
54
+ ) -> Union[ApplicationResponse, Generator[ApplicationResponse, None, None]]:
49
55
  """Call app completion service.
50
56
 
51
57
  Args:
@@ -59,6 +65,7 @@ class Application(BaseApi):
59
65
  workspace(str, `optional`): Workspace for app completion call
60
66
  api_key (str, optional): The api api_key, can be None,
61
67
  if None, will get by default rule(TODO: api key doc).
68
+ messages(list): The generation messages.
62
69
 
63
70
  **kwargs:
64
71
  stream(bool, `optional`): Enable server-sent events
@@ -112,8 +119,8 @@ class Application(BaseApi):
112
119
 
113
120
  api_key, app_id = Application._validate_params(api_key, app_id)
114
121
 
115
- if prompt is None or not prompt:
116
- raise InputRequired('prompt is required!')
122
+ if (prompt is None or not prompt) and (messages is None or len(messages) == 0):
123
+ raise InputRequired('prompt or messages is required!')
117
124
 
118
125
  if workspace is not None and workspace:
119
126
  headers = kwargs.pop('headers', {})
@@ -121,7 +128,7 @@ class Application(BaseApi):
121
128
  kwargs['headers'] = headers
122
129
 
123
130
  input, parameters = cls._build_input_parameters(
124
- prompt, history, **kwargs)
131
+ prompt, history, messages, **kwargs)
125
132
  request = _build_api_request(model='',
126
133
  input=input,
127
134
  task_group=Application.task_group,
@@ -142,10 +149,22 @@ class Application(BaseApi):
142
149
  return ApplicationResponse.from_api_response(response)
143
150
 
144
151
  @classmethod
145
- def _build_input_parameters(cls, prompt, history, **kwargs):
152
+ def _build_input_parameters(cls, prompt, history, messages, **kwargs):
146
153
  parameters = {}
147
154
 
148
- input_param = {HISTORY: history, PROMPT: prompt}
155
+ input_param = {}
156
+ if messages is not None:
157
+ msgs = copy.deepcopy(messages)
158
+ if prompt is not None and prompt:
159
+ msgs.append({'role': Role.USER, 'content': prompt})
160
+ input_param = {MESSAGES: msgs}
161
+ elif history is not None and history:
162
+ logger.warning(DEPRECATED_MESSAGE)
163
+ input_param[HISTORY] = history
164
+ if prompt is not None and prompt:
165
+ input_param[PROMPT] = prompt
166
+ else:
167
+ input_param[PROMPT] = prompt
149
168
 
150
169
  session_id = kwargs.pop('session_id', None)
151
170
  if session_id is not None and session_id:
@@ -68,6 +68,7 @@ class ApplicationDocReference(DictMixin):
68
68
  text: str
69
69
  biz_id: str
70
70
  images: List[str]
71
+ page_number: List[int]
71
72
 
72
73
  def __init__(self,
73
74
  index_id: str = None,
@@ -78,6 +79,7 @@ class ApplicationDocReference(DictMixin):
78
79
  text: str = None,
79
80
  biz_id: str = None,
80
81
  images: List[str] = None,
82
+ page_number: List[int] = None,
81
83
  **kwargs):
82
84
  """ Doc references for retrieval result.
83
85
 
@@ -100,6 +102,7 @@ class ApplicationDocReference(DictMixin):
100
102
  text=text,
101
103
  biz_id=biz_id,
102
104
  images=images,
105
+ page_number=page_number,
103
106
  **kwargs)
104
107
 
105
108
 
@@ -36,11 +36,11 @@ class VocabularyService(BaseApi):
36
36
  self._kwargs = kwargs
37
37
  self._last_request_id = None
38
38
  self.model = model
39
- if self.model == None:
39
+ if self.model is None:
40
40
  self.model = 'speech-biasing'
41
41
 
42
42
  def __call_with_input(self, input):
43
- try_count = 0
43
+ try_count = 0
44
44
  while True:
45
45
  try:
46
46
  response = super().call(model=self.model,
@@ -36,7 +36,7 @@ class VoiceEnrollmentService(BaseApi):
36
36
  self._kwargs = kwargs
37
37
  self._last_request_id = None
38
38
  self.model = model
39
- if self.model == None:
39
+ if self.model is None:
40
40
  self.model = 'voice-enrollment'
41
41
 
42
42
  def __call_with_input(self, input):
@@ -178,9 +178,9 @@ class AsyncTaskGetMixin():
178
178
  }
179
179
  if custom_headers:
180
180
  headers = {
181
- **custom_headers,
182
- **headers,
183
- }
181
+ **custom_headers,
182
+ **headers,
183
+ }
184
184
  with requests.Session() as session:
185
185
  logger.debug('Starting request: %s' % status_url)
186
186
  response = session.get(status_url,
dashscope/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '1.20.13'
1
+ __version__ = '1.20.14'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dashscope
3
- Version: 1.20.13
3
+ Version: 1.20.14
4
4
  Summary: dashscope client sdk library
5
5
  Home-page: https://dashscope.aliyun.com/
6
6
  Author: Alibaba Cloud
@@ -6,7 +6,7 @@ dashscope/files.py,sha256=QgJjwhtn9F548nCA8jD8OvE6aQEj-20hZqJgYXsUdQU,3930
6
6
  dashscope/finetune.py,sha256=_tflDUvu0KagSoCzLaf0hofpG_P8NU6PylL8CPjVhrA,6243
7
7
  dashscope/model.py,sha256=UPOn1qMYFhX-ovXi3BMxZEBk8qOK7WLJOYHMbPZwYBo,1440
8
8
  dashscope/models.py,sha256=1-bc-Ue68zurgu_y6RhfFr9uzeQMF5AZq-C32lJGMGU,1224
9
- dashscope/version.py,sha256=S_Jpp_0DyAr58XdPBnt8Vp3igXO6V6giLNnGEK_HJHQ,24
9
+ dashscope/version.py,sha256=f2v96-65Z-gg0WsfONkq43TxOuOMUup-4S2fb1hhRjA,24
10
10
  dashscope/aigc/__init__.py,sha256=s-MCA87KYiVumYtKtJi5IMN7xelSF6TqEU3s3_7RF-Y,327
11
11
  dashscope/aigc/code_generation.py,sha256=KAJVrGp6tiNFBBg64Ovs9RfcP5SrIhrbW3wdA89NKso,10885
12
12
  dashscope/aigc/conversation.py,sha256=xRoJlCR-IXHjSdkDrK74a9ut1FJg0FZhTNXZAJC18MA,14231
@@ -22,8 +22,8 @@ dashscope/api_entities/dashscope_response.py,sha256=Bp1T7HwVlkOvpMNg-AEjz-BScxhL
22
22
  dashscope/api_entities/http_request.py,sha256=pYE8qRMu9CaQDiugPlXeYoaj_diBv-ZDExCD3WNhehI,13259
23
23
  dashscope/api_entities/websocket_request.py,sha256=Xr6IJ9WqrIw5ouBQLpgoRSwL1C09jkb4u1EZdxhVQy0,15039
24
24
  dashscope/app/__init__.py,sha256=UiN_9i--z84Dw5wUehOh_Tkk_9Gq_td_Kbz1dobBEKg,62
25
- dashscope/app/application.py,sha256=QdFSUgQCDDwEaJtlKkbrxrw1lXBCZB7eOX7P1D3GNgU,8532
26
- dashscope/app/application_response.py,sha256=U5I8Yb1IlXzj2L5a1OAl55i0MCB3kG9Qp4aY17_73pI,6886
25
+ dashscope/app/application.py,sha256=Cnd62LFpG70XJUo4Oibry9KzXPhPNmNkKFD4R5YuGTA,9343
26
+ dashscope/app/application_response.py,sha256=0pulI3O3z4R4h_YaDwzVimamo3XwTXGy5TiHCzysTBg,7011
27
27
  dashscope/assistants/__init__.py,sha256=i9N5OxHgY7edlOhTdPyC0N5Uc0uMCkB2vbMPDCD1zX0,383
28
28
  dashscope/assistants/assistant_types.py,sha256=1jNL30TOlrkiYhvCaB3E8jkPLG8CnQ6I3tHpYXZCsD0,4211
29
29
  dashscope/assistants/assistants.py,sha256=NYahIDqhtnOcQOmnhZsjc5F5jvBUQcce8-fbrJXHVnQ,10833
@@ -34,14 +34,14 @@ dashscope/audio/asr/asr_phrase_manager.py,sha256=EjtbI3zz9UQGS1qv6Yb4zzEMj4OJJVX
34
34
  dashscope/audio/asr/recognition.py,sha256=a4zIkIMiWwOEApP9k9ZC9jGDr7CP7BqB6Cy1dBVTN4g,18978
35
35
  dashscope/audio/asr/transcribe.py,sha256=HfZYpvpVfvGRAIIIzX65Af33E6vsIFGd_qqhQ8LaNcM,9651
36
36
  dashscope/audio/asr/transcription.py,sha256=D8CW0XDqJuEJVmNFJ6qczTysSV3Sz_rzk2C6NIKTtVc,9042
37
- dashscope/audio/asr/vocabulary.py,sha256=880u5CGh8Ky9iWXDf_7cUuHfL5AGmw8JJRCbRThVCMI,6484
37
+ dashscope/audio/asr/vocabulary.py,sha256=2MHxeaL0ANWk-TILrHhArKSdj0d5M_YHw0cnjB-E4dY,6476
38
38
  dashscope/audio/tts/__init__.py,sha256=fbnieZX9yNFNh5BsxLpLXb63jlxzxrdCJakV3ignjlQ,194
39
39
  dashscope/audio/tts/speech_synthesizer.py,sha256=dnKx9FDDdO_ETHAjhK8zaMVaH6SfoTtN5YxXXqgY1JA,7571
40
40
  dashscope/audio/tts_v2/__init__.py,sha256=5UfyDBYnuGgOy9KMxEIXA2U2ihcXutdZc1cqJudy-8M,282
41
- dashscope/audio/tts_v2/enrollment.py,sha256=sUkOEUsP8RXREMtTkAeDTYfrQJ6lPnM_Y-DeefXB_Q4,6140
41
+ dashscope/audio/tts_v2/enrollment.py,sha256=mvkYMj9WzqEztZb8zc56fm8Obw7ON9USrEYhATU6rcs,6140
42
42
  dashscope/audio/tts_v2/speech_synthesizer.py,sha256=lATasQJB8HlB_yYm90qqW6zIAE1CQFxBxhnch6xdg9s,19285
43
43
  dashscope/client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
- dashscope/client/base_api.py,sha256=rXN97XGyDhCCaD_dz_clpFDjOJfpGjqiH7yX3LaD-GE,41233
44
+ dashscope/client/base_api.py,sha256=D1lRDr_k58Vwd3jvmsMx4UtTjwdngx182LPYvmtXZjQ,41212
45
45
  dashscope/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
46
46
  dashscope/common/api_key.py,sha256=5Stp0odL5JSuIO3qJBp23QNppuGbqhhvKPS66qbMs0I,1986
47
47
  dashscope/common/base_type.py,sha256=C9xP6WuN5pOzviZ2g3X2EPcigldtFE0VlaUmjyNnUUk,4619
@@ -85,9 +85,9 @@ dashscope/tokenizers/tokenizer.py,sha256=y6P91qTCYo__pEx_0VHAcj9YECfbUdRqZU1fdGT
85
85
  dashscope/tokenizers/tokenizer_base.py,sha256=REDhzRyDT13iequ61-a6_KcTy0GFKlihQve5HkyoyRs,656
86
86
  dashscope/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
87
87
  dashscope/utils/oss_utils.py,sha256=7vZ2Lypxwiit8VcAqAvr3cCyhVfaLapDiNuF-H3ZCD4,7332
88
- dashscope-1.20.13.dist-info/LICENSE,sha256=Izp5L1DF1Mbza6qojkqNNWlE_mYLnr4rmzx2EBF8YFw,11413
89
- dashscope-1.20.13.dist-info/METADATA,sha256=LdYg6imH5DQJpKnK2iRS77l5js8bPweeV2yO-M6AfcA,6642
90
- dashscope-1.20.13.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
91
- dashscope-1.20.13.dist-info/entry_points.txt,sha256=raEp5dOuj8whJ7yqZlDM8WQ5p2RfnGrGNo0QLQEnatY,50
92
- dashscope-1.20.13.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
93
- dashscope-1.20.13.dist-info/RECORD,,
88
+ dashscope-1.20.14.dist-info/LICENSE,sha256=Izp5L1DF1Mbza6qojkqNNWlE_mYLnr4rmzx2EBF8YFw,11413
89
+ dashscope-1.20.14.dist-info/METADATA,sha256=BjqLaIu_UNVWxAYRXU8wsrrr4I8qsr08dUtKcm-LGyY,6642
90
+ dashscope-1.20.14.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
91
+ dashscope-1.20.14.dist-info/entry_points.txt,sha256=raEp5dOuj8whJ7yqZlDM8WQ5p2RfnGrGNo0QLQEnatY,50
92
+ dashscope-1.20.14.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
93
+ dashscope-1.20.14.dist-info/RECORD,,