mistralai 1.0.2__py3-none-any.whl → 1.1.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.
- mistralai/_hooks/sdkhooks.py +23 -4
- mistralai/_hooks/types.py +27 -9
- mistralai/agents.py +286 -150
- mistralai/basesdk.py +90 -5
- mistralai/chat.py +260 -144
- mistralai/embeddings.py +73 -53
- mistralai/files.py +252 -192
- mistralai/fim.py +174 -110
- mistralai/fine_tuning.py +3 -2
- mistralai/jobs.py +372 -263
- mistralai/models/__init__.py +499 -46
- mistralai/models/agentscompletionrequest.py +47 -11
- mistralai/models/agentscompletionstreamrequest.py +49 -11
- mistralai/models/archiveftmodelout.py +6 -2
- mistralai/models/assistantmessage.py +11 -4
- mistralai/models/{modelcard.py → basemodelcard.py} +37 -14
- mistralai/models/chatcompletionchoice.py +4 -2
- mistralai/models/chatcompletionrequest.py +57 -11
- mistralai/models/chatcompletionresponse.py +6 -2
- mistralai/models/chatcompletionstreamrequest.py +59 -11
- mistralai/models/checkpointout.py +3 -2
- mistralai/models/completionchunk.py +10 -3
- mistralai/models/completionevent.py +1 -2
- mistralai/models/completionresponsestreamchoice.py +13 -5
- mistralai/models/contentchunk.py +13 -10
- mistralai/models/delete_model_v1_models_model_id_deleteop.py +4 -3
- mistralai/models/deletefileout.py +3 -2
- mistralai/models/deletemodelout.py +3 -2
- mistralai/models/deltamessage.py +9 -4
- mistralai/models/detailedjobout.py +59 -7
- mistralai/models/embeddingrequest.py +9 -4
- mistralai/models/embeddingresponse.py +5 -2
- mistralai/models/embeddingresponsedata.py +3 -2
- mistralai/models/eventout.py +9 -4
- mistralai/models/files_api_routes_delete_fileop.py +4 -3
- mistralai/models/files_api_routes_retrieve_fileop.py +4 -3
- mistralai/models/files_api_routes_upload_fileop.py +27 -8
- mistralai/models/fileschema.py +26 -5
- mistralai/models/fimcompletionrequest.py +26 -5
- mistralai/models/fimcompletionresponse.py +6 -2
- mistralai/models/fimcompletionstreamrequest.py +26 -5
- mistralai/models/finetuneablemodel.py +7 -1
- mistralai/models/ftmodelcapabilitiesout.py +4 -2
- mistralai/models/ftmodelcard.py +103 -0
- mistralai/models/ftmodelout.py +32 -6
- mistralai/models/function.py +3 -2
- mistralai/models/functioncall.py +2 -2
- mistralai/models/functionname.py +17 -0
- mistralai/models/githubrepositoryin.py +15 -4
- mistralai/models/githubrepositoryout.py +15 -4
- mistralai/models/httpvalidationerror.py +2 -2
- mistralai/models/imageurl.py +48 -0
- mistralai/models/imageurlchunk.py +32 -0
- mistralai/models/jobin.py +22 -5
- mistralai/models/jobmetadataout.py +31 -6
- mistralai/models/jobout.py +55 -7
- mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +3 -2
- mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +83 -16
- mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +4 -3
- mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +9 -4
- mistralai/models/jobsout.py +6 -2
- mistralai/models/legacyjobmetadataout.py +45 -6
- mistralai/models/listfilesout.py +2 -2
- mistralai/models/metricout.py +11 -6
- mistralai/models/modelcapabilities.py +7 -2
- mistralai/models/modellist.py +21 -7
- mistralai/models/responseformat.py +6 -7
- mistralai/models/responseformats.py +8 -0
- mistralai/models/retrieve_model_v1_models_model_id_getop.py +24 -5
- mistralai/models/retrievefileout.py +26 -5
- mistralai/models/security.py +12 -3
- mistralai/models/systemmessage.py +6 -5
- mistralai/models/textchunk.py +9 -4
- mistralai/models/tool.py +9 -8
- mistralai/models/toolcall.py +9 -7
- mistralai/models/toolchoice.py +29 -0
- mistralai/models/toolchoiceenum.py +7 -0
- mistralai/models/toolmessage.py +11 -4
- mistralai/models/tooltypes.py +8 -0
- mistralai/models/trainingfile.py +2 -2
- mistralai/models/trainingparameters.py +27 -6
- mistralai/models/trainingparametersin.py +29 -8
- mistralai/models/unarchiveftmodelout.py +6 -2
- mistralai/models/updateftmodelin.py +8 -4
- mistralai/models/uploadfileout.py +26 -5
- mistralai/models/usageinfo.py +3 -2
- mistralai/models/usermessage.py +6 -5
- mistralai/models/validationerror.py +3 -2
- mistralai/models/wandbintegration.py +14 -4
- mistralai/models/wandbintegrationout.py +13 -4
- mistralai/models_.py +392 -294
- mistralai/sdk.py +24 -19
- mistralai/sdkconfiguration.py +6 -8
- mistralai/utils/__init__.py +6 -1
- mistralai/utils/logger.py +4 -1
- mistralai/utils/retries.py +2 -1
- mistralai/utils/security.py +13 -6
- {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/METADATA +103 -74
- mistralai-1.1.0.dist-info/RECORD +254 -0
- mistralai_azure/_hooks/sdkhooks.py +23 -4
- mistralai_azure/_hooks/types.py +27 -9
- mistralai_azure/basesdk.py +91 -6
- mistralai_azure/chat.py +252 -144
- mistralai_azure/models/__init__.py +157 -15
- mistralai_azure/models/assistantmessage.py +18 -5
- mistralai_azure/models/chatcompletionchoice.py +7 -3
- mistralai_azure/models/chatcompletionrequest.py +65 -12
- mistralai_azure/models/chatcompletionresponse.py +6 -2
- mistralai_azure/models/chatcompletionstreamrequest.py +67 -12
- mistralai_azure/models/completionchunk.py +10 -3
- mistralai_azure/models/completionevent.py +1 -2
- mistralai_azure/models/completionresponsestreamchoice.py +10 -4
- mistralai_azure/models/contentchunk.py +4 -11
- mistralai_azure/models/deltamessage.py +16 -5
- mistralai_azure/models/function.py +3 -2
- mistralai_azure/models/functioncall.py +2 -2
- mistralai_azure/models/functionname.py +17 -0
- mistralai_azure/models/httpvalidationerror.py +2 -2
- mistralai_azure/models/responseformat.py +6 -7
- mistralai_azure/models/responseformats.py +8 -0
- mistralai_azure/models/security.py +12 -3
- mistralai_azure/models/systemmessage.py +6 -5
- mistralai_azure/models/textchunk.py +9 -4
- mistralai_azure/models/tool.py +9 -8
- mistralai_azure/models/toolcall.py +9 -7
- mistralai_azure/models/toolchoice.py +29 -0
- mistralai_azure/models/toolchoiceenum.py +7 -0
- mistralai_azure/models/toolmessage.py +18 -5
- mistralai_azure/models/tooltypes.py +8 -0
- mistralai_azure/models/usageinfo.py +3 -2
- mistralai_azure/models/usermessage.py +6 -5
- mistralai_azure/models/validationerror.py +3 -2
- mistralai_azure/sdkconfiguration.py +6 -8
- mistralai_azure/utils/__init__.py +8 -3
- mistralai_azure/utils/forms.py +10 -9
- mistralai_azure/utils/headers.py +8 -8
- mistralai_azure/utils/logger.py +6 -0
- mistralai_azure/utils/queryparams.py +16 -14
- mistralai_azure/utils/retries.py +2 -1
- mistralai_azure/utils/security.py +12 -6
- mistralai_azure/utils/serializers.py +17 -8
- mistralai_azure/utils/url.py +13 -8
- mistralai_azure/utils/values.py +6 -0
- mistralai_gcp/_hooks/sdkhooks.py +23 -4
- mistralai_gcp/_hooks/types.py +27 -9
- mistralai_gcp/basesdk.py +91 -6
- mistralai_gcp/chat.py +252 -144
- mistralai_gcp/fim.py +166 -110
- mistralai_gcp/models/__init__.py +179 -17
- mistralai_gcp/models/assistantmessage.py +18 -5
- mistralai_gcp/models/chatcompletionchoice.py +7 -3
- mistralai_gcp/models/chatcompletionrequest.py +62 -12
- mistralai_gcp/models/chatcompletionresponse.py +6 -2
- mistralai_gcp/models/chatcompletionstreamrequest.py +64 -12
- mistralai_gcp/models/completionchunk.py +10 -3
- mistralai_gcp/models/completionevent.py +1 -2
- mistralai_gcp/models/completionresponsestreamchoice.py +10 -4
- mistralai_gcp/models/contentchunk.py +4 -11
- mistralai_gcp/models/deltamessage.py +16 -5
- mistralai_gcp/models/fimcompletionrequest.py +33 -6
- mistralai_gcp/models/fimcompletionresponse.py +6 -2
- mistralai_gcp/models/fimcompletionstreamrequest.py +33 -6
- mistralai_gcp/models/function.py +3 -2
- mistralai_gcp/models/functioncall.py +2 -2
- mistralai_gcp/models/functionname.py +17 -0
- mistralai_gcp/models/httpvalidationerror.py +2 -2
- mistralai_gcp/models/responseformat.py +6 -7
- mistralai_gcp/models/responseformats.py +8 -0
- mistralai_gcp/models/security.py +12 -3
- mistralai_gcp/models/systemmessage.py +6 -5
- mistralai_gcp/models/textchunk.py +9 -4
- mistralai_gcp/models/tool.py +9 -8
- mistralai_gcp/models/toolcall.py +9 -7
- mistralai_gcp/models/toolchoice.py +29 -0
- mistralai_gcp/models/toolchoiceenum.py +7 -0
- mistralai_gcp/models/toolmessage.py +18 -5
- mistralai_gcp/models/tooltypes.py +8 -0
- mistralai_gcp/models/usageinfo.py +3 -2
- mistralai_gcp/models/usermessage.py +6 -5
- mistralai_gcp/models/validationerror.py +3 -2
- mistralai_gcp/sdk.py +14 -10
- mistralai_gcp/sdkconfiguration.py +6 -8
- mistralai_gcp/utils/__init__.py +8 -3
- mistralai_gcp/utils/forms.py +10 -9
- mistralai_gcp/utils/headers.py +8 -8
- mistralai_gcp/utils/logger.py +6 -0
- mistralai_gcp/utils/queryparams.py +16 -14
- mistralai_gcp/utils/retries.py +2 -1
- mistralai_gcp/utils/security.py +12 -6
- mistralai_gcp/utils/serializers.py +17 -8
- mistralai_gcp/utils/url.py +13 -8
- mistralai_gcp/utils/values.py +6 -0
- mistralai-1.0.2.dist-info/RECORD +0 -236
- {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/LICENSE +0 -0
- {mistralai-1.0.2.dist-info → mistralai-1.1.0.dist-info}/WHEEL +0 -0
mistralai/chat.py
CHANGED
|
@@ -7,12 +7,13 @@ from mistralai.types import Nullable, OptionalNullable, UNSET
|
|
|
7
7
|
from mistralai.utils import eventstreaming, get_security_from_env
|
|
8
8
|
from typing import Any, AsyncGenerator, Generator, List, Optional, Union
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
class Chat(BaseSDK):
|
|
11
12
|
r"""Chat Completion API."""
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
def complete(
|
|
15
|
-
self,
|
|
15
|
+
self,
|
|
16
|
+
*,
|
|
16
17
|
model: Nullable[str],
|
|
17
18
|
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
18
19
|
temperature: Optional[float] = 0.7,
|
|
@@ -22,9 +23,18 @@ class Chat(BaseSDK):
|
|
|
22
23
|
stream: Optional[bool] = False,
|
|
23
24
|
stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
|
|
24
25
|
random_seed: OptionalNullable[int] = UNSET,
|
|
25
|
-
response_format: Optional[
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
response_format: Optional[
|
|
27
|
+
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
28
|
+
] = None,
|
|
29
|
+
tools: OptionalNullable[
|
|
30
|
+
Union[List[models.Tool], List[models.ToolTypedDict]]
|
|
31
|
+
] = UNSET,
|
|
32
|
+
tool_choice: Optional[
|
|
33
|
+
Union[
|
|
34
|
+
models.ChatCompletionRequestToolChoice,
|
|
35
|
+
models.ChatCompletionRequestToolChoiceTypedDict,
|
|
36
|
+
]
|
|
37
|
+
] = None,
|
|
28
38
|
safe_prompt: Optional[bool] = False,
|
|
29
39
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
30
40
|
server_url: Optional[str] = None,
|
|
@@ -41,9 +51,9 @@ class Chat(BaseSDK):
|
|
|
41
51
|
:param stream: Whether to stream back partial progress. If set, tokens will be sent as data-only server-side events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
|
|
42
52
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
43
53
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
44
|
-
:param response_format:
|
|
45
|
-
:param tools:
|
|
46
|
-
:param tool_choice:
|
|
54
|
+
:param response_format:
|
|
55
|
+
:param tools:
|
|
56
|
+
:param tool_choice:
|
|
47
57
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
48
58
|
:param retries: Override the default retry configuration for this method
|
|
49
59
|
:param server_url: Override the default server URL for this method
|
|
@@ -53,10 +63,10 @@ class Chat(BaseSDK):
|
|
|
53
63
|
url_variables = None
|
|
54
64
|
if timeout_ms is None:
|
|
55
65
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
56
|
-
|
|
66
|
+
|
|
57
67
|
if server_url is not None:
|
|
58
68
|
base_url = server_url
|
|
59
|
-
|
|
69
|
+
|
|
60
70
|
request = models.ChatCompletionRequest(
|
|
61
71
|
model=model,
|
|
62
72
|
temperature=temperature,
|
|
@@ -67,12 +77,16 @@ class Chat(BaseSDK):
|
|
|
67
77
|
stop=stop,
|
|
68
78
|
random_seed=random_seed,
|
|
69
79
|
messages=utils.get_pydantic_model(messages, List[models.Messages]),
|
|
70
|
-
response_format=utils.get_pydantic_model(
|
|
80
|
+
response_format=utils.get_pydantic_model(
|
|
81
|
+
response_format, Optional[models.ResponseFormat]
|
|
82
|
+
),
|
|
71
83
|
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
72
|
-
tool_choice=
|
|
84
|
+
tool_choice=utils.get_pydantic_model(
|
|
85
|
+
tool_choice, Optional[models.ChatCompletionRequestToolChoice]
|
|
86
|
+
),
|
|
73
87
|
safe_prompt=safe_prompt,
|
|
74
88
|
)
|
|
75
|
-
|
|
89
|
+
|
|
76
90
|
req = self.build_request(
|
|
77
91
|
method="POST",
|
|
78
92
|
path="/v1/chat/completions",
|
|
@@ -85,47 +99,57 @@ class Chat(BaseSDK):
|
|
|
85
99
|
user_agent_header="user-agent",
|
|
86
100
|
accept_header_value="application/json",
|
|
87
101
|
security=self.sdk_configuration.security,
|
|
88
|
-
get_serialized_body=lambda: utils.serialize_request_body(
|
|
102
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
103
|
+
request, False, False, "json", models.ChatCompletionRequest
|
|
104
|
+
),
|
|
89
105
|
timeout_ms=timeout_ms,
|
|
90
106
|
)
|
|
91
|
-
|
|
107
|
+
|
|
92
108
|
if retries == UNSET:
|
|
93
109
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
94
110
|
retries = self.sdk_configuration.retry_config
|
|
95
111
|
|
|
96
112
|
retry_config = None
|
|
97
113
|
if isinstance(retries, utils.RetryConfig):
|
|
98
|
-
retry_config = (retries, [
|
|
99
|
-
|
|
100
|
-
"500",
|
|
101
|
-
"502",
|
|
102
|
-
"503",
|
|
103
|
-
"504"
|
|
104
|
-
])
|
|
105
|
-
|
|
114
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
115
|
+
|
|
106
116
|
http_res = self.do_request(
|
|
107
|
-
hook_ctx=HookContext(
|
|
117
|
+
hook_ctx=HookContext(
|
|
118
|
+
operation_id="chat_completion_v1_chat_completions_post",
|
|
119
|
+
oauth2_scopes=[],
|
|
120
|
+
security_source=get_security_from_env(
|
|
121
|
+
self.sdk_configuration.security, models.Security
|
|
122
|
+
),
|
|
123
|
+
),
|
|
108
124
|
request=req,
|
|
109
|
-
error_status_codes=["422","4XX","5XX"],
|
|
110
|
-
retry_config=retry_config
|
|
125
|
+
error_status_codes=["422", "4XX", "5XX"],
|
|
126
|
+
retry_config=retry_config,
|
|
111
127
|
)
|
|
112
|
-
|
|
128
|
+
|
|
113
129
|
data: Any = None
|
|
114
130
|
if utils.match_response(http_res, "200", "application/json"):
|
|
115
|
-
return utils.unmarshal_json(
|
|
131
|
+
return utils.unmarshal_json(
|
|
132
|
+
http_res.text, Optional[models.ChatCompletionResponse]
|
|
133
|
+
)
|
|
116
134
|
if utils.match_response(http_res, "422", "application/json"):
|
|
117
135
|
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
118
136
|
raise models.HTTPValidationError(data=data)
|
|
119
|
-
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
120
|
-
raise models.SDKError(
|
|
121
|
-
|
|
137
|
+
if utils.match_response(http_res, ["4XX", "5XX"], "*"):
|
|
138
|
+
raise models.SDKError(
|
|
139
|
+
"API error occurred", http_res.status_code, http_res.text, http_res
|
|
140
|
+
)
|
|
141
|
+
|
|
122
142
|
content_type = http_res.headers.get("Content-Type")
|
|
123
|
-
raise models.SDKError(
|
|
143
|
+
raise models.SDKError(
|
|
144
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
145
|
+
http_res.status_code,
|
|
146
|
+
http_res.text,
|
|
147
|
+
http_res,
|
|
148
|
+
)
|
|
124
149
|
|
|
125
|
-
|
|
126
|
-
|
|
127
150
|
async def complete_async(
|
|
128
|
-
self,
|
|
151
|
+
self,
|
|
152
|
+
*,
|
|
129
153
|
model: Nullable[str],
|
|
130
154
|
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
131
155
|
temperature: Optional[float] = 0.7,
|
|
@@ -135,9 +159,18 @@ class Chat(BaseSDK):
|
|
|
135
159
|
stream: Optional[bool] = False,
|
|
136
160
|
stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
|
|
137
161
|
random_seed: OptionalNullable[int] = UNSET,
|
|
138
|
-
response_format: Optional[
|
|
139
|
-
|
|
140
|
-
|
|
162
|
+
response_format: Optional[
|
|
163
|
+
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
164
|
+
] = None,
|
|
165
|
+
tools: OptionalNullable[
|
|
166
|
+
Union[List[models.Tool], List[models.ToolTypedDict]]
|
|
167
|
+
] = UNSET,
|
|
168
|
+
tool_choice: Optional[
|
|
169
|
+
Union[
|
|
170
|
+
models.ChatCompletionRequestToolChoice,
|
|
171
|
+
models.ChatCompletionRequestToolChoiceTypedDict,
|
|
172
|
+
]
|
|
173
|
+
] = None,
|
|
141
174
|
safe_prompt: Optional[bool] = False,
|
|
142
175
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
143
176
|
server_url: Optional[str] = None,
|
|
@@ -154,9 +187,9 @@ class Chat(BaseSDK):
|
|
|
154
187
|
:param stream: Whether to stream back partial progress. If set, tokens will be sent as data-only server-side events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
|
|
155
188
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
156
189
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
157
|
-
:param response_format:
|
|
158
|
-
:param tools:
|
|
159
|
-
:param tool_choice:
|
|
190
|
+
:param response_format:
|
|
191
|
+
:param tools:
|
|
192
|
+
:param tool_choice:
|
|
160
193
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
161
194
|
:param retries: Override the default retry configuration for this method
|
|
162
195
|
:param server_url: Override the default server URL for this method
|
|
@@ -166,10 +199,10 @@ class Chat(BaseSDK):
|
|
|
166
199
|
url_variables = None
|
|
167
200
|
if timeout_ms is None:
|
|
168
201
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
169
|
-
|
|
202
|
+
|
|
170
203
|
if server_url is not None:
|
|
171
204
|
base_url = server_url
|
|
172
|
-
|
|
205
|
+
|
|
173
206
|
request = models.ChatCompletionRequest(
|
|
174
207
|
model=model,
|
|
175
208
|
temperature=temperature,
|
|
@@ -180,13 +213,17 @@ class Chat(BaseSDK):
|
|
|
180
213
|
stop=stop,
|
|
181
214
|
random_seed=random_seed,
|
|
182
215
|
messages=utils.get_pydantic_model(messages, List[models.Messages]),
|
|
183
|
-
response_format=utils.get_pydantic_model(
|
|
216
|
+
response_format=utils.get_pydantic_model(
|
|
217
|
+
response_format, Optional[models.ResponseFormat]
|
|
218
|
+
),
|
|
184
219
|
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
185
|
-
tool_choice=
|
|
220
|
+
tool_choice=utils.get_pydantic_model(
|
|
221
|
+
tool_choice, Optional[models.ChatCompletionRequestToolChoice]
|
|
222
|
+
),
|
|
186
223
|
safe_prompt=safe_prompt,
|
|
187
224
|
)
|
|
188
|
-
|
|
189
|
-
req = self.
|
|
225
|
+
|
|
226
|
+
req = self.build_request_async(
|
|
190
227
|
method="POST",
|
|
191
228
|
path="/v1/chat/completions",
|
|
192
229
|
base_url=base_url,
|
|
@@ -198,59 +235,86 @@ class Chat(BaseSDK):
|
|
|
198
235
|
user_agent_header="user-agent",
|
|
199
236
|
accept_header_value="application/json",
|
|
200
237
|
security=self.sdk_configuration.security,
|
|
201
|
-
get_serialized_body=lambda: utils.serialize_request_body(
|
|
238
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
239
|
+
request, False, False, "json", models.ChatCompletionRequest
|
|
240
|
+
),
|
|
202
241
|
timeout_ms=timeout_ms,
|
|
203
242
|
)
|
|
204
|
-
|
|
243
|
+
|
|
205
244
|
if retries == UNSET:
|
|
206
245
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
207
246
|
retries = self.sdk_configuration.retry_config
|
|
208
247
|
|
|
209
248
|
retry_config = None
|
|
210
249
|
if isinstance(retries, utils.RetryConfig):
|
|
211
|
-
retry_config = (retries, [
|
|
212
|
-
|
|
213
|
-
"500",
|
|
214
|
-
"502",
|
|
215
|
-
"503",
|
|
216
|
-
"504"
|
|
217
|
-
])
|
|
218
|
-
|
|
250
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
251
|
+
|
|
219
252
|
http_res = await self.do_request_async(
|
|
220
|
-
hook_ctx=HookContext(
|
|
253
|
+
hook_ctx=HookContext(
|
|
254
|
+
operation_id="chat_completion_v1_chat_completions_post",
|
|
255
|
+
oauth2_scopes=[],
|
|
256
|
+
security_source=get_security_from_env(
|
|
257
|
+
self.sdk_configuration.security, models.Security
|
|
258
|
+
),
|
|
259
|
+
),
|
|
221
260
|
request=req,
|
|
222
|
-
error_status_codes=["422","4XX","5XX"],
|
|
223
|
-
retry_config=retry_config
|
|
261
|
+
error_status_codes=["422", "4XX", "5XX"],
|
|
262
|
+
retry_config=retry_config,
|
|
224
263
|
)
|
|
225
|
-
|
|
264
|
+
|
|
226
265
|
data: Any = None
|
|
227
266
|
if utils.match_response(http_res, "200", "application/json"):
|
|
228
|
-
return utils.unmarshal_json(
|
|
267
|
+
return utils.unmarshal_json(
|
|
268
|
+
http_res.text, Optional[models.ChatCompletionResponse]
|
|
269
|
+
)
|
|
229
270
|
if utils.match_response(http_res, "422", "application/json"):
|
|
230
271
|
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
231
272
|
raise models.HTTPValidationError(data=data)
|
|
232
|
-
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
233
|
-
raise models.SDKError(
|
|
234
|
-
|
|
273
|
+
if utils.match_response(http_res, ["4XX", "5XX"], "*"):
|
|
274
|
+
raise models.SDKError(
|
|
275
|
+
"API error occurred", http_res.status_code, http_res.text, http_res
|
|
276
|
+
)
|
|
277
|
+
|
|
235
278
|
content_type = http_res.headers.get("Content-Type")
|
|
236
|
-
raise models.SDKError(
|
|
279
|
+
raise models.SDKError(
|
|
280
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
281
|
+
http_res.status_code,
|
|
282
|
+
http_res.text,
|
|
283
|
+
http_res,
|
|
284
|
+
)
|
|
237
285
|
|
|
238
|
-
|
|
239
|
-
|
|
240
286
|
def stream(
|
|
241
|
-
self,
|
|
287
|
+
self,
|
|
288
|
+
*,
|
|
242
289
|
model: Nullable[str],
|
|
243
|
-
messages: Union[
|
|
290
|
+
messages: Union[
|
|
291
|
+
List[models.ChatCompletionStreamRequestMessages],
|
|
292
|
+
List[models.ChatCompletionStreamRequestMessagesTypedDict],
|
|
293
|
+
],
|
|
244
294
|
temperature: Optional[float] = 0.7,
|
|
245
295
|
top_p: Optional[float] = 1,
|
|
246
296
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
247
297
|
min_tokens: OptionalNullable[int] = UNSET,
|
|
248
298
|
stream: Optional[bool] = True,
|
|
249
|
-
stop: Optional[
|
|
299
|
+
stop: Optional[
|
|
300
|
+
Union[
|
|
301
|
+
models.ChatCompletionStreamRequestStop,
|
|
302
|
+
models.ChatCompletionStreamRequestStopTypedDict,
|
|
303
|
+
]
|
|
304
|
+
] = None,
|
|
250
305
|
random_seed: OptionalNullable[int] = UNSET,
|
|
251
|
-
response_format: Optional[
|
|
252
|
-
|
|
253
|
-
|
|
306
|
+
response_format: Optional[
|
|
307
|
+
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
308
|
+
] = None,
|
|
309
|
+
tools: OptionalNullable[
|
|
310
|
+
Union[List[models.Tool], List[models.ToolTypedDict]]
|
|
311
|
+
] = UNSET,
|
|
312
|
+
tool_choice: Optional[
|
|
313
|
+
Union[
|
|
314
|
+
models.ChatCompletionStreamRequestToolChoice,
|
|
315
|
+
models.ChatCompletionStreamRequestToolChoiceTypedDict,
|
|
316
|
+
]
|
|
317
|
+
] = None,
|
|
254
318
|
safe_prompt: Optional[bool] = False,
|
|
255
319
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
256
320
|
server_url: Optional[str] = None,
|
|
@@ -266,12 +330,12 @@ class Chat(BaseSDK):
|
|
|
266
330
|
:param top_p: Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
|
|
267
331
|
:param max_tokens: The maximum number of tokens to generate in the completion. The token count of your prompt plus `max_tokens` cannot exceed the model's context length.
|
|
268
332
|
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
269
|
-
:param stream:
|
|
333
|
+
:param stream:
|
|
270
334
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
271
335
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
272
|
-
:param response_format:
|
|
273
|
-
:param tools:
|
|
274
|
-
:param tool_choice:
|
|
336
|
+
:param response_format:
|
|
337
|
+
:param tools:
|
|
338
|
+
:param tool_choice:
|
|
275
339
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
276
340
|
:param retries: Override the default retry configuration for this method
|
|
277
341
|
:param server_url: Override the default server URL for this method
|
|
@@ -281,10 +345,10 @@ class Chat(BaseSDK):
|
|
|
281
345
|
url_variables = None
|
|
282
346
|
if timeout_ms is None:
|
|
283
347
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
284
|
-
|
|
348
|
+
|
|
285
349
|
if server_url is not None:
|
|
286
350
|
base_url = server_url
|
|
287
|
-
|
|
351
|
+
|
|
288
352
|
request = models.ChatCompletionStreamRequest(
|
|
289
353
|
model=model,
|
|
290
354
|
temperature=temperature,
|
|
@@ -294,13 +358,19 @@ class Chat(BaseSDK):
|
|
|
294
358
|
stream=stream,
|
|
295
359
|
stop=stop,
|
|
296
360
|
random_seed=random_seed,
|
|
297
|
-
messages=utils.get_pydantic_model(
|
|
298
|
-
|
|
361
|
+
messages=utils.get_pydantic_model(
|
|
362
|
+
messages, List[models.ChatCompletionStreamRequestMessages]
|
|
363
|
+
),
|
|
364
|
+
response_format=utils.get_pydantic_model(
|
|
365
|
+
response_format, Optional[models.ResponseFormat]
|
|
366
|
+
),
|
|
299
367
|
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
300
|
-
tool_choice=
|
|
368
|
+
tool_choice=utils.get_pydantic_model(
|
|
369
|
+
tool_choice, Optional[models.ChatCompletionStreamRequestToolChoice]
|
|
370
|
+
),
|
|
301
371
|
safe_prompt=safe_prompt,
|
|
302
372
|
)
|
|
303
|
-
|
|
373
|
+
|
|
304
374
|
req = self.build_request(
|
|
305
375
|
method="POST",
|
|
306
376
|
path="/v1/chat/completions#stream",
|
|
@@ -313,60 +383,89 @@ class Chat(BaseSDK):
|
|
|
313
383
|
user_agent_header="user-agent",
|
|
314
384
|
accept_header_value="text/event-stream",
|
|
315
385
|
security=self.sdk_configuration.security,
|
|
316
|
-
get_serialized_body=lambda: utils.serialize_request_body(
|
|
386
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
387
|
+
request, False, False, "json", models.ChatCompletionStreamRequest
|
|
388
|
+
),
|
|
317
389
|
timeout_ms=timeout_ms,
|
|
318
390
|
)
|
|
319
|
-
|
|
391
|
+
|
|
320
392
|
if retries == UNSET:
|
|
321
393
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
322
394
|
retries = self.sdk_configuration.retry_config
|
|
323
395
|
|
|
324
396
|
retry_config = None
|
|
325
397
|
if isinstance(retries, utils.RetryConfig):
|
|
326
|
-
retry_config = (retries, [
|
|
327
|
-
|
|
328
|
-
"500",
|
|
329
|
-
"502",
|
|
330
|
-
"503",
|
|
331
|
-
"504"
|
|
332
|
-
])
|
|
333
|
-
|
|
398
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
399
|
+
|
|
334
400
|
http_res = self.do_request(
|
|
335
|
-
hook_ctx=HookContext(
|
|
401
|
+
hook_ctx=HookContext(
|
|
402
|
+
operation_id="stream_chat",
|
|
403
|
+
oauth2_scopes=[],
|
|
404
|
+
security_source=get_security_from_env(
|
|
405
|
+
self.sdk_configuration.security, models.Security
|
|
406
|
+
),
|
|
407
|
+
),
|
|
336
408
|
request=req,
|
|
337
|
-
error_status_codes=["422","4XX","5XX"],
|
|
409
|
+
error_status_codes=["422", "4XX", "5XX"],
|
|
338
410
|
stream=True,
|
|
339
|
-
retry_config=retry_config
|
|
411
|
+
retry_config=retry_config,
|
|
340
412
|
)
|
|
341
|
-
|
|
413
|
+
|
|
342
414
|
data: Any = None
|
|
343
415
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
344
|
-
return eventstreaming.stream_events(
|
|
416
|
+
return eventstreaming.stream_events(
|
|
417
|
+
http_res,
|
|
418
|
+
lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
|
|
419
|
+
sentinel="[DONE]",
|
|
420
|
+
)
|
|
345
421
|
if utils.match_response(http_res, "422", "application/json"):
|
|
346
422
|
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
347
423
|
raise models.HTTPValidationError(data=data)
|
|
348
|
-
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
349
|
-
raise models.SDKError(
|
|
350
|
-
|
|
424
|
+
if utils.match_response(http_res, ["4XX", "5XX"], "*"):
|
|
425
|
+
raise models.SDKError(
|
|
426
|
+
"API error occurred", http_res.status_code, http_res.text, http_res
|
|
427
|
+
)
|
|
428
|
+
|
|
351
429
|
content_type = http_res.headers.get("Content-Type")
|
|
352
|
-
raise models.SDKError(
|
|
430
|
+
raise models.SDKError(
|
|
431
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
432
|
+
http_res.status_code,
|
|
433
|
+
http_res.text,
|
|
434
|
+
http_res,
|
|
435
|
+
)
|
|
353
436
|
|
|
354
|
-
|
|
355
|
-
|
|
356
437
|
async def stream_async(
|
|
357
|
-
self,
|
|
438
|
+
self,
|
|
439
|
+
*,
|
|
358
440
|
model: Nullable[str],
|
|
359
|
-
messages: Union[
|
|
441
|
+
messages: Union[
|
|
442
|
+
List[models.ChatCompletionStreamRequestMessages],
|
|
443
|
+
List[models.ChatCompletionStreamRequestMessagesTypedDict],
|
|
444
|
+
],
|
|
360
445
|
temperature: Optional[float] = 0.7,
|
|
361
446
|
top_p: Optional[float] = 1,
|
|
362
447
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
363
448
|
min_tokens: OptionalNullable[int] = UNSET,
|
|
364
449
|
stream: Optional[bool] = True,
|
|
365
|
-
stop: Optional[
|
|
450
|
+
stop: Optional[
|
|
451
|
+
Union[
|
|
452
|
+
models.ChatCompletionStreamRequestStop,
|
|
453
|
+
models.ChatCompletionStreamRequestStopTypedDict,
|
|
454
|
+
]
|
|
455
|
+
] = None,
|
|
366
456
|
random_seed: OptionalNullable[int] = UNSET,
|
|
367
|
-
response_format: Optional[
|
|
368
|
-
|
|
369
|
-
|
|
457
|
+
response_format: Optional[
|
|
458
|
+
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
459
|
+
] = None,
|
|
460
|
+
tools: OptionalNullable[
|
|
461
|
+
Union[List[models.Tool], List[models.ToolTypedDict]]
|
|
462
|
+
] = UNSET,
|
|
463
|
+
tool_choice: Optional[
|
|
464
|
+
Union[
|
|
465
|
+
models.ChatCompletionStreamRequestToolChoice,
|
|
466
|
+
models.ChatCompletionStreamRequestToolChoiceTypedDict,
|
|
467
|
+
]
|
|
468
|
+
] = None,
|
|
370
469
|
safe_prompt: Optional[bool] = False,
|
|
371
470
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
372
471
|
server_url: Optional[str] = None,
|
|
@@ -382,12 +481,12 @@ class Chat(BaseSDK):
|
|
|
382
481
|
:param top_p: Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
|
|
383
482
|
:param max_tokens: The maximum number of tokens to generate in the completion. The token count of your prompt plus `max_tokens` cannot exceed the model's context length.
|
|
384
483
|
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
385
|
-
:param stream:
|
|
484
|
+
:param stream:
|
|
386
485
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
387
486
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
388
|
-
:param response_format:
|
|
389
|
-
:param tools:
|
|
390
|
-
:param tool_choice:
|
|
487
|
+
:param response_format:
|
|
488
|
+
:param tools:
|
|
489
|
+
:param tool_choice:
|
|
391
490
|
:param safe_prompt: Whether to inject a safety prompt before all conversations.
|
|
392
491
|
:param retries: Override the default retry configuration for this method
|
|
393
492
|
:param server_url: Override the default server URL for this method
|
|
@@ -397,10 +496,10 @@ class Chat(BaseSDK):
|
|
|
397
496
|
url_variables = None
|
|
398
497
|
if timeout_ms is None:
|
|
399
498
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
400
|
-
|
|
499
|
+
|
|
401
500
|
if server_url is not None:
|
|
402
501
|
base_url = server_url
|
|
403
|
-
|
|
502
|
+
|
|
404
503
|
request = models.ChatCompletionStreamRequest(
|
|
405
504
|
model=model,
|
|
406
505
|
temperature=temperature,
|
|
@@ -410,14 +509,20 @@ class Chat(BaseSDK):
|
|
|
410
509
|
stream=stream,
|
|
411
510
|
stop=stop,
|
|
412
511
|
random_seed=random_seed,
|
|
413
|
-
messages=utils.get_pydantic_model(
|
|
414
|
-
|
|
512
|
+
messages=utils.get_pydantic_model(
|
|
513
|
+
messages, List[models.ChatCompletionStreamRequestMessages]
|
|
514
|
+
),
|
|
515
|
+
response_format=utils.get_pydantic_model(
|
|
516
|
+
response_format, Optional[models.ResponseFormat]
|
|
517
|
+
),
|
|
415
518
|
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
416
|
-
tool_choice=
|
|
519
|
+
tool_choice=utils.get_pydantic_model(
|
|
520
|
+
tool_choice, Optional[models.ChatCompletionStreamRequestToolChoice]
|
|
521
|
+
),
|
|
417
522
|
safe_prompt=safe_prompt,
|
|
418
523
|
)
|
|
419
|
-
|
|
420
|
-
req = self.
|
|
524
|
+
|
|
525
|
+
req = self.build_request_async(
|
|
421
526
|
method="POST",
|
|
422
527
|
path="/v1/chat/completions#stream",
|
|
423
528
|
base_url=base_url,
|
|
@@ -429,42 +534,53 @@ class Chat(BaseSDK):
|
|
|
429
534
|
user_agent_header="user-agent",
|
|
430
535
|
accept_header_value="text/event-stream",
|
|
431
536
|
security=self.sdk_configuration.security,
|
|
432
|
-
get_serialized_body=lambda: utils.serialize_request_body(
|
|
537
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
538
|
+
request, False, False, "json", models.ChatCompletionStreamRequest
|
|
539
|
+
),
|
|
433
540
|
timeout_ms=timeout_ms,
|
|
434
541
|
)
|
|
435
|
-
|
|
542
|
+
|
|
436
543
|
if retries == UNSET:
|
|
437
544
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
438
545
|
retries = self.sdk_configuration.retry_config
|
|
439
546
|
|
|
440
547
|
retry_config = None
|
|
441
548
|
if isinstance(retries, utils.RetryConfig):
|
|
442
|
-
retry_config = (retries, [
|
|
443
|
-
|
|
444
|
-
"500",
|
|
445
|
-
"502",
|
|
446
|
-
"503",
|
|
447
|
-
"504"
|
|
448
|
-
])
|
|
449
|
-
|
|
549
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
550
|
+
|
|
450
551
|
http_res = await self.do_request_async(
|
|
451
|
-
hook_ctx=HookContext(
|
|
552
|
+
hook_ctx=HookContext(
|
|
553
|
+
operation_id="stream_chat",
|
|
554
|
+
oauth2_scopes=[],
|
|
555
|
+
security_source=get_security_from_env(
|
|
556
|
+
self.sdk_configuration.security, models.Security
|
|
557
|
+
),
|
|
558
|
+
),
|
|
452
559
|
request=req,
|
|
453
|
-
error_status_codes=["422","4XX","5XX"],
|
|
560
|
+
error_status_codes=["422", "4XX", "5XX"],
|
|
454
561
|
stream=True,
|
|
455
|
-
retry_config=retry_config
|
|
562
|
+
retry_config=retry_config,
|
|
456
563
|
)
|
|
457
|
-
|
|
564
|
+
|
|
458
565
|
data: Any = None
|
|
459
566
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
460
|
-
return eventstreaming.stream_events_async(
|
|
567
|
+
return eventstreaming.stream_events_async(
|
|
568
|
+
http_res,
|
|
569
|
+
lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
|
|
570
|
+
sentinel="[DONE]",
|
|
571
|
+
)
|
|
461
572
|
if utils.match_response(http_res, "422", "application/json"):
|
|
462
573
|
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
463
574
|
raise models.HTTPValidationError(data=data)
|
|
464
|
-
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
465
|
-
raise models.SDKError(
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
575
|
+
if utils.match_response(http_res, ["4XX", "5XX"], "*"):
|
|
576
|
+
raise models.SDKError(
|
|
577
|
+
"API error occurred", http_res.status_code, http_res.text, http_res
|
|
578
|
+
)
|
|
469
579
|
|
|
470
|
-
|
|
580
|
+
content_type = http_res.headers.get("Content-Type")
|
|
581
|
+
raise models.SDKError(
|
|
582
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
583
|
+
http_res.status_code,
|
|
584
|
+
http_res.text,
|
|
585
|
+
http_res,
|
|
586
|
+
)
|