dashscope 1.20.7__py3-none-any.whl → 1.20.9__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/finetune.py ADDED
@@ -0,0 +1,175 @@
1
+ from typing import Union
2
+
3
+ from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
4
+ from dashscope.client.base_api import (CancelMixin, CreateMixin, DeleteMixin,
5
+ GetStatusMixin, ListMixin, LogMixin,
6
+ StreamEventMixin)
7
+
8
+
9
+ class FineTune(CreateMixin, CancelMixin, DeleteMixin, ListMixin,
10
+ GetStatusMixin, StreamEventMixin, LogMixin):
11
+ SUB_PATH = 'fine-tunes'
12
+
13
+ @classmethod
14
+ def call(cls,
15
+ model: str,
16
+ training_file_ids: Union[list, str],
17
+ validation_file_ids: Union[list, str] = None,
18
+ mode: str = None,
19
+ hyper_parameters: dict = {},
20
+ api_key: str = None,
21
+ workspace: str = None,
22
+ **kwargs) -> DashScopeAPIResponse:
23
+ """Create fine-tune job
24
+
25
+ Args:
26
+ model (str): The model to be fine-tuned
27
+ training_file_ids (list, str): Ids of the fine-tune training data,
28
+ which can be pre-uploaded using the File API.
29
+ validation_file_ids ([list,str], optional): Ids of the fine-tune
30
+ validating data, which can be pre-uploaded using the File API.
31
+ mode (str): The fine-tune mode, sft or efficient_sft.
32
+ hyper_parameters (dict, optional): The fine-tune hyper parameters.
33
+ Defaults to empty.
34
+ api_key (str, optional): The api key. Defaults to None.
35
+ workspace (str): The dashscope workspace id.
36
+
37
+ Returns:
38
+ DashScopeAPIResponse: The request result.
39
+ """
40
+ request = {
41
+ 'model': model,
42
+ 'training_file_ids': training_file_ids,
43
+ 'validation_file_ids': validation_file_ids,
44
+ 'hyper_parameters': hyper_parameters if hyper_parameters else {},
45
+ }
46
+ if mode is not None:
47
+ request['training_type'] = mode
48
+ if 'finetuned_output' in kwargs:
49
+ request['finetuned_output'] = kwargs['finetuned_output']
50
+ return super().call(request,
51
+ api_key=api_key,
52
+ workspace=workspace,
53
+ **kwargs)
54
+
55
+ @classmethod
56
+ def cancel(cls,
57
+ job_id: str,
58
+ api_key: str = None,
59
+ workspace: str = None,
60
+ **kwargs) -> DashScopeAPIResponse:
61
+ """Cancel a running fine-tune job.
62
+
63
+ Args:
64
+ job_id (str): The fine-tune job id.
65
+ api_key (str, optional): The api api_key, can be None,
66
+ if None, will get by default rule(TODO: api key doc).
67
+ workspace (str): The dashscope workspace id.
68
+
69
+ Returns:
70
+ DashScopeAPIResponse: The request result.
71
+ """
72
+ return super().cancel(job_id, api_key, workspace=workspace, **kwargs)
73
+
74
+ @classmethod
75
+ def list(cls,
76
+ page=1,
77
+ page_size=10,
78
+ api_key: str = None,
79
+ workspace: str = None,
80
+ **kwargs) -> DashScopeAPIResponse:
81
+ """List fine-tune job.
82
+
83
+ Args:
84
+ api_key (str, optional): The api key
85
+ page (int, optional): Page number. Defaults to 1.
86
+ page_size (int, optional): Items per page. Defaults to 10.
87
+ workspace (str): The dashscope workspace id.
88
+
89
+ Returns:
90
+ DashScopeAPIResponse: The fine-tune jobs in the result.
91
+ """
92
+ return super().list(page,
93
+ page_size,
94
+ api_key,
95
+ workspace=workspace,
96
+ **kwargs)
97
+
98
+ @classmethod
99
+ def get(cls,
100
+ job_id: str,
101
+ api_key: str = None,
102
+ workspace: str = None,
103
+ **kwargs) -> DashScopeAPIResponse:
104
+ """Get fine-tune job information.
105
+
106
+ Args:
107
+ job_id (str): The fine-tune job id
108
+ api_key (str, optional): The api key. Defaults to None.
109
+ workspace (str): The dashscope workspace id.
110
+
111
+ Returns:
112
+ DashScopeAPIResponse: The job info
113
+ """
114
+ return super().get(job_id, api_key, workspace=workspace, **kwargs)
115
+
116
+ @classmethod
117
+ def delete(cls,
118
+ job_id: str,
119
+ api_key: str = None,
120
+ workspace: str = None,
121
+ **kwargs) -> DashScopeAPIResponse:
122
+ """Delete a fine-tune job.
123
+
124
+ Args:
125
+ job_id (str): The fine-tune job id.
126
+ api_key (str, optional): The api key. Defaults to None.
127
+ workspace (str): The dashscope workspace id.
128
+
129
+ Returns:
130
+ DashScopeAPIResponse: The delete result.
131
+ """
132
+ return super().delete(job_id, api_key, workspace=workspace, **kwargs)
133
+
134
+ @classmethod
135
+ def stream_events(cls,
136
+ job_id: str,
137
+ api_key: str = None,
138
+ workspace: str = None,
139
+ **kwargs) -> DashScopeAPIResponse:
140
+ """Get fine-tune job events.
141
+
142
+ Args:
143
+ job_id (str): The fine-tune job id
144
+ api_key (str, optional): the api key. Defaults to None.
145
+ workspace (str): The dashscope workspace id.
146
+
147
+ Returns:
148
+ DashScopeAPIResponse: The job log events.
149
+ """
150
+ return super().stream_events(job_id,
151
+ api_key,
152
+ workspace=workspace,
153
+ **kwargs)
154
+
155
+ @classmethod
156
+ def logs(cls,
157
+ job_id: str,
158
+ offset=1,
159
+ line=1000,
160
+ api_key: str = None,
161
+ workspace: str = None,
162
+ **kwargs) -> DashScopeAPIResponse:
163
+ """Get log of the job.
164
+
165
+ Args:
166
+ job_id (str): The job id(used for fine-tune)
167
+ offset (int, optional): start log line. Defaults to 1.
168
+ line (int, optional): total line return. Defaults to 1000.
169
+ api_key (str, optional): The api key. Defaults to None.
170
+ workspace (str): The dashscope workspace id.
171
+
172
+ Returns:
173
+ DashScopeAPIResponse: The response
174
+ """
175
+ return super().logs(job_id, offset, line, workspace=workspace)