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

dashscope/__init__.py CHANGED
@@ -25,6 +25,7 @@ from dashscope.model import Model
25
25
  from dashscope.nlp.understanding import Understanding
26
26
  from dashscope.tokenizers import (Tokenization, Tokenizer, get_tokenizer,
27
27
  list_tokenizers)
28
+ from dashscope.app.application import Application
28
29
 
29
30
  __all__ = [
30
31
  base_http_api_url, base_websocket_api_url, api_key, api_key_file_path,
@@ -34,7 +35,7 @@ __all__ = [
34
35
  MultiModalEmbeddingItemImage, MultiModalEmbeddingItemText,
35
36
  SpeechSynthesizer, MultiModalConversation, BatchTextEmbedding,
36
37
  BatchTextEmbeddingResponse, Understanding, CodeGeneration, Tokenization,
37
- Tokenizer, get_tokenizer, list_tokenizers
38
+ Tokenizer, get_tokenizer, list_tokenizers, Application
38
39
  ]
39
40
 
40
41
  logging.getLogger(__name__).addHandler(NullHandler())
@@ -0,0 +1,5 @@
1
+ from .application import Application
2
+
3
+ __all__ = [
4
+ Application
5
+ ]
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env python3
2
+ # -*-coding:utf-8 -*-
3
+
4
+ """
5
+ @File : application.py
6
+ @Date : 2024-02-24
7
+ @Desc : Application calls for both http and http sse
8
+ """
9
+ from typing import Generator, Union
10
+
11
+ from dashscope.api_entities.api_request_factory import _build_api_request
12
+ from dashscope.app.application_response import ApplicationResponse
13
+ from dashscope.client.base_api import BaseApi
14
+ from dashscope.common.api_key import get_default_api_key
15
+ from dashscope.common.constants import HISTORY, PROMPT
16
+ from dashscope.common.error import InputRequired, InvalidInput
17
+
18
+
19
+ class Application(BaseApi):
20
+ task_group = 'apps'
21
+ function = "completion"
22
+
23
+ """API for app completion calls.
24
+
25
+ """
26
+
27
+ class DocReferenceType:
28
+ """ doc reference type for rag completion """
29
+
30
+ simple = 'simple'
31
+
32
+ indexed = 'indexed'
33
+
34
+ @classmethod
35
+ def _validate_params(cls, api_key, app_id):
36
+ if api_key is None:
37
+ api_key = get_default_api_key()
38
+ if app_id is None or not app_id:
39
+ raise InputRequired('App id is required!')
40
+ return api_key, app_id
41
+
42
+ @classmethod
43
+ def call(
44
+ cls,
45
+ app_id: str,
46
+ prompt: str,
47
+ history: list = None,
48
+ workspace: str = None,
49
+ api_key: str = None,
50
+ **kwargs
51
+ ) -> Union[ApplicationResponse, Generator[ApplicationResponse, None, None]]:
52
+ """Call app completion service.
53
+
54
+ Args:
55
+ app_id (str): Id of bailian application
56
+ prompt (str): The input prompt.
57
+ history (list):The user provided history
58
+ examples:
59
+ [{'user':'The weather is fine today.',
60
+ 'bot': 'Suitable for outings'}].
61
+ Defaults to None.
62
+ workspace(str, `optional`): Workspace for app completion call
63
+ api_key (str, optional): The api api_key, can be None,
64
+ if None, will get by default rule(TODO: api key doc).
65
+
66
+ **kwargs:
67
+ stream(bool, `optional`): Enable server-sent events
68
+ (ref: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) # noqa E501
69
+ the result will back partially[qwen-turbo,bailian-v1].
70
+ temperature(float, `optional`): Used to control the degree
71
+ of randomness and diversity. Specifically, the temperature
72
+ value controls the degree to which the probability distribution
73
+ of each candidate word is smoothed when generating text.
74
+ A higher temperature value will reduce the peak value of
75
+ the probability, allowing more low-probability words to be
76
+ selected, and the generated results will be more diverse;
77
+ while a lower temperature value will enhance the peak value
78
+ of the probability, making it easier for high-probability
79
+ words to be selected, the generated results are more
80
+ deterministic, range(0, 2) .[qwen-turbo,qwen-plus].
81
+ top_p(float, `optional`): A sampling strategy, called nucleus
82
+ sampling, where the model considers the results of the
83
+ tokens with top_p probability mass. So 0.1 means only
84
+ the tokens comprising the top 10% probability mass are
85
+ considered[qwen-turbo,bailian-v1].
86
+ top_k(int, `optional`): The size of the sample candidate set when generated. # noqa E501
87
+ For example, when the value is 50, only the 50 highest-scoring tokens # noqa E501
88
+ in a single generation form a randomly sampled candidate set. # noqa E501
89
+ The larger the value, the higher the randomness generated; # noqa E501
90
+ the smaller the value, the higher the certainty generated. # noqa E501
91
+ The default value is 0, which means the top_k policy is # noqa E501
92
+ not enabled. At this time, only the top_p policy takes effect. # noqa E501
93
+ seed(int, `optional`): When generating, the seed of the random number is used to control the
94
+ randomness of the model generation. If you use the same seed, each run will generate the same results;
95
+ you can use the same seed when you need to reproduce the model's generated results.
96
+ The seed parameter supports unsigned 64-bit integer types. Default value 1234
97
+ session_id(str, `optional`): Session if for multiple rounds call.
98
+ biz_params(dict, `optional`): The extra parameters for flow or plugin.
99
+ has_thoughts(bool, `optional`): Flag to return rag or plugin process details. Default value false.
100
+ doc_tag_codes(list[str], `optional`): Tag code list for doc retrival.
101
+ doc_reference_type(str, `optional`): The type of doc reference.
102
+ simple: simple format of doc retrival which not include index in response text but in doc reference list.
103
+ indexed: include both index in response text and doc reference list
104
+ Raises:
105
+ InvalidInput: The history and auto_history are mutually exclusive.
106
+
107
+ Returns:
108
+ Union[CompletionResponse,
109
+ Generator[CompletionResponse, None, None]]: If
110
+ stream is True, return Generator, otherwise GenerationResponse.
111
+ """
112
+
113
+ api_key, app_id = Application._validate_params(api_key, app_id)
114
+
115
+ if prompt is None or not prompt:
116
+ raise InputRequired('prompt is required!')
117
+
118
+ if workspace is not None and workspace:
119
+ headers = kwargs.pop('headers', {})
120
+ headers['X-DashScope-WorkSpace'] = workspace
121
+ kwargs['headers'] = headers
122
+
123
+ input, parameters = cls._build_input_parameters(prompt, history, **kwargs)
124
+ request = _build_api_request(model='',
125
+ input=input,
126
+ task_group=Application.task_group,
127
+ task=app_id,
128
+ function=Application.function,
129
+ api_key=api_key,
130
+ is_service=False,
131
+ **parameters)
132
+ # call request service.
133
+ response = request.call()
134
+ is_stream = kwargs.get('stream', False)
135
+
136
+ if is_stream:
137
+ return (ApplicationResponse.from_api_response(rsp)
138
+ for rsp in response)
139
+ else:
140
+ return ApplicationResponse.from_api_response(response)
141
+
142
+ @classmethod
143
+ def _build_input_parameters(cls, prompt, history, **kwargs):
144
+ parameters = {}
145
+
146
+ input_param = {HISTORY: history,
147
+ PROMPT: prompt
148
+ }
149
+
150
+ session_id = kwargs.pop('session_id', None)
151
+ if session_id is not None and session_id:
152
+ input_param['session_id'] = session_id
153
+
154
+ doc_reference_type = kwargs.pop('doc_reference_type', None)
155
+ if doc_reference_type is not None and doc_reference_type:
156
+ input_param['doc_reference_type'] = doc_reference_type
157
+
158
+ doc_tag_codes = kwargs.pop('doc_tag_codes', None)
159
+ if doc_tag_codes is not None:
160
+ if isinstance(doc_tag_codes, list) and all(isinstance(item, str) for item in doc_tag_codes):
161
+ input_param['doc_tag_codes'] = doc_tag_codes
162
+ else:
163
+ raise InvalidInput('doc_tag_codes is not a List[str]')
164
+
165
+ biz_params = kwargs.pop('biz_params', None)
166
+ if biz_params is not None and biz_params:
167
+ input_param['biz_params'] = biz_params
168
+
169
+ return input_param, {**parameters, **kwargs}
@@ -0,0 +1,196 @@
1
+ #!/usr/bin/env python3
2
+ # -*-coding:utf-8 -*-
3
+
4
+ """
5
+ @File : application_response.py
6
+ @Date : 2024-02-24
7
+ @Desc : application call response
8
+ """
9
+ from dataclasses import dataclass
10
+ from http import HTTPStatus
11
+ from typing import List, Dict
12
+
13
+ from dashscope.api_entities.dashscope_response import DashScopeAPIResponse, DictMixin
14
+
15
+
16
+ @dataclass(init=False)
17
+ class ApplicationThought(DictMixin):
18
+ thought: str
19
+ action_type: str
20
+ response: str
21
+ action_name: str
22
+ action: str
23
+ action_input_stream: str
24
+ action_input: Dict
25
+ observation: str
26
+
27
+ def __init__(self,
28
+ thought: str = None,
29
+ action_type: str = None,
30
+ response: str = None,
31
+ action_name: str = None,
32
+ action: str = None,
33
+ action_input_stream: str = None,
34
+ action_input: Dict = None,
35
+ observation: str = None,
36
+ **kwargs):
37
+ """ Thought of app completion call result which describe model planning and doc retrieval
38
+ or plugin calls details.
39
+
40
+ Args:
41
+ thought (str, optional): Model's inference thought for doc retrieval or plugin process.
42
+ action_type (str, optional): Action type. response : final response; api: to run api calls.
43
+ response (str, optional): Model's results.
44
+ action_name (str, optional): Action name, e.g. searchDocument、api.
45
+ action (str, optional): Code of action, means which plugin or action to be run.
46
+ action_input_stream (str, optional): Input param with stream.
47
+ action_input (dict, optional): Api or plugin input parameters.
48
+ observation (str, optional): Result of api call or doc retrieval.
49
+ """
50
+
51
+ super().__init__(thought=thought,
52
+ action_type=action_type,
53
+ response=response,
54
+ action_name=action_name,
55
+ action=action,
56
+ action_input_stream=action_input_stream,
57
+ action_input=action_input,
58
+ observation=observation,
59
+ **kwargs)
60
+
61
+
62
+ @dataclass(init=False)
63
+ class ApplicationDocReference(DictMixin):
64
+ index_id: str
65
+ title: str
66
+ doc_id: str
67
+ doc_name: str
68
+ doc_url: str
69
+ text: str
70
+ biz_id: str
71
+
72
+ def __init__(self,
73
+ index_id: str = None,
74
+ title: str = None,
75
+ doc_id: str = None,
76
+ doc_name: str = None,
77
+ doc_url: str = None,
78
+ text: str = None,
79
+ biz_id: str = None,
80
+ **kwargs):
81
+ """ Doc references for retrieval result.
82
+
83
+ Args:
84
+ index_id (str, optional): Index id of doc retrival result reference.
85
+ title (str, optional): Title of original doc that retrieved.
86
+ doc_id (str, optional): Id of original doc that retrieved.
87
+ doc_name (str, optional): Name of original doc that retrieved.
88
+ doc_url (str, optional): Url of original doc that retrieved.
89
+ text (str, optional): Text in original doc that retrieved.
90
+ biz_id (str, optional): Biz id that caller is able to associated for biz logic.
91
+ """
92
+
93
+ super().__init__(index_id=index_id,
94
+ title=title,
95
+ doc_id=doc_id,
96
+ doc_name=doc_name,
97
+ doc_url=doc_url,
98
+ text=text,
99
+ biz_id=biz_id,
100
+ **kwargs)
101
+
102
+
103
+ @dataclass(init=False)
104
+ class ApplicationOutput(DictMixin):
105
+ text: str
106
+ finish_reason: str
107
+ session_id: str
108
+ thoughts: List[ApplicationThought]
109
+ doc_references: List[ApplicationDocReference]
110
+
111
+ def __init__(self,
112
+ text: str = None,
113
+ finish_reason: str = None,
114
+ session_id: str = None,
115
+ thoughts: List[ApplicationThought] = None,
116
+ doc_references: List[ApplicationDocReference] = None,
117
+ **kwargs):
118
+
119
+ ths = None
120
+ if thoughts is not None:
121
+ ths = []
122
+ for thought in thoughts:
123
+ ths.append(ApplicationThought(**thought))
124
+
125
+ refs = None
126
+ if doc_references is not None:
127
+ refs = []
128
+ for ref in doc_references:
129
+ refs.append(ApplicationDocReference(**ref))
130
+
131
+ super().__init__(text=text,
132
+ finish_reason=finish_reason,
133
+ session_id=session_id,
134
+ thoughts=ths,
135
+ doc_references=refs,
136
+ **kwargs)
137
+
138
+
139
+ @dataclass(init=False)
140
+ class ApplicationModelUsage(DictMixin):
141
+ model_id: str
142
+ input_tokens: int
143
+ output_tokens: int
144
+
145
+ def __init__(self,
146
+ model_id: str = None,
147
+ input_tokens: int = 0,
148
+ output_tokens: int = 0,
149
+ **kwargs):
150
+ super().__init__(model_id=model_id,
151
+ input_tokens=input_tokens,
152
+ output_tokens=output_tokens,
153
+ **kwargs)
154
+
155
+
156
+ @dataclass(init=False)
157
+ class ApplicationUsage(DictMixin):
158
+ models: List[ApplicationModelUsage]
159
+
160
+ def __init__(self,
161
+ models: List[ApplicationModelUsage] = None,
162
+ **kwargs):
163
+ model_usages = None
164
+ if models is not None:
165
+ model_usages = []
166
+ for model_usage in models:
167
+ model_usages.append(ApplicationModelUsage(**model_usage))
168
+
169
+ super().__init__(models=model_usages,
170
+ **kwargs)
171
+
172
+
173
+ @dataclass(init=False)
174
+ class ApplicationResponse(DashScopeAPIResponse):
175
+ output: ApplicationOutput
176
+ usage: ApplicationUsage
177
+
178
+ @staticmethod
179
+ def from_api_response(api_response: DashScopeAPIResponse):
180
+ if api_response.status_code == HTTPStatus.OK:
181
+ usage = {}
182
+ if api_response.usage:
183
+ usage = api_response.usage
184
+
185
+ return ApplicationResponse(
186
+ status_code=api_response.status_code,
187
+ request_id=api_response.request_id,
188
+ code=api_response.code,
189
+ message=api_response.message,
190
+ output=ApplicationOutput(**api_response.output),
191
+ usage=ApplicationUsage(**usage))
192
+ else:
193
+ return ApplicationResponse(status_code=api_response.status_code,
194
+ request_id=api_response.request_id,
195
+ code=api_response.code,
196
+ message=api_response.message)
dashscope/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = '1.14.1'
1
+ __version__ = '1.15.0'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dashscope
3
- Version: 1.14.1
3
+ Version: 1.15.0
4
4
  Summary: dashscope client sdk library
5
5
  Home-page: https://dashscope.aliyun.com/
6
6
  Author: Alibaba Cloud
@@ -1,10 +1,10 @@
1
- dashscope/__init__.py,sha256=UExSJnogmqVAzRL6R4HhTp-yTz9GwoDIh5xAf7E_BEI,2018
1
+ dashscope/__init__.py,sha256=zochMrwoyyQyf62XbUZaFhFpkIwULQCSNHCd2lcb7pY,2081
2
2
  dashscope/cli.py,sha256=7CnUZqaaUc0FxbmXHMiqOALl9YzZmSrFS23A7hbR0w0,23917
3
3
  dashscope/deployment.py,sha256=uhlQYOiu1baMQxQnFmRwI6ces0I-_DKp8uej_L0v1eY,4400
4
4
  dashscope/file.py,sha256=Dv2Fz3DLbcye2uuQxyQwRM7ky27OthouLXIpSQagQy4,3324
5
5
  dashscope/finetune.py,sha256=5QlIcnFCfSjN3gn9A2FO0kLUDa9Rx_jSc44ezT3aBEo,5118
6
6
  dashscope/model.py,sha256=iuIfal-vOo0yav0HXPdA7f93vd5JNTGIAdCG_WIYkW8,1158
7
- dashscope/version.py,sha256=eyARjsqZfiB7blnKzG-sgKU2HEsI143aQSUAfhkeA8U,23
7
+ dashscope/version.py,sha256=qiatipDCHB37xXqNBOc2sezBvX8WXTRFhAGZHwi0CXc,23
8
8
  dashscope/aigc/__init__.py,sha256=s-MCA87KYiVumYtKtJi5IMN7xelSF6TqEU3s3_7RF-Y,327
9
9
  dashscope/aigc/code_generation.py,sha256=bizJb3zGZx3pB74FKMIcnOi_6jkxpKgx__6urzqhQ_E,10627
10
10
  dashscope/aigc/conversation.py,sha256=_sAWhQjLgJENqRAXh-i2dw8bt_i69fJv9KZYVIi4CEg,14090
@@ -19,6 +19,9 @@ dashscope/api_entities/base_request.py,sha256=cXUL7xqSV8wBr5d-1kx65AO3IsRR9A_ps6
19
19
  dashscope/api_entities/dashscope_response.py,sha256=1KdBib5xOftcKXLzTETe5LElGy2mB8IG8E3JZrGOaAY,15814
20
20
  dashscope/api_entities/http_request.py,sha256=MzaTznVJUbyA8u6cLegxVSEM3JWlAhPHbSh4uDCX0-A,9506
21
21
  dashscope/api_entities/websocket_request.py,sha256=zU7OskAHaNlKcR9s_6Hlnhr5N3oam4w0sUD5E9N-4BQ,14586
22
+ dashscope/app/__init__.py,sha256=OOV2rFy0QlA9Gu3XVPtWJoBwK1J11BdGhkEdX_sdYGU,68
23
+ dashscope/app/application.py,sha256=nr27hXX8Es_6IWAPKO-Yzj7GF-sxC6JbL2P9U6UhqcE,7911
24
+ dashscope/app/application_response.py,sha256=pIuDSu_SAcX1Y_gK6ZYaadaMXV52XBZoM1uN4tTZ3FA,6739
22
25
  dashscope/audio/__init__.py,sha256=vlw0TFVRdeRWfzmJxhzarVUqkMs-DZNf4GiMtm3C8XE,45
23
26
  dashscope/audio/asr/__init__.py,sha256=-s180qWn_JPSpCo1q0aDJJ5HQ3zTzD4z5yUwsRqH4aU,275
24
27
  dashscope/audio/asr/asr_phrase_manager.py,sha256=BNrRBGGoAW_rcxoi_euh6bRktJO6asTiGroE8PMh1Xg,6641
@@ -55,9 +58,9 @@ dashscope/tokenizers/tokenizer.py,sha256=y6P91qTCYo__pEx_0VHAcj9YECfbUdRqZU1fdGT
55
58
  dashscope/tokenizers/tokenizer_base.py,sha256=REDhzRyDT13iequ61-a6_KcTy0GFKlihQve5HkyoyRs,656
56
59
  dashscope/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
57
60
  dashscope/utils/oss_utils.py,sha256=iCF5fLqIXDCS2zkE96t2DEUxCI76ArnQH2DiY2hgHu0,6522
58
- dashscope-1.14.1.dist-info/LICENSE,sha256=Izp5L1DF1Mbza6qojkqNNWlE_mYLnr4rmzx2EBF8YFw,11413
59
- dashscope-1.14.1.dist-info/METADATA,sha256=Hlg9nly8P6C_7fj2RwM8HEDuP8dt5unBCUmwGEy-FoY,6659
60
- dashscope-1.14.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
61
- dashscope-1.14.1.dist-info/entry_points.txt,sha256=raEp5dOuj8whJ7yqZlDM8WQ5p2RfnGrGNo0QLQEnatY,50
62
- dashscope-1.14.1.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
63
- dashscope-1.14.1.dist-info/RECORD,,
61
+ dashscope-1.15.0.dist-info/LICENSE,sha256=Izp5L1DF1Mbza6qojkqNNWlE_mYLnr4rmzx2EBF8YFw,11413
62
+ dashscope-1.15.0.dist-info/METADATA,sha256=Fgl_zE_G36nWNnB7UuE5Yh-soXFqps3ysxWqs-K_T3k,6659
63
+ dashscope-1.15.0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
64
+ dashscope-1.15.0.dist-info/entry_points.txt,sha256=raEp5dOuj8whJ7yqZlDM8WQ5p2RfnGrGNo0QLQEnatY,50
65
+ dashscope-1.15.0.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
66
+ dashscope-1.15.0.dist-info/RECORD,,