mistralai 1.0.3__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.3.dist-info → mistralai-1.1.0.dist-info}/METADATA +102 -73
- 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 +6 -7
- 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.3.dist-info/RECORD +0 -236
- {mistralai-1.0.3.dist-info → mistralai-1.1.0.dist-info}/LICENSE +0 -0
- {mistralai-1.0.3.dist-info → mistralai-1.1.0.dist-info}/WHEEL +0 -0
mistralai/agents.py
CHANGED
|
@@ -7,22 +7,40 @@ from mistralai.types import 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 Agents(BaseSDK):
|
|
11
12
|
r"""Agents API."""
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
|
|
14
14
|
def complete(
|
|
15
|
-
self,
|
|
16
|
-
|
|
15
|
+
self,
|
|
16
|
+
*,
|
|
17
|
+
messages: Union[
|
|
18
|
+
List[models.AgentsCompletionRequestMessages],
|
|
19
|
+
List[models.AgentsCompletionRequestMessagesTypedDict],
|
|
20
|
+
],
|
|
17
21
|
agent_id: str,
|
|
18
22
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
19
23
|
min_tokens: OptionalNullable[int] = UNSET,
|
|
20
24
|
stream: Optional[bool] = False,
|
|
21
|
-
stop: Optional[
|
|
25
|
+
stop: Optional[
|
|
26
|
+
Union[
|
|
27
|
+
models.AgentsCompletionRequestStop,
|
|
28
|
+
models.AgentsCompletionRequestStopTypedDict,
|
|
29
|
+
]
|
|
30
|
+
] = None,
|
|
22
31
|
random_seed: OptionalNullable[int] = UNSET,
|
|
23
|
-
response_format: Optional[
|
|
24
|
-
|
|
25
|
-
|
|
32
|
+
response_format: Optional[
|
|
33
|
+
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
34
|
+
] = None,
|
|
35
|
+
tools: OptionalNullable[
|
|
36
|
+
Union[List[models.Tool], List[models.ToolTypedDict]]
|
|
37
|
+
] = UNSET,
|
|
38
|
+
tool_choice: Optional[
|
|
39
|
+
Union[
|
|
40
|
+
models.AgentsCompletionRequestToolChoice,
|
|
41
|
+
models.AgentsCompletionRequestToolChoiceTypedDict,
|
|
42
|
+
]
|
|
43
|
+
] = None,
|
|
26
44
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
27
45
|
server_url: Optional[str] = None,
|
|
28
46
|
timeout_ms: Optional[int] = None,
|
|
@@ -36,9 +54,9 @@ class Agents(BaseSDK):
|
|
|
36
54
|
: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.
|
|
37
55
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
38
56
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
39
|
-
:param response_format:
|
|
40
|
-
:param tools:
|
|
41
|
-
:param tool_choice:
|
|
57
|
+
:param response_format:
|
|
58
|
+
:param tools:
|
|
59
|
+
:param tool_choice:
|
|
42
60
|
:param retries: Override the default retry configuration for this method
|
|
43
61
|
:param server_url: Override the default server URL for this method
|
|
44
62
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -47,23 +65,29 @@ class Agents(BaseSDK):
|
|
|
47
65
|
url_variables = None
|
|
48
66
|
if timeout_ms is None:
|
|
49
67
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
50
|
-
|
|
68
|
+
|
|
51
69
|
if server_url is not None:
|
|
52
70
|
base_url = server_url
|
|
53
|
-
|
|
71
|
+
|
|
54
72
|
request = models.AgentsCompletionRequest(
|
|
55
73
|
max_tokens=max_tokens,
|
|
56
74
|
min_tokens=min_tokens,
|
|
57
75
|
stream=stream,
|
|
58
76
|
stop=stop,
|
|
59
77
|
random_seed=random_seed,
|
|
60
|
-
messages=utils.get_pydantic_model(
|
|
61
|
-
|
|
78
|
+
messages=utils.get_pydantic_model(
|
|
79
|
+
messages, List[models.AgentsCompletionRequestMessages]
|
|
80
|
+
),
|
|
81
|
+
response_format=utils.get_pydantic_model(
|
|
82
|
+
response_format, Optional[models.ResponseFormat]
|
|
83
|
+
),
|
|
62
84
|
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
63
|
-
tool_choice=
|
|
85
|
+
tool_choice=utils.get_pydantic_model(
|
|
86
|
+
tool_choice, Optional[models.AgentsCompletionRequestToolChoice]
|
|
87
|
+
),
|
|
64
88
|
agent_id=agent_id,
|
|
65
89
|
)
|
|
66
|
-
|
|
90
|
+
|
|
67
91
|
req = self.build_request(
|
|
68
92
|
method="POST",
|
|
69
93
|
path="/v1/agents/completions",
|
|
@@ -76,57 +100,84 @@ class Agents(BaseSDK):
|
|
|
76
100
|
user_agent_header="user-agent",
|
|
77
101
|
accept_header_value="application/json",
|
|
78
102
|
security=self.sdk_configuration.security,
|
|
79
|
-
get_serialized_body=lambda: utils.serialize_request_body(
|
|
103
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
104
|
+
request, False, False, "json", models.AgentsCompletionRequest
|
|
105
|
+
),
|
|
80
106
|
timeout_ms=timeout_ms,
|
|
81
107
|
)
|
|
82
|
-
|
|
108
|
+
|
|
83
109
|
if retries == UNSET:
|
|
84
110
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
85
111
|
retries = self.sdk_configuration.retry_config
|
|
86
112
|
|
|
87
113
|
retry_config = None
|
|
88
114
|
if isinstance(retries, utils.RetryConfig):
|
|
89
|
-
retry_config = (retries, [
|
|
90
|
-
|
|
91
|
-
"500",
|
|
92
|
-
"502",
|
|
93
|
-
"503",
|
|
94
|
-
"504"
|
|
95
|
-
])
|
|
96
|
-
|
|
115
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
116
|
+
|
|
97
117
|
http_res = self.do_request(
|
|
98
|
-
hook_ctx=HookContext(
|
|
118
|
+
hook_ctx=HookContext(
|
|
119
|
+
operation_id="agents_completion_v1_agents_completions_post",
|
|
120
|
+
oauth2_scopes=[],
|
|
121
|
+
security_source=get_security_from_env(
|
|
122
|
+
self.sdk_configuration.security, models.Security
|
|
123
|
+
),
|
|
124
|
+
),
|
|
99
125
|
request=req,
|
|
100
|
-
error_status_codes=["422","4XX","5XX"],
|
|
101
|
-
retry_config=retry_config
|
|
126
|
+
error_status_codes=["422", "4XX", "5XX"],
|
|
127
|
+
retry_config=retry_config,
|
|
102
128
|
)
|
|
103
|
-
|
|
129
|
+
|
|
104
130
|
data: Any = None
|
|
105
131
|
if utils.match_response(http_res, "200", "application/json"):
|
|
106
|
-
return utils.unmarshal_json(
|
|
132
|
+
return utils.unmarshal_json(
|
|
133
|
+
http_res.text, Optional[models.ChatCompletionResponse]
|
|
134
|
+
)
|
|
107
135
|
if utils.match_response(http_res, "422", "application/json"):
|
|
108
136
|
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
109
137
|
raise models.HTTPValidationError(data=data)
|
|
110
|
-
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
111
|
-
raise models.SDKError(
|
|
112
|
-
|
|
138
|
+
if utils.match_response(http_res, ["4XX", "5XX"], "*"):
|
|
139
|
+
raise models.SDKError(
|
|
140
|
+
"API error occurred", http_res.status_code, http_res.text, http_res
|
|
141
|
+
)
|
|
142
|
+
|
|
113
143
|
content_type = http_res.headers.get("Content-Type")
|
|
114
|
-
raise models.SDKError(
|
|
144
|
+
raise models.SDKError(
|
|
145
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
146
|
+
http_res.status_code,
|
|
147
|
+
http_res.text,
|
|
148
|
+
http_res,
|
|
149
|
+
)
|
|
115
150
|
|
|
116
|
-
|
|
117
|
-
|
|
118
151
|
async def complete_async(
|
|
119
|
-
self,
|
|
120
|
-
|
|
152
|
+
self,
|
|
153
|
+
*,
|
|
154
|
+
messages: Union[
|
|
155
|
+
List[models.AgentsCompletionRequestMessages],
|
|
156
|
+
List[models.AgentsCompletionRequestMessagesTypedDict],
|
|
157
|
+
],
|
|
121
158
|
agent_id: str,
|
|
122
159
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
123
160
|
min_tokens: OptionalNullable[int] = UNSET,
|
|
124
161
|
stream: Optional[bool] = False,
|
|
125
|
-
stop: Optional[
|
|
162
|
+
stop: Optional[
|
|
163
|
+
Union[
|
|
164
|
+
models.AgentsCompletionRequestStop,
|
|
165
|
+
models.AgentsCompletionRequestStopTypedDict,
|
|
166
|
+
]
|
|
167
|
+
] = None,
|
|
126
168
|
random_seed: OptionalNullable[int] = UNSET,
|
|
127
|
-
response_format: Optional[
|
|
128
|
-
|
|
129
|
-
|
|
169
|
+
response_format: Optional[
|
|
170
|
+
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
171
|
+
] = None,
|
|
172
|
+
tools: OptionalNullable[
|
|
173
|
+
Union[List[models.Tool], List[models.ToolTypedDict]]
|
|
174
|
+
] = UNSET,
|
|
175
|
+
tool_choice: Optional[
|
|
176
|
+
Union[
|
|
177
|
+
models.AgentsCompletionRequestToolChoice,
|
|
178
|
+
models.AgentsCompletionRequestToolChoiceTypedDict,
|
|
179
|
+
]
|
|
180
|
+
] = None,
|
|
130
181
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
131
182
|
server_url: Optional[str] = None,
|
|
132
183
|
timeout_ms: Optional[int] = None,
|
|
@@ -140,9 +191,9 @@ class Agents(BaseSDK):
|
|
|
140
191
|
: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.
|
|
141
192
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
142
193
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
143
|
-
:param response_format:
|
|
144
|
-
:param tools:
|
|
145
|
-
:param tool_choice:
|
|
194
|
+
:param response_format:
|
|
195
|
+
:param tools:
|
|
196
|
+
:param tool_choice:
|
|
146
197
|
:param retries: Override the default retry configuration for this method
|
|
147
198
|
:param server_url: Override the default server URL for this method
|
|
148
199
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -151,24 +202,30 @@ class Agents(BaseSDK):
|
|
|
151
202
|
url_variables = None
|
|
152
203
|
if timeout_ms is None:
|
|
153
204
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
154
|
-
|
|
205
|
+
|
|
155
206
|
if server_url is not None:
|
|
156
207
|
base_url = server_url
|
|
157
|
-
|
|
208
|
+
|
|
158
209
|
request = models.AgentsCompletionRequest(
|
|
159
210
|
max_tokens=max_tokens,
|
|
160
211
|
min_tokens=min_tokens,
|
|
161
212
|
stream=stream,
|
|
162
213
|
stop=stop,
|
|
163
214
|
random_seed=random_seed,
|
|
164
|
-
messages=utils.get_pydantic_model(
|
|
165
|
-
|
|
215
|
+
messages=utils.get_pydantic_model(
|
|
216
|
+
messages, List[models.AgentsCompletionRequestMessages]
|
|
217
|
+
),
|
|
218
|
+
response_format=utils.get_pydantic_model(
|
|
219
|
+
response_format, Optional[models.ResponseFormat]
|
|
220
|
+
),
|
|
166
221
|
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
167
|
-
tool_choice=
|
|
222
|
+
tool_choice=utils.get_pydantic_model(
|
|
223
|
+
tool_choice, Optional[models.AgentsCompletionRequestToolChoice]
|
|
224
|
+
),
|
|
168
225
|
agent_id=agent_id,
|
|
169
226
|
)
|
|
170
|
-
|
|
171
|
-
req = self.
|
|
227
|
+
|
|
228
|
+
req = self.build_request_async(
|
|
172
229
|
method="POST",
|
|
173
230
|
path="/v1/agents/completions",
|
|
174
231
|
base_url=base_url,
|
|
@@ -180,57 +237,84 @@ class Agents(BaseSDK):
|
|
|
180
237
|
user_agent_header="user-agent",
|
|
181
238
|
accept_header_value="application/json",
|
|
182
239
|
security=self.sdk_configuration.security,
|
|
183
|
-
get_serialized_body=lambda: utils.serialize_request_body(
|
|
240
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
241
|
+
request, False, False, "json", models.AgentsCompletionRequest
|
|
242
|
+
),
|
|
184
243
|
timeout_ms=timeout_ms,
|
|
185
244
|
)
|
|
186
|
-
|
|
245
|
+
|
|
187
246
|
if retries == UNSET:
|
|
188
247
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
189
248
|
retries = self.sdk_configuration.retry_config
|
|
190
249
|
|
|
191
250
|
retry_config = None
|
|
192
251
|
if isinstance(retries, utils.RetryConfig):
|
|
193
|
-
retry_config = (retries, [
|
|
194
|
-
|
|
195
|
-
"500",
|
|
196
|
-
"502",
|
|
197
|
-
"503",
|
|
198
|
-
"504"
|
|
199
|
-
])
|
|
200
|
-
|
|
252
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
253
|
+
|
|
201
254
|
http_res = await self.do_request_async(
|
|
202
|
-
hook_ctx=HookContext(
|
|
255
|
+
hook_ctx=HookContext(
|
|
256
|
+
operation_id="agents_completion_v1_agents_completions_post",
|
|
257
|
+
oauth2_scopes=[],
|
|
258
|
+
security_source=get_security_from_env(
|
|
259
|
+
self.sdk_configuration.security, models.Security
|
|
260
|
+
),
|
|
261
|
+
),
|
|
203
262
|
request=req,
|
|
204
|
-
error_status_codes=["422","4XX","5XX"],
|
|
205
|
-
retry_config=retry_config
|
|
263
|
+
error_status_codes=["422", "4XX", "5XX"],
|
|
264
|
+
retry_config=retry_config,
|
|
206
265
|
)
|
|
207
|
-
|
|
266
|
+
|
|
208
267
|
data: Any = None
|
|
209
268
|
if utils.match_response(http_res, "200", "application/json"):
|
|
210
|
-
return utils.unmarshal_json(
|
|
269
|
+
return utils.unmarshal_json(
|
|
270
|
+
http_res.text, Optional[models.ChatCompletionResponse]
|
|
271
|
+
)
|
|
211
272
|
if utils.match_response(http_res, "422", "application/json"):
|
|
212
273
|
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
213
274
|
raise models.HTTPValidationError(data=data)
|
|
214
|
-
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
215
|
-
raise models.SDKError(
|
|
216
|
-
|
|
275
|
+
if utils.match_response(http_res, ["4XX", "5XX"], "*"):
|
|
276
|
+
raise models.SDKError(
|
|
277
|
+
"API error occurred", http_res.status_code, http_res.text, http_res
|
|
278
|
+
)
|
|
279
|
+
|
|
217
280
|
content_type = http_res.headers.get("Content-Type")
|
|
218
|
-
raise models.SDKError(
|
|
281
|
+
raise models.SDKError(
|
|
282
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
283
|
+
http_res.status_code,
|
|
284
|
+
http_res.text,
|
|
285
|
+
http_res,
|
|
286
|
+
)
|
|
219
287
|
|
|
220
|
-
|
|
221
|
-
|
|
222
288
|
def stream(
|
|
223
|
-
self,
|
|
224
|
-
|
|
289
|
+
self,
|
|
290
|
+
*,
|
|
291
|
+
messages: Union[
|
|
292
|
+
List[models.AgentsCompletionStreamRequestMessages],
|
|
293
|
+
List[models.AgentsCompletionStreamRequestMessagesTypedDict],
|
|
294
|
+
],
|
|
225
295
|
agent_id: str,
|
|
226
296
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
227
297
|
min_tokens: OptionalNullable[int] = UNSET,
|
|
228
298
|
stream: Optional[bool] = True,
|
|
229
|
-
stop: Optional[
|
|
299
|
+
stop: Optional[
|
|
300
|
+
Union[
|
|
301
|
+
models.AgentsCompletionStreamRequestStop,
|
|
302
|
+
models.AgentsCompletionStreamRequestStopTypedDict,
|
|
303
|
+
]
|
|
304
|
+
] = None,
|
|
230
305
|
random_seed: OptionalNullable[int] = UNSET,
|
|
231
|
-
response_format: Optional[
|
|
232
|
-
|
|
233
|
-
|
|
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.AgentsCompletionStreamRequestToolChoice,
|
|
315
|
+
models.AgentsCompletionStreamRequestToolChoiceTypedDict,
|
|
316
|
+
]
|
|
317
|
+
] = None,
|
|
234
318
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
235
319
|
server_url: Optional[str] = None,
|
|
236
320
|
timeout_ms: Optional[int] = None,
|
|
@@ -243,12 +327,12 @@ class Agents(BaseSDK):
|
|
|
243
327
|
:param agent_id: The ID of the agent to use for this completion.
|
|
244
328
|
: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.
|
|
245
329
|
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
246
|
-
:param stream:
|
|
330
|
+
:param stream:
|
|
247
331
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
248
332
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
249
|
-
:param response_format:
|
|
250
|
-
:param tools:
|
|
251
|
-
:param tool_choice:
|
|
333
|
+
:param response_format:
|
|
334
|
+
:param tools:
|
|
335
|
+
:param tool_choice:
|
|
252
336
|
:param retries: Override the default retry configuration for this method
|
|
253
337
|
:param server_url: Override the default server URL for this method
|
|
254
338
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -257,23 +341,29 @@ class Agents(BaseSDK):
|
|
|
257
341
|
url_variables = None
|
|
258
342
|
if timeout_ms is None:
|
|
259
343
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
260
|
-
|
|
344
|
+
|
|
261
345
|
if server_url is not None:
|
|
262
346
|
base_url = server_url
|
|
263
|
-
|
|
347
|
+
|
|
264
348
|
request = models.AgentsCompletionStreamRequest(
|
|
265
349
|
max_tokens=max_tokens,
|
|
266
350
|
min_tokens=min_tokens,
|
|
267
351
|
stream=stream,
|
|
268
352
|
stop=stop,
|
|
269
353
|
random_seed=random_seed,
|
|
270
|
-
messages=utils.get_pydantic_model(
|
|
271
|
-
|
|
354
|
+
messages=utils.get_pydantic_model(
|
|
355
|
+
messages, List[models.AgentsCompletionStreamRequestMessages]
|
|
356
|
+
),
|
|
357
|
+
response_format=utils.get_pydantic_model(
|
|
358
|
+
response_format, Optional[models.ResponseFormat]
|
|
359
|
+
),
|
|
272
360
|
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
273
|
-
tool_choice=
|
|
361
|
+
tool_choice=utils.get_pydantic_model(
|
|
362
|
+
tool_choice, Optional[models.AgentsCompletionStreamRequestToolChoice]
|
|
363
|
+
),
|
|
274
364
|
agent_id=agent_id,
|
|
275
365
|
)
|
|
276
|
-
|
|
366
|
+
|
|
277
367
|
req = self.build_request(
|
|
278
368
|
method="POST",
|
|
279
369
|
path="/v1/agents/completions#stream",
|
|
@@ -286,58 +376,87 @@ class Agents(BaseSDK):
|
|
|
286
376
|
user_agent_header="user-agent",
|
|
287
377
|
accept_header_value="text/event-stream",
|
|
288
378
|
security=self.sdk_configuration.security,
|
|
289
|
-
get_serialized_body=lambda: utils.serialize_request_body(
|
|
379
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
380
|
+
request, False, False, "json", models.AgentsCompletionStreamRequest
|
|
381
|
+
),
|
|
290
382
|
timeout_ms=timeout_ms,
|
|
291
383
|
)
|
|
292
|
-
|
|
384
|
+
|
|
293
385
|
if retries == UNSET:
|
|
294
386
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
295
387
|
retries = self.sdk_configuration.retry_config
|
|
296
388
|
|
|
297
389
|
retry_config = None
|
|
298
390
|
if isinstance(retries, utils.RetryConfig):
|
|
299
|
-
retry_config = (retries, [
|
|
300
|
-
|
|
301
|
-
"500",
|
|
302
|
-
"502",
|
|
303
|
-
"503",
|
|
304
|
-
"504"
|
|
305
|
-
])
|
|
306
|
-
|
|
391
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
392
|
+
|
|
307
393
|
http_res = self.do_request(
|
|
308
|
-
hook_ctx=HookContext(
|
|
394
|
+
hook_ctx=HookContext(
|
|
395
|
+
operation_id="stream_agents",
|
|
396
|
+
oauth2_scopes=[],
|
|
397
|
+
security_source=get_security_from_env(
|
|
398
|
+
self.sdk_configuration.security, models.Security
|
|
399
|
+
),
|
|
400
|
+
),
|
|
309
401
|
request=req,
|
|
310
|
-
error_status_codes=["422","4XX","5XX"],
|
|
402
|
+
error_status_codes=["422", "4XX", "5XX"],
|
|
311
403
|
stream=True,
|
|
312
|
-
retry_config=retry_config
|
|
404
|
+
retry_config=retry_config,
|
|
313
405
|
)
|
|
314
|
-
|
|
406
|
+
|
|
315
407
|
data: Any = None
|
|
316
408
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
317
|
-
return eventstreaming.stream_events(
|
|
409
|
+
return eventstreaming.stream_events(
|
|
410
|
+
http_res,
|
|
411
|
+
lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
|
|
412
|
+
sentinel="[DONE]",
|
|
413
|
+
)
|
|
318
414
|
if utils.match_response(http_res, "422", "application/json"):
|
|
319
415
|
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
320
416
|
raise models.HTTPValidationError(data=data)
|
|
321
|
-
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
322
|
-
raise models.SDKError(
|
|
323
|
-
|
|
417
|
+
if utils.match_response(http_res, ["4XX", "5XX"], "*"):
|
|
418
|
+
raise models.SDKError(
|
|
419
|
+
"API error occurred", http_res.status_code, http_res.text, http_res
|
|
420
|
+
)
|
|
421
|
+
|
|
324
422
|
content_type = http_res.headers.get("Content-Type")
|
|
325
|
-
raise models.SDKError(
|
|
423
|
+
raise models.SDKError(
|
|
424
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
425
|
+
http_res.status_code,
|
|
426
|
+
http_res.text,
|
|
427
|
+
http_res,
|
|
428
|
+
)
|
|
326
429
|
|
|
327
|
-
|
|
328
|
-
|
|
329
430
|
async def stream_async(
|
|
330
|
-
self,
|
|
331
|
-
|
|
431
|
+
self,
|
|
432
|
+
*,
|
|
433
|
+
messages: Union[
|
|
434
|
+
List[models.AgentsCompletionStreamRequestMessages],
|
|
435
|
+
List[models.AgentsCompletionStreamRequestMessagesTypedDict],
|
|
436
|
+
],
|
|
332
437
|
agent_id: str,
|
|
333
438
|
max_tokens: OptionalNullable[int] = UNSET,
|
|
334
439
|
min_tokens: OptionalNullable[int] = UNSET,
|
|
335
440
|
stream: Optional[bool] = True,
|
|
336
|
-
stop: Optional[
|
|
441
|
+
stop: Optional[
|
|
442
|
+
Union[
|
|
443
|
+
models.AgentsCompletionStreamRequestStop,
|
|
444
|
+
models.AgentsCompletionStreamRequestStopTypedDict,
|
|
445
|
+
]
|
|
446
|
+
] = None,
|
|
337
447
|
random_seed: OptionalNullable[int] = UNSET,
|
|
338
|
-
response_format: Optional[
|
|
339
|
-
|
|
340
|
-
|
|
448
|
+
response_format: Optional[
|
|
449
|
+
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
450
|
+
] = None,
|
|
451
|
+
tools: OptionalNullable[
|
|
452
|
+
Union[List[models.Tool], List[models.ToolTypedDict]]
|
|
453
|
+
] = UNSET,
|
|
454
|
+
tool_choice: Optional[
|
|
455
|
+
Union[
|
|
456
|
+
models.AgentsCompletionStreamRequestToolChoice,
|
|
457
|
+
models.AgentsCompletionStreamRequestToolChoiceTypedDict,
|
|
458
|
+
]
|
|
459
|
+
] = None,
|
|
341
460
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
342
461
|
server_url: Optional[str] = None,
|
|
343
462
|
timeout_ms: Optional[int] = None,
|
|
@@ -350,12 +469,12 @@ class Agents(BaseSDK):
|
|
|
350
469
|
:param agent_id: The ID of the agent to use for this completion.
|
|
351
470
|
: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.
|
|
352
471
|
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
353
|
-
:param stream:
|
|
472
|
+
:param stream:
|
|
354
473
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
355
474
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
356
|
-
:param response_format:
|
|
357
|
-
:param tools:
|
|
358
|
-
:param tool_choice:
|
|
475
|
+
:param response_format:
|
|
476
|
+
:param tools:
|
|
477
|
+
:param tool_choice:
|
|
359
478
|
:param retries: Override the default retry configuration for this method
|
|
360
479
|
:param server_url: Override the default server URL for this method
|
|
361
480
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -364,24 +483,30 @@ class Agents(BaseSDK):
|
|
|
364
483
|
url_variables = None
|
|
365
484
|
if timeout_ms is None:
|
|
366
485
|
timeout_ms = self.sdk_configuration.timeout_ms
|
|
367
|
-
|
|
486
|
+
|
|
368
487
|
if server_url is not None:
|
|
369
488
|
base_url = server_url
|
|
370
|
-
|
|
489
|
+
|
|
371
490
|
request = models.AgentsCompletionStreamRequest(
|
|
372
491
|
max_tokens=max_tokens,
|
|
373
492
|
min_tokens=min_tokens,
|
|
374
493
|
stream=stream,
|
|
375
494
|
stop=stop,
|
|
376
495
|
random_seed=random_seed,
|
|
377
|
-
messages=utils.get_pydantic_model(
|
|
378
|
-
|
|
496
|
+
messages=utils.get_pydantic_model(
|
|
497
|
+
messages, List[models.AgentsCompletionStreamRequestMessages]
|
|
498
|
+
),
|
|
499
|
+
response_format=utils.get_pydantic_model(
|
|
500
|
+
response_format, Optional[models.ResponseFormat]
|
|
501
|
+
),
|
|
379
502
|
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
380
|
-
tool_choice=
|
|
503
|
+
tool_choice=utils.get_pydantic_model(
|
|
504
|
+
tool_choice, Optional[models.AgentsCompletionStreamRequestToolChoice]
|
|
505
|
+
),
|
|
381
506
|
agent_id=agent_id,
|
|
382
507
|
)
|
|
383
|
-
|
|
384
|
-
req = self.
|
|
508
|
+
|
|
509
|
+
req = self.build_request_async(
|
|
385
510
|
method="POST",
|
|
386
511
|
path="/v1/agents/completions#stream",
|
|
387
512
|
base_url=base_url,
|
|
@@ -393,42 +518,53 @@ class Agents(BaseSDK):
|
|
|
393
518
|
user_agent_header="user-agent",
|
|
394
519
|
accept_header_value="text/event-stream",
|
|
395
520
|
security=self.sdk_configuration.security,
|
|
396
|
-
get_serialized_body=lambda: utils.serialize_request_body(
|
|
521
|
+
get_serialized_body=lambda: utils.serialize_request_body(
|
|
522
|
+
request, False, False, "json", models.AgentsCompletionStreamRequest
|
|
523
|
+
),
|
|
397
524
|
timeout_ms=timeout_ms,
|
|
398
525
|
)
|
|
399
|
-
|
|
526
|
+
|
|
400
527
|
if retries == UNSET:
|
|
401
528
|
if self.sdk_configuration.retry_config is not UNSET:
|
|
402
529
|
retries = self.sdk_configuration.retry_config
|
|
403
530
|
|
|
404
531
|
retry_config = None
|
|
405
532
|
if isinstance(retries, utils.RetryConfig):
|
|
406
|
-
retry_config = (retries, [
|
|
407
|
-
|
|
408
|
-
"500",
|
|
409
|
-
"502",
|
|
410
|
-
"503",
|
|
411
|
-
"504"
|
|
412
|
-
])
|
|
413
|
-
|
|
533
|
+
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
534
|
+
|
|
414
535
|
http_res = await self.do_request_async(
|
|
415
|
-
hook_ctx=HookContext(
|
|
536
|
+
hook_ctx=HookContext(
|
|
537
|
+
operation_id="stream_agents",
|
|
538
|
+
oauth2_scopes=[],
|
|
539
|
+
security_source=get_security_from_env(
|
|
540
|
+
self.sdk_configuration.security, models.Security
|
|
541
|
+
),
|
|
542
|
+
),
|
|
416
543
|
request=req,
|
|
417
|
-
error_status_codes=["422","4XX","5XX"],
|
|
544
|
+
error_status_codes=["422", "4XX", "5XX"],
|
|
418
545
|
stream=True,
|
|
419
|
-
retry_config=retry_config
|
|
546
|
+
retry_config=retry_config,
|
|
420
547
|
)
|
|
421
|
-
|
|
548
|
+
|
|
422
549
|
data: Any = None
|
|
423
550
|
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
424
|
-
return eventstreaming.stream_events_async(
|
|
551
|
+
return eventstreaming.stream_events_async(
|
|
552
|
+
http_res,
|
|
553
|
+
lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
|
|
554
|
+
sentinel="[DONE]",
|
|
555
|
+
)
|
|
425
556
|
if utils.match_response(http_res, "422", "application/json"):
|
|
426
557
|
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
427
558
|
raise models.HTTPValidationError(data=data)
|
|
428
|
-
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
429
|
-
raise models.SDKError(
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
559
|
+
if utils.match_response(http_res, ["4XX", "5XX"], "*"):
|
|
560
|
+
raise models.SDKError(
|
|
561
|
+
"API error occurred", http_res.status_code, http_res.text, http_res
|
|
562
|
+
)
|
|
433
563
|
|
|
434
|
-
|
|
564
|
+
content_type = http_res.headers.get("Content-Type")
|
|
565
|
+
raise models.SDKError(
|
|
566
|
+
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
567
|
+
http_res.status_code,
|
|
568
|
+
http_res.text,
|
|
569
|
+
http_res,
|
|
570
|
+
)
|