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

@@ -0,0 +1,271 @@
1
+ import json
2
+ from typing import Any, Dict, Generator, List, Union
3
+
4
+ import dashscope
5
+ from dashscope.api_entities.dashscope_response import (GenerationResponse,
6
+ Message)
7
+ from dashscope.client.base_api import BaseAioApi, CreateMixin
8
+ from dashscope.common import constants
9
+ from dashscope.common.error import InputRequired, ModelRequired
10
+ from dashscope.common.utils import _get_task_group_and_task
11
+ from dashscope.api_entities.chat_completion_types import ChatCompletion, ChatCompletionChunk
12
+
13
+
14
+ class Completions(CreateMixin):
15
+ """Support openai compatible chat completion interface.
16
+
17
+ """
18
+ SUB_PATH = ''
19
+ @classmethod
20
+ def create(
21
+ cls,
22
+ *,
23
+ model: str,
24
+ messages: List[Message],
25
+ stream: bool = False,
26
+ temperature: float = None,
27
+ top_p: float = None,
28
+ top_k: int = None,
29
+ stop: Union[List[str], List[List[int]]] = None,
30
+ max_tokens: int = None,
31
+ repetition_penalty: float = None,
32
+ api_key: str = None,
33
+ workspace: str = None,
34
+ extra_headers: Dict = None,
35
+ extra_body: Dict = None,
36
+ **kwargs
37
+ ) -> Union[ChatCompletion, Generator[ChatCompletionChunk, None, None]]:
38
+ """Call openai compatible chat completion model service.
39
+
40
+ Args:
41
+ model (str): The requested model, such as qwen-long
42
+ messages (list): The generation messages.
43
+ examples:
44
+ [{'role': 'user',
45
+ 'content': 'The weather is fine today.'},
46
+ {'role': 'assistant', 'content': 'Suitable for outings'}]
47
+ stream(bool, `optional`): Enable server-sent events
48
+ (ref: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) # noqa E501
49
+ the result will back partially[qwen-turbo,bailian-v1].
50
+ temperature(float, `optional`): Used to control the degree
51
+ of randomness and diversity. Specifically, the temperature
52
+ value controls the degree to which the probability distribution
53
+ of each candidate word is smoothed when generating text.
54
+ A higher temperature value will reduce the peak value of
55
+ the probability, allowing more low-probability words to be
56
+ selected, and the generated results will be more diverse;
57
+ while a lower temperature value will enhance the peak value
58
+ of the probability, making it easier for high-probability
59
+ words to be selected, the generated results are more
60
+ deterministic.
61
+ top_p(float, `optional`): A sampling strategy, called nucleus
62
+ sampling, where the model considers the results of the
63
+ tokens with top_p probability mass. So 0.1 means only
64
+ the tokens comprising the top 10% probability mass are
65
+ considered.
66
+ top_k(int, `optional`): The size of the sample candidate set when generated. # noqa E501
67
+ For example, when the value is 50, only the 50 highest-scoring tokens # noqa E501
68
+ in a single generation form a randomly sampled candidate set. # noqa E501
69
+ The larger the value, the higher the randomness generated; # noqa E501
70
+ the smaller the value, the higher the certainty generated. # noqa E501
71
+ The default value is 0, which means the top_k policy is # noqa E501
72
+ not enabled. At this time, only the top_p policy takes effect. # noqa E501
73
+ stop(list[str] or list[list[int]], `optional`): Used to control the generation to stop # noqa E501
74
+ when encountering setting str or token ids, the result will not include # noqa E501
75
+ stop words or tokens.
76
+ max_tokens(int, `optional`): The maximum token num expected to be output. It should be # noqa E501
77
+ noted that the length generated by the model will only be less than max_tokens, # noqa E501
78
+ not necessarily equal to it. If max_tokens is set too large, the service will # noqa E501
79
+ directly prompt that the length exceeds the limit. It is generally # noqa E501
80
+ not recommended to set this value.
81
+ repetition_penalty(float, `optional`): Used to control the repeatability when generating models. # noqa E501
82
+ Increasing repetition_penalty can reduce the duplication of model generation. # noqa E501
83
+ 1.0 means no punishment.
84
+ api_key (str, optional): The api api_key, can be None,
85
+ if None, will get by default rule.
86
+ workspace (str, optional): The bailian workspace id.
87
+ **kwargs:
88
+ timeout: set request timeout.
89
+ Raises:
90
+ InvalidInput: The history and auto_history are mutually exclusive.
91
+
92
+ Returns:
93
+ Union[ChatCompletion,
94
+ Generator[ChatCompletionChunk, None, None]]: If
95
+ stream is True, return Generator, otherwise ChatCompletion.
96
+ """
97
+ if messages is None or not messages:
98
+ raise InputRequired('Messages is required!')
99
+ if model is None or not model:
100
+ raise ModelRequired('Model is required!')
101
+ data = {}
102
+ data['model'] = model
103
+ data['messages'] = messages
104
+ if temperature is not None:
105
+ data['temperature'] = temperature
106
+ if top_p is not None:
107
+ data['top_p'] = top_p
108
+ if top_k is not None:
109
+ data['top_k'] = top_k
110
+ if stop is not None:
111
+ data['stop'] = stop
112
+ if max_tokens is not None:
113
+ data[max_tokens] = max_tokens
114
+ if repetition_penalty is not None:
115
+ data['repetition_penalty'] = repetition_penalty
116
+ if extra_body is not None and extra_body:
117
+ data = {**data, **extra_body}
118
+
119
+ if extra_headers is not None and extra_headers:
120
+ kwargs = {'headers': extra_headers} if kwargs else {**kwargs, **{'headers': extra_headers}}
121
+
122
+ response = super().call(data=data,
123
+ path='chat/completions',
124
+ base_address=dashscope.base_compatible_api_url,
125
+ api_key=api_key,
126
+ flattened_output=True,
127
+ stream=stream,
128
+ workspace=workspace,
129
+ **kwargs)
130
+ if stream:
131
+ return (ChatCompletionChunk(**item) for _, item in response)
132
+ else:
133
+ return ChatCompletion(**response)
134
+
135
+
136
+ class AioGeneration(BaseAioApi):
137
+ task = 'text-generation'
138
+ """API for AI-Generated Content(AIGC) models.
139
+
140
+ """
141
+ class Models:
142
+ """@deprecated, use qwen_turbo instead"""
143
+ qwen_v1 = 'qwen-v1'
144
+ """@deprecated, use qwen_plus instead"""
145
+ qwen_plus_v1 = 'qwen-plus-v1'
146
+
147
+ bailian_v1 = 'bailian-v1'
148
+ dolly_12b_v2 = 'dolly-12b-v2'
149
+ qwen_turbo = 'qwen-turbo'
150
+ qwen_plus = 'qwen-plus'
151
+ qwen_max = 'qwen-max'
152
+
153
+ @classmethod
154
+ async def call(
155
+ cls,
156
+ model: str,
157
+ prompt: Any = None,
158
+ history: list = None,
159
+ api_key: str = None,
160
+ messages: List[Message] = None,
161
+ plugins: Union[str, Dict[str, Any]] = None,
162
+ workspace: str = None,
163
+ **kwargs
164
+ ) -> Union[GenerationResponse, Generator[GenerationResponse, None, None]]:
165
+ """Call generation model service.
166
+
167
+ Args:
168
+ model (str): The requested model, such as qwen-turbo
169
+ prompt (Any): The input prompt.
170
+ history (list):The user provided history, deprecated
171
+ examples:
172
+ [{'user':'The weather is fine today.',
173
+ 'bot': 'Suitable for outings'}].
174
+ Defaults to None.
175
+ api_key (str, optional): The api api_key, can be None,
176
+ if None, will get by default rule(TODO: api key doc).
177
+ messages (list): The generation messages.
178
+ examples:
179
+ [{'role': 'user',
180
+ 'content': 'The weather is fine today.'},
181
+ {'role': 'assistant', 'content': 'Suitable for outings'}]
182
+ plugins (Any): The plugin config. Can be plugins config str, or dict.
183
+ **kwargs:
184
+ stream(bool, `optional`): Enable server-sent events
185
+ (ref: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) # noqa E501
186
+ the result will back partially[qwen-turbo,bailian-v1].
187
+ temperature(float, `optional`): Used to control the degree
188
+ of randomness and diversity. Specifically, the temperature
189
+ value controls the degree to which the probability distribution
190
+ of each candidate word is smoothed when generating text.
191
+ A higher temperature value will reduce the peak value of
192
+ the probability, allowing more low-probability words to be
193
+ selected, and the generated results will be more diverse;
194
+ while a lower temperature value will enhance the peak value
195
+ of the probability, making it easier for high-probability
196
+ words to be selected, the generated results are more
197
+ deterministic, range(0, 2) .[qwen-turbo,qwen-plus].
198
+ top_p(float, `optional`): A sampling strategy, called nucleus
199
+ sampling, where the model considers the results of the
200
+ tokens with top_p probability mass. So 0.1 means only
201
+ the tokens comprising the top 10% probability mass are
202
+ considered[qwen-turbo,bailian-v1].
203
+ top_k(int, `optional`): The size of the sample candidate set when generated. # noqa E501
204
+ For example, when the value is 50, only the 50 highest-scoring tokens # noqa E501
205
+ in a single generation form a randomly sampled candidate set. # noqa E501
206
+ The larger the value, the higher the randomness generated; # noqa E501
207
+ the smaller the value, the higher the certainty generated. # noqa E501
208
+ The default value is 0, which means the top_k policy is # noqa E501
209
+ not enabled. At this time, only the top_p policy takes effect. # noqa E501
210
+ enable_search(bool, `optional`): Whether to enable web search(quark). # noqa E501
211
+ Currently works best only on the first round of conversation.
212
+ Default to False, support model: [qwen-turbo].
213
+ customized_model_id(str, required) The enterprise-specific
214
+ large model id, which needs to be generated from the
215
+ operation background of the enterprise-specific
216
+ large model product, support model: [bailian-v1].
217
+ result_format(str, `optional`): [message|text] Set result result format. # noqa E501
218
+ Default result is text
219
+ incremental_output(bool, `optional`): Used to control the streaming output mode. # noqa E501
220
+ If true, the subsequent output will include the previously input content. # noqa E501
221
+ Otherwise, the subsequent output will not include the previously output # noqa E501
222
+ content. Default false.
223
+ stop(list[str] or list[list[int]], `optional`): Used to control the generation to stop # noqa E501
224
+ when encountering setting str or token ids, the result will not include # noqa E501
225
+ stop words or tokens.
226
+ max_tokens(int, `optional`): The maximum token num expected to be output. It should be # noqa E501
227
+ noted that the length generated by the model will only be less than max_tokens, # noqa E501
228
+ not necessarily equal to it. If max_tokens is set too large, the service will # noqa E501
229
+ directly prompt that the length exceeds the limit. It is generally # noqa E501
230
+ not recommended to set this value.
231
+ repetition_penalty(float, `optional`): Used to control the repeatability when generating models. # noqa E501
232
+ Increasing repetition_penalty can reduce the duplication of model generation. # noqa E501
233
+ 1.0 means no punishment.
234
+ workspace (str): The dashscope workspace id.
235
+ Raises:
236
+ InvalidInput: The history and auto_history are mutually exclusive.
237
+
238
+ Returns:
239
+ Union[GenerationResponse,
240
+ Generator[GenerationResponse, None, None]]: If
241
+ stream is True, return Generator, otherwise GenerationResponse.
242
+ """
243
+ if (prompt is None or not prompt) and (messages is None
244
+ or not messages):
245
+ raise InputRequired('prompt or messages is required!')
246
+ if model is None or not model:
247
+ raise ModelRequired('Model is required!')
248
+ task_group, function = _get_task_group_and_task(__name__)
249
+ if plugins is not None:
250
+ headers = kwargs.pop('headers', {})
251
+ if isinstance(plugins, str):
252
+ headers['X-DashScope-Plugin'] = plugins
253
+ else:
254
+ headers['X-DashScope-Plugin'] = json.dumps(plugins)
255
+ kwargs['headers'] = headers
256
+ input, parameters = Generation._build_input_parameters(
257
+ model, prompt, history, messages, **kwargs)
258
+ response = await super().call(model=model,
259
+ task_group=task_group,
260
+ task=Generation.task,
261
+ function=function,
262
+ api_key=api_key,
263
+ input=input,
264
+ workspace=workspace,
265
+ **parameters)
266
+ is_stream = kwargs.get('stream', False)
267
+ if is_stream:
268
+ return (GenerationResponse.from_api_response(rsp)
269
+ async for rsp in response)
270
+ else:
271
+ return GenerationResponse.from_api_response(response)
@@ -0,0 +1,349 @@
1
+ # adapter from openai sdk
2
+ from dataclasses import dataclass
3
+ from typing import Dict, List, Literal, Optional
4
+
5
+ from dashscope.common.base_type import BaseObjectMixin
6
+ """
7
+ {
8
+ "choices": [
9
+ {
10
+ "message": {
11
+ "role": "assistant",
12
+ "content": "很抱歉,由于您提供的信息不完整,我无法直接比较两篇文章的内容。但是,一般而言,大型语言模型的训练通常确实涉及两个主要阶段:\n\n1. **预训练阶段 (Pre-Training Phase)**:在这个阶段,模型在大规模无标注文本数据集(如互联网上的网页、书籍、新闻等)上进行训练。目的是让模型学习语言的通用模式和结构。常见的预训练技术包括自回归(Autoregressive)模型如GPT系列,以及transformer架构下的编码器-解码器模型如BERT系列。\n\n2. **微调阶段 (Fine-Tuning Phase)**:预训练模型在特定任务的数据集上进行进一步训练,以适应下游任务,如问答、文本分类、机器翻译等。这个阶段允许模型根据具体任务的需求调整权重,从而提高性能。\n\n如果您能提供更详细的信息或两篇文章的具体内容,我可以给出更准确的比较分析。"
13
+ },
14
+ "finish_reason": "stop",
15
+ "index": 0,
16
+ "logprobs": null
17
+ }
18
+ ],
19
+ "object": "chat.completion",
20
+ "usage": {
21
+ "prompt_tokens": 66,
22
+ "completion_tokens": 195,
23
+ "total_tokens": 261
24
+ },
25
+ "created": 1716539630,
26
+ "system_fingerprint": null,
27
+ "model": "qwen-long",
28
+ "id": "chatcmpl-a737071790e091c6be016ea27a891392",
29
+ "status_code": 200
30
+ }
31
+ """
32
+
33
+ @dataclass(init=False)
34
+ class CompletionUsage(BaseObjectMixin):
35
+ completion_tokens: int
36
+ """Number of tokens in the generated completion."""
37
+
38
+ prompt_tokens: int
39
+ """Number of tokens in the prompt."""
40
+
41
+ total_tokens: int
42
+ """Total number of tokens used in the request (prompt + completion)."""
43
+ def __init__(self, **kwargs):
44
+ super().__init__(**kwargs)
45
+
46
+ @dataclass(init=False)
47
+ class TopLogprob(BaseObjectMixin):
48
+ token: str
49
+ """The token."""
50
+
51
+ bytes: Optional[List[int]] = None
52
+ """A list of integers representing the UTF-8 bytes representation of the token.
53
+
54
+ Useful in instances where characters are represented by multiple tokens and
55
+ their byte representations must be combined to generate the correct text
56
+ representation. Can be `null` if there is no bytes representation for the token.
57
+ """
58
+
59
+ logprob: float
60
+ """The log probability of this token, if it is within the top 20 most likely
61
+ tokens.
62
+
63
+ Otherwise, the value `-9999.0` is used to signify that the token is very
64
+ unlikely.
65
+ """
66
+ def __init__(self, **kwargs):
67
+ super().__init__(**kwargs)
68
+
69
+ @dataclass(init=False)
70
+ class ChatCompletionTokenLogprob(BaseObjectMixin):
71
+ token: str
72
+ """The token."""
73
+
74
+ bytes: Optional[List[int]] = None
75
+ """A list of integers representing the UTF-8 bytes representation of the token.
76
+
77
+ Useful in instances where characters are represented by multiple tokens and
78
+ their byte representations must be combined to generate the correct text
79
+ representation. Can be `null` if there is no bytes representation for the token.
80
+ """
81
+
82
+ logprob: float
83
+ """The log probability of this token, if it is within the top 20 most likely
84
+ tokens.
85
+
86
+ Otherwise, the value `-9999.0` is used to signify that the token is very
87
+ unlikely.
88
+ """
89
+
90
+ top_logprobs: List[TopLogprob]
91
+ """List of the most likely tokens and their log probability, at this token
92
+ position.
93
+
94
+ In rare cases, there may be fewer than the number of requested `top_logprobs`
95
+ returned.
96
+ """
97
+ def __init__(self, **kwargs):
98
+ if 'top_logprobs' in kwargs and kwargs['top_logprobs'] is not None and kwargs['top_logprobs']:
99
+ top_logprobs = []
100
+ for logprob in kwargs['top_logprobs']:
101
+ top_logprobs.append(ChatCompletionTokenLogprob(**logprob))
102
+ self.top_logprobs = top_logprobs
103
+ else:
104
+ self.top_logprobs = None
105
+
106
+ super().__init__(**kwargs)
107
+
108
+
109
+ @dataclass(init=False)
110
+ class ChoiceLogprobs(BaseObjectMixin):
111
+ content: Optional[List[ChatCompletionTokenLogprob]] = None
112
+ """A list of message content tokens with log probability information."""
113
+ def __init__(self, **kwargs):
114
+ if 'content' in kwargs and kwargs['content'] is not None and kwargs['content']:
115
+ logprobs = []
116
+ for logprob in kwargs['content']:
117
+ logprobs.append(ChatCompletionTokenLogprob(**logprob))
118
+ self.content = logprobs
119
+ else:
120
+ self.content = None
121
+
122
+ super().__init__(**kwargs)
123
+
124
+ @dataclass(init=False)
125
+ class FunctionCall(BaseObjectMixin):
126
+ arguments: str
127
+ """
128
+ The arguments to call the function with, as generated by the model in JSON
129
+ format. Note that the model does not always generate valid JSON, and may
130
+ hallucinate parameters not defined by your function schema. Validate the
131
+ arguments in your code before calling your function.
132
+ """
133
+
134
+ name: str
135
+ """The name of the function to call."""
136
+ def __init__(self, **kwargs):
137
+ super().__init__(**kwargs)
138
+
139
+ @dataclass(init=False)
140
+ class Function(BaseObjectMixin):
141
+ arguments: str
142
+ """
143
+ The arguments to call the function with, as generated by the model in JSON
144
+ format. Note that the model does not always generate valid JSON, and may
145
+ hallucinate parameters not defined by your function schema. Validate the
146
+ arguments in your code before calling your function.
147
+ """
148
+
149
+ name: str
150
+ """The name of the function to call."""
151
+ def __init__(self, **kwargs):
152
+ super().__init__(**kwargs)
153
+
154
+ @dataclass(init=False)
155
+ class ChatCompletionMessageToolCall(BaseObjectMixin):
156
+ id: str
157
+ """The ID of the tool call."""
158
+
159
+ function: Function
160
+ """The function that the model called."""
161
+
162
+ type: Literal["function"]
163
+ """The type of the tool. Currently, only `function` is supported."""
164
+ def __init__(self, **kwargs):
165
+ if 'function' in kwargs and kwargs['function'] is not None and kwargs['function']:
166
+ self.function = Function(**kwargs.pop('function', {}))
167
+ else:
168
+ function = None
169
+
170
+ super().__init__(**kwargs)
171
+
172
+ @dataclass(init=False)
173
+ class ChatCompletionMessage(BaseObjectMixin):
174
+ content: Optional[str] = None
175
+ """The contents of the message."""
176
+
177
+ role: Literal["assistant"]
178
+ """The role of the author of this message."""
179
+
180
+ function_call: Optional[FunctionCall] = None
181
+ """Deprecated and replaced by `tool_calls`.
182
+
183
+ The name and arguments of a function that should be called, as generated by the
184
+ model.
185
+ """
186
+
187
+ tool_calls: Optional[List[ChatCompletionMessageToolCall]] = None
188
+
189
+ """The tool calls generated by the model, such as function calls."""
190
+ def __init__(self, **kwargs):
191
+ if 'function_call' in kwargs and kwargs['function_call'] is not None and kwargs['function_call']:
192
+ self.function_call = FunctionCall(**kwargs.pop('function_call', {}))
193
+
194
+ if 'tool_calls' in kwargs and kwargs['tool_calls'] is not None and kwargs['tool_calls']:
195
+ tool_calls = []
196
+ for tool_call in kwargs['tool_calls']:
197
+ tool_calls.append(ChatCompletionMessageToolCall(**tool_call))
198
+ self.tool_calls = tool_calls
199
+
200
+ super().__init__(**kwargs)
201
+
202
+ @dataclass(init=False)
203
+ class Choice(BaseObjectMixin):
204
+ finish_reason: Literal["stop", "length", "tool_calls", "content_filter", "function_call"]
205
+ """The reason the model stopped generating tokens.
206
+
207
+ This will be `stop` if the model hit a natural stop point or a provided stop
208
+ sequence, `length` if the maximum number of tokens specified in the request was
209
+ reached, `content_filter` if content was omitted due to a flag from our content
210
+ filters, `tool_calls` if the model called a tool, or `function_call`
211
+ (deprecated) if the model called a function.
212
+ """
213
+
214
+ index: int
215
+ """The index of the choice in the list of choices."""
216
+
217
+ logprobs: Optional[ChoiceLogprobs] = None
218
+ """Log probability information for the choice."""
219
+
220
+ message: ChatCompletionMessage
221
+ """A chat completion message generated by the model."""
222
+
223
+ def __init__(self, **kwargs):
224
+ if 'message' in kwargs and kwargs['message'] is not None and kwargs['message']:
225
+ self.message = ChatCompletionMessage(**kwargs.pop('message', {}))
226
+ else:
227
+ self.message = None
228
+
229
+ if 'logprobs' in kwargs and kwargs['logprobs'] is not None and kwargs['logprobs']:
230
+ self.logprobs = ChoiceLogprobs(**kwargs.pop('logprobs', {}))
231
+
232
+ super().__init__(**kwargs)
233
+
234
+ @dataclass(init=False)
235
+ class ChatCompletion(BaseObjectMixin):
236
+ status_code: int
237
+ """The call response status_code, 200 indicate create success.
238
+ """
239
+ code: str
240
+ """The request failed, this is the error code.
241
+ """
242
+ message: str
243
+ """The request failed, this is the error message.
244
+ """
245
+ id: str
246
+ """A unique identifier for the chat completion.
247
+ """
248
+ choices: List[Choice]
249
+ """A list of chat completion choices.
250
+
251
+ Can be more than one if `n` is greater than 1.
252
+ """
253
+
254
+ created: int
255
+ """The Unix timestamp (in seconds) of when the chat completion was created."""
256
+
257
+ model: str
258
+ """The model used for the chat completion."""
259
+
260
+ object: Literal["chat.completion"]
261
+ """The object type, which is always `chat.completion`."""
262
+
263
+ system_fingerprint: Optional[str] = None
264
+ """This fingerprint represents the backend configuration that the model runs with.
265
+
266
+ Can be used in conjunction with the `seed` request parameter to understand when
267
+ backend changes have been made that might impact determinism.
268
+ """
269
+
270
+ usage: Optional[CompletionUsage] = None
271
+ """Usage statistics for the completion request."""
272
+
273
+ def __init__(self, **kwargs):
274
+ if 'usage' in kwargs and kwargs['usage'] is not None and kwargs['usage']:
275
+ self.usage = CompletionUsage(**kwargs.pop('usage', {}))
276
+ else:
277
+ self.usage = None
278
+
279
+ if 'choices' in kwargs and kwargs['choices'] is not None and kwargs['choices']:
280
+ choices = []
281
+ for choice in kwargs.pop('choices', []):
282
+ choices.append(Choice(**choice))
283
+ self.choices = choices
284
+ else:
285
+ self.choices = None
286
+ super().__init__(**kwargs)
287
+
288
+ @dataclass(init=False)
289
+ class ChatCompletionChunk(BaseObjectMixin):
290
+ status_code: int
291
+ """The call response status_code, 200 indicate create success.
292
+ """
293
+ code: str
294
+ """The request failed, this is the error code.
295
+ """
296
+ message: str
297
+ """The request failed, this is the error message.
298
+ """
299
+ id: str
300
+ """A unique identifier for the chat completion. Each chunk has the same ID."""
301
+
302
+ choices: List[Choice]
303
+ """A list of chat completion choices.
304
+
305
+ Can contain more than one elements if `n` is greater than 1. Can also be empty
306
+ for the last chunk if you set `stream_options: {"include_usage": true}`.
307
+ """
308
+
309
+ created: int
310
+ """The Unix timestamp (in seconds) of when the chat completion was created.
311
+
312
+ Each chunk has the same timestamp.
313
+ """
314
+
315
+ model: str
316
+ """The model to generate the completion."""
317
+
318
+ object: Literal["chat.completion.chunk"]
319
+ """The object type, which is always `chat.completion.chunk`."""
320
+
321
+ system_fingerprint: Optional[str] = None
322
+ """
323
+ This fingerprint represents the backend configuration that the model runs with.
324
+ Can be used in conjunction with the `seed` request parameter to understand when
325
+ backend changes have been made that might impact determinism.
326
+ """
327
+
328
+ usage: Optional[CompletionUsage] = None
329
+ """
330
+ An optional field that will only be present when you set
331
+ `stream_options: {"include_usage": true}` in your request. When present, it
332
+ contains a null value except for the last chunk which contains the token usage
333
+ statistics for the entire request.
334
+ """
335
+ def __init__(self, **kwargs):
336
+ if 'usage' in kwargs and kwargs['usage'] is not None and kwargs['usage']:
337
+ self.usage = CompletionUsage(**kwargs.pop('usage', {}))
338
+ else:
339
+ self.usage = None
340
+
341
+ if 'choices' in kwargs and kwargs['choices'] is not None and kwargs['choices']:
342
+ choices = []
343
+ for choice in kwargs.pop('choices', []):
344
+ choices.append(Choice(**choice))
345
+ self.choices = choices
346
+ else:
347
+ self.choices = None
348
+ super().__init__(**kwargs)
349
+
@@ -480,7 +480,7 @@ class VideoSynthesisOutput(DictMixin):
480
480
  class ImageSynthesisUsage(DictMixin):
481
481
  image_count: int
482
482
 
483
- def __init__(self, image_count: int, **kwargs):
483
+ def __init__(self, image_count: int = None, **kwargs):
484
484
  super().__init__(image_count=image_count, **kwargs)
485
485
 
486
486
 
@@ -356,3 +356,5 @@ class WebSocketRequest(AioBaseRequest):
356
356
  def _build_up_message(self, headers, payload):
357
357
  message = {'header': headers, 'payload': payload}
358
358
  return json.dumps(message)
359
+
360
+ [{"type": "Path", "pathConfig": {"values": ["/api/v1/configs/*","/api/v1/auths/activate","/api/v1/evaluations/*","/oauth/*","/api/v1/auths/reset/password","~*^/api/v1/users/logout/*"]}}]