dashscope 1.15.0__py3-none-any.whl → 1.16.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 +34 -9
- dashscope/api_entities/dashscope_response.py +63 -0
- dashscope/rerank/__init__.py +0 -0
- dashscope/rerank/text_rerank.py +67 -0
- dashscope/version.py +1 -1
- {dashscope-1.15.0.dist-info → dashscope-1.16.0.dist-info}/METADATA +1 -1
- {dashscope-1.15.0.dist-info → dashscope-1.16.0.dist-info}/RECORD +11 -9
- {dashscope-1.15.0.dist-info → dashscope-1.16.0.dist-info}/LICENSE +0 -0
- {dashscope-1.15.0.dist-info → dashscope-1.16.0.dist-info}/WHEEL +0 -0
- {dashscope-1.15.0.dist-info → dashscope-1.16.0.dist-info}/entry_points.txt +0 -0
- {dashscope-1.15.0.dist-info → dashscope-1.16.0.dist-info}/top_level.txt +0 -0
dashscope/__init__.py
CHANGED
|
@@ -6,6 +6,7 @@ from dashscope.aigc.conversation import Conversation, History, HistoryItem
|
|
|
6
6
|
from dashscope.aigc.generation import Generation
|
|
7
7
|
from dashscope.aigc.image_synthesis import ImageSynthesis
|
|
8
8
|
from dashscope.aigc.multimodal_conversation import MultiModalConversation
|
|
9
|
+
from dashscope.app.application import Application
|
|
9
10
|
from dashscope.audio.asr.transcription import Transcription
|
|
10
11
|
from dashscope.audio.tts.speech_synthesizer import SpeechSynthesizer
|
|
11
12
|
from dashscope.common.api_key import save_api_key
|
|
@@ -23,19 +24,43 @@ from dashscope.file import File
|
|
|
23
24
|
from dashscope.finetune import FineTune
|
|
24
25
|
from dashscope.model import Model
|
|
25
26
|
from dashscope.nlp.understanding import Understanding
|
|
27
|
+
from dashscope.rerank.text_rerank import TextReRank
|
|
26
28
|
from dashscope.tokenizers import (Tokenization, Tokenizer, get_tokenizer,
|
|
27
29
|
list_tokenizers)
|
|
28
|
-
from dashscope.app.application import Application
|
|
29
30
|
|
|
30
31
|
__all__ = [
|
|
31
|
-
base_http_api_url,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
base_http_api_url,
|
|
33
|
+
base_websocket_api_url,
|
|
34
|
+
api_key,
|
|
35
|
+
api_key_file_path,
|
|
36
|
+
save_api_key,
|
|
37
|
+
Conversation,
|
|
38
|
+
Generation,
|
|
39
|
+
History,
|
|
40
|
+
HistoryItem,
|
|
41
|
+
ImageSynthesis,
|
|
42
|
+
Transcription,
|
|
43
|
+
File,
|
|
44
|
+
Deployment,
|
|
45
|
+
FineTune,
|
|
46
|
+
Model,
|
|
47
|
+
TextEmbedding,
|
|
48
|
+
MultiModalEmbedding,
|
|
49
|
+
MultiModalEmbeddingItemAudio,
|
|
50
|
+
MultiModalEmbeddingItemImage,
|
|
51
|
+
MultiModalEmbeddingItemText,
|
|
52
|
+
SpeechSynthesizer,
|
|
53
|
+
MultiModalConversation,
|
|
54
|
+
BatchTextEmbedding,
|
|
55
|
+
BatchTextEmbeddingResponse,
|
|
56
|
+
Understanding,
|
|
57
|
+
CodeGeneration,
|
|
58
|
+
Tokenization,
|
|
59
|
+
Tokenizer,
|
|
60
|
+
get_tokenizer,
|
|
61
|
+
list_tokenizers,
|
|
62
|
+
Application,
|
|
63
|
+
TextReRank,
|
|
39
64
|
]
|
|
40
65
|
|
|
41
66
|
logging.getLogger(__name__).addHandler(NullHandler())
|
|
@@ -493,3 +493,66 @@ class ImageSynthesisResponse(DashScopeAPIResponse):
|
|
|
493
493
|
request_id=api_response.request_id,
|
|
494
494
|
code=api_response.code,
|
|
495
495
|
message=api_response.message)
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
@dataclass(init=False)
|
|
499
|
+
class ReRankResult(DictMixin):
|
|
500
|
+
index: int
|
|
501
|
+
relevance_score: float
|
|
502
|
+
document: Dict = None
|
|
503
|
+
|
|
504
|
+
def __init__(self,
|
|
505
|
+
index: int,
|
|
506
|
+
relevance_score: float,
|
|
507
|
+
document: Dict = None,
|
|
508
|
+
**kwargs):
|
|
509
|
+
super().__init__(index=index,
|
|
510
|
+
relevance_score=relevance_score,
|
|
511
|
+
document=document,
|
|
512
|
+
**kwargs)
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
@dataclass(init=False)
|
|
516
|
+
class ReRankOutput(DictMixin):
|
|
517
|
+
results: List[ReRankResult]
|
|
518
|
+
|
|
519
|
+
def __init__(self, results: List[ReRankResult] = None, **kwargs):
|
|
520
|
+
ress = None
|
|
521
|
+
if results is not None:
|
|
522
|
+
ress = []
|
|
523
|
+
for res in results:
|
|
524
|
+
ress.append(ReRankResult(**res))
|
|
525
|
+
super().__init__(results=ress, **kwargs)
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
@dataclass(init=False)
|
|
529
|
+
class ReRankUsage(DictMixin):
|
|
530
|
+
total_tokens: int
|
|
531
|
+
|
|
532
|
+
def __init__(self, total_tokens=None, **kwargs):
|
|
533
|
+
super().__init__(total_tokens=total_tokens, **kwargs)
|
|
534
|
+
|
|
535
|
+
|
|
536
|
+
@dataclass(init=False)
|
|
537
|
+
class ReRankResponse(DashScopeAPIResponse):
|
|
538
|
+
output: ReRankOutput
|
|
539
|
+
usage: GenerationUsage
|
|
540
|
+
|
|
541
|
+
@staticmethod
|
|
542
|
+
def from_api_response(api_response: DashScopeAPIResponse):
|
|
543
|
+
if api_response.status_code == HTTPStatus.OK:
|
|
544
|
+
usage = {}
|
|
545
|
+
if api_response.usage:
|
|
546
|
+
usage = api_response.usage
|
|
547
|
+
|
|
548
|
+
return ReRankResponse(status_code=api_response.status_code,
|
|
549
|
+
request_id=api_response.request_id,
|
|
550
|
+
code=api_response.code,
|
|
551
|
+
message=api_response.message,
|
|
552
|
+
output=ReRankOutput(**api_response.output),
|
|
553
|
+
usage=ReRankUsage(**usage))
|
|
554
|
+
else:
|
|
555
|
+
return ReRankResponse(status_code=api_response.status_code,
|
|
556
|
+
request_id=api_response.request_id,
|
|
557
|
+
code=api_response.code,
|
|
558
|
+
message=api_response.message)
|
|
File without changes
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from typing import List
|
|
2
|
+
|
|
3
|
+
from dashscope.api_entities.dashscope_response import ReRankResponse
|
|
4
|
+
from dashscope.client.base_api import BaseApi
|
|
5
|
+
from dashscope.common.error import InputRequired, ModelRequired
|
|
6
|
+
from dashscope.common.utils import _get_task_group_and_task
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TextReRank(BaseApi):
|
|
10
|
+
task = 'text-rerank'
|
|
11
|
+
"""API for rerank models.
|
|
12
|
+
|
|
13
|
+
"""
|
|
14
|
+
class Models:
|
|
15
|
+
gte_rerank = 'gte-rerank'
|
|
16
|
+
|
|
17
|
+
@classmethod
|
|
18
|
+
def call(cls,
|
|
19
|
+
model: str,
|
|
20
|
+
query: str,
|
|
21
|
+
documents: List[str],
|
|
22
|
+
return_documents: bool = None,
|
|
23
|
+
top_n: int = None,
|
|
24
|
+
api_key: str = None,
|
|
25
|
+
**kwargs) -> ReRankResponse:
|
|
26
|
+
"""Calling rerank service.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
model (str): The model to use.
|
|
30
|
+
query (str): The query string.
|
|
31
|
+
documents (List[str]): The documents to rank.
|
|
32
|
+
return_documents(bool, `optional`): enable return origin documents,
|
|
33
|
+
system default is false.
|
|
34
|
+
top_n(int, `optional`): how many documents to return, default return
|
|
35
|
+
all the documents.
|
|
36
|
+
api_key (str, optional): The DashScope api key. Defaults to None.
|
|
37
|
+
|
|
38
|
+
Raises:
|
|
39
|
+
InputRequired: The query and documents are required.
|
|
40
|
+
ModelRequired: The model is required.
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
RerankResponse: The rerank result.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
if query is None or documents is None or not documents:
|
|
47
|
+
raise InputRequired('query and documents are required!')
|
|
48
|
+
if model is None or not model:
|
|
49
|
+
raise ModelRequired('Model is required!')
|
|
50
|
+
task_group, function = _get_task_group_and_task(__name__)
|
|
51
|
+
input = {'query': query, 'documents': documents}
|
|
52
|
+
parameters = {}
|
|
53
|
+
if return_documents is not None:
|
|
54
|
+
parameters['return_documents'] = return_documents
|
|
55
|
+
if top_n is not None:
|
|
56
|
+
parameters['top_n'] = top_n
|
|
57
|
+
parameters = {**parameters, **kwargs}
|
|
58
|
+
|
|
59
|
+
response = super().call(model=model,
|
|
60
|
+
task_group=task_group,
|
|
61
|
+
task=TextReRank.task,
|
|
62
|
+
function=function,
|
|
63
|
+
api_key=api_key,
|
|
64
|
+
input=input,
|
|
65
|
+
**parameters)
|
|
66
|
+
|
|
67
|
+
return ReRankResponse.from_api_response(response)
|
dashscope/version.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = '1.
|
|
1
|
+
__version__ = '1.16.0'
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
dashscope/__init__.py,sha256=
|
|
1
|
+
dashscope/__init__.py,sha256=d8I_67Tz2SZ2QQl5ApZQce86c3EM3obx9bQPtlvR_c8,2242
|
|
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=
|
|
7
|
+
dashscope/version.py,sha256=VqyRgjiBsROG0SjVyQSaBPufjG1-xO7kqvhm7iGUJGA,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
|
|
@@ -16,7 +16,7 @@ dashscope/api_entities/aiohttp_request.py,sha256=ZFbdpJh7SwHnBzbYLhqr_FdcDVRgLVM
|
|
|
16
16
|
dashscope/api_entities/api_request_data.py,sha256=JUMcfpJjKXEZLCBSFIDpgoaeQYk5uK9-CwhM4OHIHFQ,5463
|
|
17
17
|
dashscope/api_entities/api_request_factory.py,sha256=MCJOGgUzaWTaLZ5d8m8dck7QdSUNX7XLbKYyB3pT23E,4067
|
|
18
18
|
dashscope/api_entities/base_request.py,sha256=cXUL7xqSV8wBr5d-1kx65AO3IsRR9A_ps6Lok-v-MKM,926
|
|
19
|
-
dashscope/api_entities/dashscope_response.py,sha256=
|
|
19
|
+
dashscope/api_entities/dashscope_response.py,sha256=Bp1T7HwVlkOvpMNg-AEjz-BScxhLUXMXlE8ApXTtfhQ,17872
|
|
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
22
|
dashscope/app/__init__.py,sha256=OOV2rFy0QlA9Gu3XVPtWJoBwK1J11BdGhkEdX_sdYGU,68
|
|
@@ -50,6 +50,8 @@ dashscope/nlp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
50
50
|
dashscope/nlp/understanding.py,sha256=uVkf_4iULnlnuGmEX3taKiHgzxu173vvgVwY5EO2C2Y,2803
|
|
51
51
|
dashscope/protocol/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
52
52
|
dashscope/protocol/websocket.py,sha256=z-v6PGx3L4zYBANuC48s7SWSQSwRCDoh0zcfhv9Bf8U,561
|
|
53
|
+
dashscope/rerank/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
54
|
+
dashscope/rerank/text_rerank.py,sha256=1L-RLUxMCvNhbMud1FUG6YFWT7ZV979fzhMEuVjJ1oI,2398
|
|
53
55
|
dashscope/resources/qwen.tiktoken,sha256=srG437XMXwJLr8NzEhxquj9m-aWgJp4kNHCh3hajMYY,2561218
|
|
54
56
|
dashscope/tokenizers/__init__.py,sha256=Oy5FMT37Non6e1YxdHQ89U93Dy3CG1Ez0gBa771KZo0,200
|
|
55
57
|
dashscope/tokenizers/qwen_tokenizer.py,sha256=dCnT9-9NrqPS85bEhjlPULUfDADVRhlleYwM_ILgCeI,4111
|
|
@@ -58,9 +60,9 @@ dashscope/tokenizers/tokenizer.py,sha256=y6P91qTCYo__pEx_0VHAcj9YECfbUdRqZU1fdGT
|
|
|
58
60
|
dashscope/tokenizers/tokenizer_base.py,sha256=REDhzRyDT13iequ61-a6_KcTy0GFKlihQve5HkyoyRs,656
|
|
59
61
|
dashscope/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
60
62
|
dashscope/utils/oss_utils.py,sha256=iCF5fLqIXDCS2zkE96t2DEUxCI76ArnQH2DiY2hgHu0,6522
|
|
61
|
-
dashscope-1.
|
|
62
|
-
dashscope-1.
|
|
63
|
-
dashscope-1.
|
|
64
|
-
dashscope-1.
|
|
65
|
-
dashscope-1.
|
|
66
|
-
dashscope-1.
|
|
63
|
+
dashscope-1.16.0.dist-info/LICENSE,sha256=Izp5L1DF1Mbza6qojkqNNWlE_mYLnr4rmzx2EBF8YFw,11413
|
|
64
|
+
dashscope-1.16.0.dist-info/METADATA,sha256=3cCTPzfYufBwbOtgXaSRwzo7mv6uEOHTjTuMAv9yPD4,6659
|
|
65
|
+
dashscope-1.16.0.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
66
|
+
dashscope-1.16.0.dist-info/entry_points.txt,sha256=raEp5dOuj8whJ7yqZlDM8WQ5p2RfnGrGNo0QLQEnatY,50
|
|
67
|
+
dashscope-1.16.0.dist-info/top_level.txt,sha256=woqavFJK9zas5xTqynmALqOtlafghjsk63Xk86powTU,10
|
|
68
|
+
dashscope-1.16.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|