mistralai 1.10.0__py3-none-any.whl → 1.11.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.
- mistralai/_hooks/tracing.py +28 -3
- mistralai/_version.py +3 -3
- mistralai/accesses.py +22 -12
- mistralai/agents.py +88 -44
- mistralai/basesdk.py +6 -0
- mistralai/chat.py +96 -40
- mistralai/classifiers.py +48 -23
- mistralai/conversations.py +186 -64
- mistralai/documents.py +72 -26
- mistralai/embeddings.py +24 -9
- mistralai/extra/README.md +1 -1
- mistralai/extra/mcp/auth.py +10 -11
- mistralai/extra/mcp/base.py +17 -16
- mistralai/extra/mcp/sse.py +13 -15
- mistralai/extra/mcp/stdio.py +5 -6
- mistralai/extra/observability/otel.py +47 -68
- mistralai/extra/run/context.py +33 -43
- mistralai/extra/run/result.py +29 -30
- mistralai/extra/run/tools.py +8 -9
- mistralai/extra/struct_chat.py +15 -8
- mistralai/extra/utils/response_format.py +5 -3
- mistralai/files.py +58 -24
- mistralai/fim.py +20 -12
- mistralai/httpclient.py +0 -1
- mistralai/jobs.py +65 -26
- mistralai/libraries.py +20 -10
- mistralai/mistral_agents.py +438 -30
- mistralai/mistral_jobs.py +62 -17
- mistralai/models/__init__.py +46 -1
- mistralai/models/agent.py +1 -1
- mistralai/models/agentconversation.py +1 -1
- mistralai/models/agenthandoffdoneevent.py +1 -1
- mistralai/models/agenthandoffentry.py +3 -2
- mistralai/models/agenthandoffstartedevent.py +1 -1
- mistralai/models/agents_api_v1_agents_get_versionop.py +21 -0
- mistralai/models/agents_api_v1_agents_list_versionsop.py +33 -0
- mistralai/models/agents_api_v1_agents_listop.py +5 -1
- mistralai/models/agents_api_v1_conversations_listop.py +1 -1
- mistralai/models/agentscompletionrequest.py +2 -5
- mistralai/models/agentscompletionstreamrequest.py +2 -5
- mistralai/models/archiveftmodelout.py +1 -1
- mistralai/models/assistantmessage.py +1 -1
- mistralai/models/audiochunk.py +1 -1
- mistralai/models/audioencoding.py +18 -0
- mistralai/models/audioformat.py +17 -0
- mistralai/models/basemodelcard.py +1 -1
- mistralai/models/batchjobin.py +18 -9
- mistralai/models/batchjobout.py +6 -1
- mistralai/models/batchjobsout.py +1 -1
- mistralai/models/batchrequest.py +48 -0
- mistralai/models/chatcompletionchoice.py +10 -5
- mistralai/models/chatcompletionrequest.py +2 -5
- mistralai/models/chatcompletionstreamrequest.py +2 -5
- mistralai/models/classificationrequest.py +37 -3
- mistralai/models/classifierdetailedjobout.py +4 -2
- mistralai/models/classifierftmodelout.py +3 -2
- mistralai/models/classifierjobout.py +4 -2
- mistralai/models/codeinterpretertool.py +1 -1
- mistralai/models/completiondetailedjobout.py +5 -2
- mistralai/models/completionftmodelout.py +3 -2
- mistralai/models/completionjobout.py +5 -2
- mistralai/models/completionresponsestreamchoice.py +9 -8
- mistralai/models/conversationappendrequest.py +4 -1
- mistralai/models/conversationappendstreamrequest.py +4 -1
- mistralai/models/conversationhistory.py +2 -1
- mistralai/models/conversationmessages.py +1 -1
- mistralai/models/conversationrequest.py +5 -1
- mistralai/models/conversationresponse.py +2 -1
- mistralai/models/conversationrestartrequest.py +4 -1
- mistralai/models/conversationrestartstreamrequest.py +4 -1
- mistralai/models/conversationstreamrequest.py +5 -1
- mistralai/models/documentlibrarytool.py +1 -1
- mistralai/models/documenturlchunk.py +1 -1
- mistralai/models/embeddingdtype.py +7 -1
- mistralai/models/embeddingrequest.py +11 -3
- mistralai/models/encodingformat.py +4 -1
- mistralai/models/entitytype.py +8 -1
- mistralai/models/filepurpose.py +8 -1
- mistralai/models/files_api_routes_list_filesop.py +4 -11
- mistralai/models/files_api_routes_upload_fileop.py +2 -6
- mistralai/models/fileschema.py +3 -5
- mistralai/models/finetuneablemodeltype.py +4 -1
- mistralai/models/ftclassifierlossfunction.py +4 -1
- mistralai/models/ftmodelcard.py +1 -1
- mistralai/models/functioncallentry.py +3 -2
- mistralai/models/functioncallevent.py +1 -1
- mistralai/models/functionresultentry.py +3 -2
- mistralai/models/functiontool.py +1 -1
- mistralai/models/githubrepositoryin.py +1 -1
- mistralai/models/githubrepositoryout.py +1 -1
- mistralai/models/httpvalidationerror.py +4 -2
- mistralai/models/imagegenerationtool.py +1 -1
- mistralai/models/imageurlchunk.py +1 -1
- mistralai/models/jobs_api_routes_batch_get_batch_jobop.py +40 -3
- mistralai/models/jobsout.py +1 -1
- mistralai/models/legacyjobmetadataout.py +1 -1
- mistralai/models/messageinputentry.py +9 -3
- mistralai/models/messageoutputentry.py +6 -3
- mistralai/models/messageoutputevent.py +4 -2
- mistralai/models/mistralerror.py +11 -7
- mistralai/models/mistralpromptmode.py +1 -1
- mistralai/models/modelconversation.py +1 -1
- mistralai/models/no_response_error.py +5 -1
- mistralai/models/ocrrequest.py +11 -1
- mistralai/models/ocrtableobject.py +4 -1
- mistralai/models/referencechunk.py +1 -1
- mistralai/models/requestsource.py +5 -1
- mistralai/models/responsedoneevent.py +1 -1
- mistralai/models/responseerrorevent.py +1 -1
- mistralai/models/responseformats.py +5 -1
- mistralai/models/responsestartedevent.py +1 -1
- mistralai/models/responsevalidationerror.py +2 -0
- mistralai/models/retrievefileout.py +3 -5
- mistralai/models/sampletype.py +7 -1
- mistralai/models/sdkerror.py +2 -0
- mistralai/models/shareenum.py +7 -1
- mistralai/models/sharingdelete.py +2 -4
- mistralai/models/sharingin.py +3 -5
- mistralai/models/source.py +8 -1
- mistralai/models/systemmessage.py +1 -1
- mistralai/models/textchunk.py +1 -1
- mistralai/models/thinkchunk.py +1 -1
- mistralai/models/timestampgranularity.py +1 -1
- mistralai/models/tool.py +2 -6
- mistralai/models/toolcall.py +2 -6
- mistralai/models/toolchoice.py +2 -6
- mistralai/models/toolchoiceenum.py +6 -1
- mistralai/models/toolexecutiondeltaevent.py +2 -1
- mistralai/models/toolexecutiondoneevent.py +2 -1
- mistralai/models/toolexecutionentry.py +4 -2
- mistralai/models/toolexecutionstartedevent.py +2 -1
- mistralai/models/toolfilechunk.py +13 -5
- mistralai/models/toolmessage.py +1 -1
- mistralai/models/toolreferencechunk.py +15 -5
- mistralai/models/tooltypes.py +1 -1
- mistralai/models/transcriptionsegmentchunk.py +1 -1
- mistralai/models/transcriptionstreamdone.py +1 -1
- mistralai/models/transcriptionstreamlanguage.py +1 -1
- mistralai/models/transcriptionstreamsegmentdelta.py +1 -1
- mistralai/models/transcriptionstreamtextdelta.py +1 -1
- mistralai/models/unarchiveftmodelout.py +1 -1
- mistralai/models/uploadfileout.py +3 -5
- mistralai/models/usermessage.py +1 -1
- mistralai/models/wandbintegration.py +1 -1
- mistralai/models/wandbintegrationout.py +1 -1
- mistralai/models/websearchpremiumtool.py +1 -1
- mistralai/models/websearchtool.py +1 -1
- mistralai/models_.py +24 -12
- mistralai/ocr.py +38 -10
- mistralai/sdk.py +2 -2
- mistralai/transcriptions.py +28 -12
- mistralai/types/basemodel.py +41 -3
- mistralai/utils/__init__.py +0 -3
- mistralai/utils/annotations.py +32 -8
- mistralai/utils/enums.py +60 -0
- mistralai/utils/forms.py +21 -10
- mistralai/utils/queryparams.py +14 -2
- mistralai/utils/requestbodies.py +3 -3
- mistralai/utils/retries.py +69 -5
- mistralai/utils/serializers.py +0 -20
- mistralai/utils/unmarshal_json_response.py +15 -1
- {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/METADATA +144 -159
- mistralai-1.11.1.dist-info/RECORD +495 -0
- {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/WHEEL +1 -1
- mistralai_azure/_version.py +3 -3
- mistralai_azure/basesdk.py +21 -5
- mistralai_azure/chat.py +82 -109
- mistralai_azure/httpclient.py +0 -1
- mistralai_azure/models/__init__.py +66 -4
- mistralai_azure/models/assistantmessage.py +1 -1
- mistralai_azure/models/chatcompletionchoice.py +10 -7
- mistralai_azure/models/chatcompletionrequest.py +24 -10
- mistralai_azure/models/chatcompletionstreamrequest.py +24 -10
- mistralai_azure/models/completionresponsestreamchoice.py +11 -7
- mistralai_azure/models/documenturlchunk.py +1 -1
- mistralai_azure/models/httpvalidationerror.py +15 -8
- mistralai_azure/models/imageurlchunk.py +1 -1
- mistralai_azure/models/mistralazureerror.py +30 -0
- mistralai_azure/models/mistralpromptmode.py +1 -1
- mistralai_azure/models/no_response_error.py +17 -0
- mistralai_azure/models/ocrpageobject.py +32 -5
- mistralai_azure/models/ocrrequest.py +20 -1
- mistralai_azure/models/ocrtableobject.py +34 -0
- mistralai_azure/models/prediction.py +4 -0
- mistralai_azure/models/referencechunk.py +1 -1
- mistralai_azure/models/responseformat.py +4 -2
- mistralai_azure/models/responseformats.py +5 -2
- mistralai_azure/models/responsevalidationerror.py +27 -0
- mistralai_azure/models/sdkerror.py +32 -14
- mistralai_azure/models/systemmessage.py +8 -4
- mistralai_azure/models/systemmessagecontentchunks.py +21 -0
- mistralai_azure/models/textchunk.py +1 -1
- mistralai_azure/models/thinkchunk.py +35 -0
- mistralai_azure/models/tool.py +2 -6
- mistralai_azure/models/toolcall.py +2 -6
- mistralai_azure/models/toolchoice.py +2 -6
- mistralai_azure/models/toolchoiceenum.py +6 -1
- mistralai_azure/models/toolmessage.py +1 -1
- mistralai_azure/models/tooltypes.py +1 -1
- mistralai_azure/models/usermessage.py +1 -1
- mistralai_azure/ocr.py +39 -40
- mistralai_azure/types/basemodel.py +41 -3
- mistralai_azure/utils/__init__.py +18 -8
- mistralai_azure/utils/annotations.py +32 -8
- mistralai_azure/utils/enums.py +60 -0
- mistralai_azure/utils/eventstreaming.py +10 -0
- mistralai_azure/utils/forms.py +21 -10
- mistralai_azure/utils/queryparams.py +14 -2
- mistralai_azure/utils/requestbodies.py +3 -3
- mistralai_azure/utils/retries.py +69 -5
- mistralai_azure/utils/serializers.py +3 -22
- mistralai_azure/utils/unmarshal_json_response.py +38 -0
- mistralai_gcp/_hooks/types.py +7 -0
- mistralai_gcp/_version.py +4 -4
- mistralai_gcp/basesdk.py +33 -25
- mistralai_gcp/chat.py +98 -109
- mistralai_gcp/fim.py +62 -85
- mistralai_gcp/httpclient.py +6 -17
- mistralai_gcp/models/__init__.py +321 -116
- mistralai_gcp/models/assistantmessage.py +2 -2
- mistralai_gcp/models/chatcompletionchoice.py +10 -7
- mistralai_gcp/models/chatcompletionrequest.py +38 -7
- mistralai_gcp/models/chatcompletionresponse.py +6 -6
- mistralai_gcp/models/chatcompletionstreamrequest.py +38 -7
- mistralai_gcp/models/completionresponsestreamchoice.py +12 -8
- mistralai_gcp/models/deltamessage.py +1 -1
- mistralai_gcp/models/fimcompletionrequest.py +9 -10
- mistralai_gcp/models/fimcompletionresponse.py +6 -6
- mistralai_gcp/models/fimcompletionstreamrequest.py +9 -10
- mistralai_gcp/models/httpvalidationerror.py +15 -8
- mistralai_gcp/models/imageurl.py +1 -1
- mistralai_gcp/models/imageurlchunk.py +1 -1
- mistralai_gcp/models/jsonschema.py +1 -1
- mistralai_gcp/models/mistralgcperror.py +30 -0
- mistralai_gcp/models/mistralpromptmode.py +8 -0
- mistralai_gcp/models/no_response_error.py +17 -0
- mistralai_gcp/models/prediction.py +4 -0
- mistralai_gcp/models/referencechunk.py +1 -1
- mistralai_gcp/models/responseformat.py +5 -3
- mistralai_gcp/models/responseformats.py +5 -2
- mistralai_gcp/models/responsevalidationerror.py +27 -0
- mistralai_gcp/models/sdkerror.py +32 -14
- mistralai_gcp/models/systemmessage.py +8 -4
- mistralai_gcp/models/systemmessagecontentchunks.py +21 -0
- mistralai_gcp/models/textchunk.py +1 -1
- mistralai_gcp/models/thinkchunk.py +35 -0
- mistralai_gcp/models/tool.py +2 -6
- mistralai_gcp/models/toolcall.py +2 -6
- mistralai_gcp/models/toolchoice.py +2 -6
- mistralai_gcp/models/toolchoiceenum.py +6 -1
- mistralai_gcp/models/toolmessage.py +2 -2
- mistralai_gcp/models/tooltypes.py +1 -1
- mistralai_gcp/models/usageinfo.py +71 -8
- mistralai_gcp/models/usermessage.py +2 -2
- mistralai_gcp/sdk.py +12 -10
- mistralai_gcp/sdkconfiguration.py +0 -7
- mistralai_gcp/types/basemodel.py +41 -3
- mistralai_gcp/utils/__init__.py +141 -46
- mistralai_gcp/utils/annotations.py +32 -8
- mistralai_gcp/utils/datetimes.py +23 -0
- mistralai_gcp/utils/enums.py +125 -25
- mistralai_gcp/utils/eventstreaming.py +10 -0
- mistralai_gcp/utils/forms.py +62 -30
- mistralai_gcp/utils/queryparams.py +14 -2
- mistralai_gcp/utils/requestbodies.py +3 -3
- mistralai_gcp/utils/retries.py +69 -5
- mistralai_gcp/utils/serializers.py +33 -23
- mistralai_gcp/utils/unmarshal_json_response.py +38 -0
- mistralai-1.10.0.dist-info/RECORD +0 -475
- {mistralai-1.10.0.dist-info → mistralai-1.11.1.dist-info}/licenses/LICENSE +0 -0
mistralai_gcp/chat.py
CHANGED
|
@@ -5,7 +5,8 @@ from mistralai_gcp import models, utils
|
|
|
5
5
|
from mistralai_gcp._hooks import HookContext
|
|
6
6
|
from mistralai_gcp.types import OptionalNullable, UNSET
|
|
7
7
|
from mistralai_gcp.utils import eventstreaming
|
|
8
|
-
from
|
|
8
|
+
from mistralai_gcp.utils.unmarshal_json_response import unmarshal_json_response
|
|
9
|
+
from typing import Any, Dict, List, Mapping, Optional, Union
|
|
9
10
|
|
|
10
11
|
|
|
11
12
|
class Chat(BaseSDK):
|
|
@@ -22,6 +23,7 @@ class Chat(BaseSDK):
|
|
|
22
23
|
stream: Optional[bool] = True,
|
|
23
24
|
stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
|
|
24
25
|
random_seed: OptionalNullable[int] = UNSET,
|
|
26
|
+
metadata: OptionalNullable[Dict[str, Any]] = UNSET,
|
|
25
27
|
response_format: Optional[
|
|
26
28
|
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
27
29
|
] = None,
|
|
@@ -41,11 +43,12 @@ class Chat(BaseSDK):
|
|
|
41
43
|
Union[models.Prediction, models.PredictionTypedDict]
|
|
42
44
|
] = None,
|
|
43
45
|
parallel_tool_calls: Optional[bool] = None,
|
|
46
|
+
prompt_mode: OptionalNullable[models.MistralPromptMode] = UNSET,
|
|
44
47
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
45
48
|
server_url: Optional[str] = None,
|
|
46
49
|
timeout_ms: Optional[int] = None,
|
|
47
50
|
http_headers: Optional[Mapping[str, str]] = None,
|
|
48
|
-
) ->
|
|
51
|
+
) -> eventstreaming.EventStream[models.CompletionEvent]:
|
|
49
52
|
r"""Stream chat completion
|
|
50
53
|
|
|
51
54
|
Mistral AI provides the ability to stream responses back to a client in order to allow partial results for certain requests. Tokens will be sent as data-only server-sent 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.
|
|
@@ -58,14 +61,16 @@ class Chat(BaseSDK):
|
|
|
58
61
|
:param stream:
|
|
59
62
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
60
63
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
61
|
-
:param
|
|
62
|
-
:param
|
|
63
|
-
:param
|
|
64
|
-
:param
|
|
65
|
-
:param
|
|
64
|
+
:param metadata:
|
|
65
|
+
:param response_format: Specify the format that the model must output. By default it will use `{ \"type\": \"text\" }`. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message. Setting to `{ \"type\": \"json_schema\" }` enables JSON schema mode, which guarantees the message the model generates is in JSON and follows the schema you provide.
|
|
66
|
+
:param tools: A list of tools the model may call. Use this to provide a list of functions the model may generate JSON inputs for.
|
|
67
|
+
:param tool_choice: Controls which (if any) tool is called by the model. `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `any` or `required` means the model must call one or more tools. Specifying a particular tool via `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to call that tool.
|
|
68
|
+
:param presence_penalty: The `presence_penalty` determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
|
|
69
|
+
:param frequency_penalty: The `frequency_penalty` penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
|
|
66
70
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
67
|
-
:param prediction:
|
|
68
|
-
:param parallel_tool_calls:
|
|
71
|
+
:param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
|
|
72
|
+
:param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
|
|
73
|
+
:param prompt_mode: Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used.
|
|
69
74
|
:param retries: Override the default retry configuration for this method
|
|
70
75
|
:param server_url: Override the default server URL for this method
|
|
71
76
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -89,6 +94,7 @@ class Chat(BaseSDK):
|
|
|
89
94
|
stream=stream,
|
|
90
95
|
stop=stop,
|
|
91
96
|
random_seed=random_seed,
|
|
97
|
+
metadata=metadata,
|
|
92
98
|
messages=utils.get_pydantic_model(messages, List[models.Messages]),
|
|
93
99
|
response_format=utils.get_pydantic_model(
|
|
94
100
|
response_format, Optional[models.ResponseFormat]
|
|
@@ -104,6 +110,7 @@ class Chat(BaseSDK):
|
|
|
104
110
|
prediction, Optional[models.Prediction]
|
|
105
111
|
),
|
|
106
112
|
parallel_tool_calls=parallel_tool_calls,
|
|
113
|
+
prompt_mode=prompt_mode,
|
|
107
114
|
)
|
|
108
115
|
|
|
109
116
|
req = self._build_request(
|
|
@@ -122,6 +129,7 @@ class Chat(BaseSDK):
|
|
|
122
129
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
123
130
|
request, False, False, "json", models.ChatCompletionStreamRequest
|
|
124
131
|
),
|
|
132
|
+
allow_empty_value=None,
|
|
125
133
|
timeout_ms=timeout_ms,
|
|
126
134
|
)
|
|
127
135
|
|
|
@@ -135,9 +143,10 @@ class Chat(BaseSDK):
|
|
|
135
143
|
|
|
136
144
|
http_res = self.do_request(
|
|
137
145
|
hook_ctx=HookContext(
|
|
146
|
+
config=self.sdk_configuration,
|
|
138
147
|
base_url=base_url or "",
|
|
139
148
|
operation_id="stream_chat",
|
|
140
|
-
oauth2_scopes=
|
|
149
|
+
oauth2_scopes=None,
|
|
141
150
|
security_source=self.sdk_configuration.security,
|
|
142
151
|
),
|
|
143
152
|
request=req,
|
|
@@ -152,32 +161,23 @@ class Chat(BaseSDK):
|
|
|
152
161
|
http_res,
|
|
153
162
|
lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
|
|
154
163
|
sentinel="[DONE]",
|
|
164
|
+
client_ref=self,
|
|
155
165
|
)
|
|
156
166
|
if utils.match_response(http_res, "422", "application/json"):
|
|
157
167
|
http_res_text = utils.stream_to_text(http_res)
|
|
158
|
-
response_data =
|
|
159
|
-
|
|
168
|
+
response_data = unmarshal_json_response(
|
|
169
|
+
models.HTTPValidationErrorData, http_res, http_res_text
|
|
160
170
|
)
|
|
161
|
-
raise models.HTTPValidationError(
|
|
171
|
+
raise models.HTTPValidationError(response_data, http_res, http_res_text)
|
|
162
172
|
if utils.match_response(http_res, "4XX", "*"):
|
|
163
173
|
http_res_text = utils.stream_to_text(http_res)
|
|
164
|
-
raise models.SDKError(
|
|
165
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
166
|
-
)
|
|
174
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
167
175
|
if utils.match_response(http_res, "5XX", "*"):
|
|
168
176
|
http_res_text = utils.stream_to_text(http_res)
|
|
169
|
-
raise models.SDKError(
|
|
170
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
171
|
-
)
|
|
177
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
172
178
|
|
|
173
|
-
content_type = http_res.headers.get("Content-Type")
|
|
174
179
|
http_res_text = utils.stream_to_text(http_res)
|
|
175
|
-
raise models.SDKError(
|
|
176
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
177
|
-
http_res.status_code,
|
|
178
|
-
http_res_text,
|
|
179
|
-
http_res,
|
|
180
|
-
)
|
|
180
|
+
raise models.SDKError("Unexpected response received", http_res, http_res_text)
|
|
181
181
|
|
|
182
182
|
async def stream_async(
|
|
183
183
|
self,
|
|
@@ -190,6 +190,7 @@ class Chat(BaseSDK):
|
|
|
190
190
|
stream: Optional[bool] = True,
|
|
191
191
|
stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
|
|
192
192
|
random_seed: OptionalNullable[int] = UNSET,
|
|
193
|
+
metadata: OptionalNullable[Dict[str, Any]] = UNSET,
|
|
193
194
|
response_format: Optional[
|
|
194
195
|
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
195
196
|
] = None,
|
|
@@ -209,11 +210,12 @@ class Chat(BaseSDK):
|
|
|
209
210
|
Union[models.Prediction, models.PredictionTypedDict]
|
|
210
211
|
] = None,
|
|
211
212
|
parallel_tool_calls: Optional[bool] = None,
|
|
213
|
+
prompt_mode: OptionalNullable[models.MistralPromptMode] = UNSET,
|
|
212
214
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
213
215
|
server_url: Optional[str] = None,
|
|
214
216
|
timeout_ms: Optional[int] = None,
|
|
215
217
|
http_headers: Optional[Mapping[str, str]] = None,
|
|
216
|
-
) ->
|
|
218
|
+
) -> eventstreaming.EventStreamAsync[models.CompletionEvent]:
|
|
217
219
|
r"""Stream chat completion
|
|
218
220
|
|
|
219
221
|
Mistral AI provides the ability to stream responses back to a client in order to allow partial results for certain requests. Tokens will be sent as data-only server-sent 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.
|
|
@@ -226,14 +228,16 @@ class Chat(BaseSDK):
|
|
|
226
228
|
:param stream:
|
|
227
229
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
228
230
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
229
|
-
:param
|
|
230
|
-
:param
|
|
231
|
-
:param
|
|
232
|
-
:param
|
|
233
|
-
:param
|
|
231
|
+
:param metadata:
|
|
232
|
+
:param response_format: Specify the format that the model must output. By default it will use `{ \"type\": \"text\" }`. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message. Setting to `{ \"type\": \"json_schema\" }` enables JSON schema mode, which guarantees the message the model generates is in JSON and follows the schema you provide.
|
|
233
|
+
:param tools: A list of tools the model may call. Use this to provide a list of functions the model may generate JSON inputs for.
|
|
234
|
+
:param tool_choice: Controls which (if any) tool is called by the model. `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `any` or `required` means the model must call one or more tools. Specifying a particular tool via `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to call that tool.
|
|
235
|
+
:param presence_penalty: The `presence_penalty` determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
|
|
236
|
+
:param frequency_penalty: The `frequency_penalty` penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
|
|
234
237
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
235
|
-
:param prediction:
|
|
236
|
-
:param parallel_tool_calls:
|
|
238
|
+
:param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
|
|
239
|
+
:param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
|
|
240
|
+
:param prompt_mode: Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used.
|
|
237
241
|
:param retries: Override the default retry configuration for this method
|
|
238
242
|
:param server_url: Override the default server URL for this method
|
|
239
243
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -257,6 +261,7 @@ class Chat(BaseSDK):
|
|
|
257
261
|
stream=stream,
|
|
258
262
|
stop=stop,
|
|
259
263
|
random_seed=random_seed,
|
|
264
|
+
metadata=metadata,
|
|
260
265
|
messages=utils.get_pydantic_model(messages, List[models.Messages]),
|
|
261
266
|
response_format=utils.get_pydantic_model(
|
|
262
267
|
response_format, Optional[models.ResponseFormat]
|
|
@@ -272,6 +277,7 @@ class Chat(BaseSDK):
|
|
|
272
277
|
prediction, Optional[models.Prediction]
|
|
273
278
|
),
|
|
274
279
|
parallel_tool_calls=parallel_tool_calls,
|
|
280
|
+
prompt_mode=prompt_mode,
|
|
275
281
|
)
|
|
276
282
|
|
|
277
283
|
req = self._build_request_async(
|
|
@@ -290,6 +296,7 @@ class Chat(BaseSDK):
|
|
|
290
296
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
291
297
|
request, False, False, "json", models.ChatCompletionStreamRequest
|
|
292
298
|
),
|
|
299
|
+
allow_empty_value=None,
|
|
293
300
|
timeout_ms=timeout_ms,
|
|
294
301
|
)
|
|
295
302
|
|
|
@@ -303,9 +310,10 @@ class Chat(BaseSDK):
|
|
|
303
310
|
|
|
304
311
|
http_res = await self.do_request_async(
|
|
305
312
|
hook_ctx=HookContext(
|
|
313
|
+
config=self.sdk_configuration,
|
|
306
314
|
base_url=base_url or "",
|
|
307
315
|
operation_id="stream_chat",
|
|
308
|
-
oauth2_scopes=
|
|
316
|
+
oauth2_scopes=None,
|
|
309
317
|
security_source=self.sdk_configuration.security,
|
|
310
318
|
),
|
|
311
319
|
request=req,
|
|
@@ -320,32 +328,23 @@ class Chat(BaseSDK):
|
|
|
320
328
|
http_res,
|
|
321
329
|
lambda raw: utils.unmarshal_json(raw, models.CompletionEvent),
|
|
322
330
|
sentinel="[DONE]",
|
|
331
|
+
client_ref=self,
|
|
323
332
|
)
|
|
324
333
|
if utils.match_response(http_res, "422", "application/json"):
|
|
325
334
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
326
|
-
response_data =
|
|
327
|
-
|
|
335
|
+
response_data = unmarshal_json_response(
|
|
336
|
+
models.HTTPValidationErrorData, http_res, http_res_text
|
|
328
337
|
)
|
|
329
|
-
raise models.HTTPValidationError(
|
|
338
|
+
raise models.HTTPValidationError(response_data, http_res, http_res_text)
|
|
330
339
|
if utils.match_response(http_res, "4XX", "*"):
|
|
331
340
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
332
|
-
raise models.SDKError(
|
|
333
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
334
|
-
)
|
|
341
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
335
342
|
if utils.match_response(http_res, "5XX", "*"):
|
|
336
343
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
337
|
-
raise models.SDKError(
|
|
338
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
339
|
-
)
|
|
344
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
340
345
|
|
|
341
|
-
content_type = http_res.headers.get("Content-Type")
|
|
342
346
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
343
|
-
raise models.SDKError(
|
|
344
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
345
|
-
http_res.status_code,
|
|
346
|
-
http_res_text,
|
|
347
|
-
http_res,
|
|
348
|
-
)
|
|
347
|
+
raise models.SDKError("Unexpected response received", http_res, http_res_text)
|
|
349
348
|
|
|
350
349
|
def complete(
|
|
351
350
|
self,
|
|
@@ -366,6 +365,7 @@ class Chat(BaseSDK):
|
|
|
366
365
|
]
|
|
367
366
|
] = None,
|
|
368
367
|
random_seed: OptionalNullable[int] = UNSET,
|
|
368
|
+
metadata: OptionalNullable[Dict[str, Any]] = UNSET,
|
|
369
369
|
response_format: Optional[
|
|
370
370
|
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
371
371
|
] = None,
|
|
@@ -385,11 +385,12 @@ class Chat(BaseSDK):
|
|
|
385
385
|
Union[models.Prediction, models.PredictionTypedDict]
|
|
386
386
|
] = None,
|
|
387
387
|
parallel_tool_calls: Optional[bool] = None,
|
|
388
|
+
prompt_mode: OptionalNullable[models.MistralPromptMode] = UNSET,
|
|
388
389
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
389
390
|
server_url: Optional[str] = None,
|
|
390
391
|
timeout_ms: Optional[int] = None,
|
|
391
392
|
http_headers: Optional[Mapping[str, str]] = None,
|
|
392
|
-
) ->
|
|
393
|
+
) -> models.ChatCompletionResponse:
|
|
393
394
|
r"""Chat Completion
|
|
394
395
|
|
|
395
396
|
:param model: ID of the model to use. You can use the [List Available Models](/api/#tag/models/operation/list_models_v1_models_get) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
|
|
@@ -400,14 +401,16 @@ class Chat(BaseSDK):
|
|
|
400
401
|
: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.
|
|
401
402
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
402
403
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
403
|
-
:param
|
|
404
|
-
:param
|
|
405
|
-
:param
|
|
406
|
-
:param
|
|
407
|
-
:param
|
|
404
|
+
:param metadata:
|
|
405
|
+
:param response_format: Specify the format that the model must output. By default it will use `{ \"type\": \"text\" }`. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message. Setting to `{ \"type\": \"json_schema\" }` enables JSON schema mode, which guarantees the message the model generates is in JSON and follows the schema you provide.
|
|
406
|
+
:param tools: A list of tools the model may call. Use this to provide a list of functions the model may generate JSON inputs for.
|
|
407
|
+
:param tool_choice: Controls which (if any) tool is called by the model. `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `any` or `required` means the model must call one or more tools. Specifying a particular tool via `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to call that tool.
|
|
408
|
+
:param presence_penalty: The `presence_penalty` determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
|
|
409
|
+
:param frequency_penalty: The `frequency_penalty` penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
|
|
408
410
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
409
|
-
:param prediction:
|
|
410
|
-
:param parallel_tool_calls:
|
|
411
|
+
:param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
|
|
412
|
+
:param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
|
|
413
|
+
:param prompt_mode: Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used.
|
|
411
414
|
:param retries: Override the default retry configuration for this method
|
|
412
415
|
:param server_url: Override the default server URL for this method
|
|
413
416
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -431,6 +434,7 @@ class Chat(BaseSDK):
|
|
|
431
434
|
stream=stream,
|
|
432
435
|
stop=stop,
|
|
433
436
|
random_seed=random_seed,
|
|
437
|
+
metadata=metadata,
|
|
434
438
|
messages=utils.get_pydantic_model(
|
|
435
439
|
messages, List[models.ChatCompletionRequestMessages]
|
|
436
440
|
),
|
|
@@ -448,6 +452,7 @@ class Chat(BaseSDK):
|
|
|
448
452
|
prediction, Optional[models.Prediction]
|
|
449
453
|
),
|
|
450
454
|
parallel_tool_calls=parallel_tool_calls,
|
|
455
|
+
prompt_mode=prompt_mode,
|
|
451
456
|
)
|
|
452
457
|
|
|
453
458
|
req = self._build_request(
|
|
@@ -466,6 +471,7 @@ class Chat(BaseSDK):
|
|
|
466
471
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
467
472
|
request, False, False, "json", models.ChatCompletionRequest
|
|
468
473
|
),
|
|
474
|
+
allow_empty_value=None,
|
|
469
475
|
timeout_ms=timeout_ms,
|
|
470
476
|
)
|
|
471
477
|
|
|
@@ -479,9 +485,10 @@ class Chat(BaseSDK):
|
|
|
479
485
|
|
|
480
486
|
http_res = self.do_request(
|
|
481
487
|
hook_ctx=HookContext(
|
|
488
|
+
config=self.sdk_configuration,
|
|
482
489
|
base_url=base_url or "",
|
|
483
490
|
operation_id="chat_completion_v1_chat_completions_post",
|
|
484
|
-
oauth2_scopes=
|
|
491
|
+
oauth2_scopes=None,
|
|
485
492
|
security_source=self.sdk_configuration.security,
|
|
486
493
|
),
|
|
487
494
|
request=req,
|
|
@@ -491,33 +498,20 @@ class Chat(BaseSDK):
|
|
|
491
498
|
|
|
492
499
|
response_data: Any = None
|
|
493
500
|
if utils.match_response(http_res, "200", "application/json"):
|
|
494
|
-
return
|
|
495
|
-
http_res.text, Optional[models.ChatCompletionResponse]
|
|
496
|
-
)
|
|
501
|
+
return unmarshal_json_response(models.ChatCompletionResponse, http_res)
|
|
497
502
|
if utils.match_response(http_res, "422", "application/json"):
|
|
498
|
-
response_data =
|
|
499
|
-
|
|
503
|
+
response_data = unmarshal_json_response(
|
|
504
|
+
models.HTTPValidationErrorData, http_res
|
|
500
505
|
)
|
|
501
|
-
raise models.HTTPValidationError(
|
|
506
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
502
507
|
if utils.match_response(http_res, "4XX", "*"):
|
|
503
508
|
http_res_text = utils.stream_to_text(http_res)
|
|
504
|
-
raise models.SDKError(
|
|
505
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
506
|
-
)
|
|
509
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
507
510
|
if utils.match_response(http_res, "5XX", "*"):
|
|
508
511
|
http_res_text = utils.stream_to_text(http_res)
|
|
509
|
-
raise models.SDKError(
|
|
510
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
511
|
-
)
|
|
512
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
512
513
|
|
|
513
|
-
|
|
514
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
515
|
-
raise models.SDKError(
|
|
516
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
517
|
-
http_res.status_code,
|
|
518
|
-
http_res_text,
|
|
519
|
-
http_res,
|
|
520
|
-
)
|
|
514
|
+
raise models.SDKError("Unexpected response received", http_res)
|
|
521
515
|
|
|
522
516
|
async def complete_async(
|
|
523
517
|
self,
|
|
@@ -538,6 +532,7 @@ class Chat(BaseSDK):
|
|
|
538
532
|
]
|
|
539
533
|
] = None,
|
|
540
534
|
random_seed: OptionalNullable[int] = UNSET,
|
|
535
|
+
metadata: OptionalNullable[Dict[str, Any]] = UNSET,
|
|
541
536
|
response_format: Optional[
|
|
542
537
|
Union[models.ResponseFormat, models.ResponseFormatTypedDict]
|
|
543
538
|
] = None,
|
|
@@ -557,11 +552,12 @@ class Chat(BaseSDK):
|
|
|
557
552
|
Union[models.Prediction, models.PredictionTypedDict]
|
|
558
553
|
] = None,
|
|
559
554
|
parallel_tool_calls: Optional[bool] = None,
|
|
555
|
+
prompt_mode: OptionalNullable[models.MistralPromptMode] = UNSET,
|
|
560
556
|
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
561
557
|
server_url: Optional[str] = None,
|
|
562
558
|
timeout_ms: Optional[int] = None,
|
|
563
559
|
http_headers: Optional[Mapping[str, str]] = None,
|
|
564
|
-
) ->
|
|
560
|
+
) -> models.ChatCompletionResponse:
|
|
565
561
|
r"""Chat Completion
|
|
566
562
|
|
|
567
563
|
:param model: ID of the model to use. You can use the [List Available Models](/api/#tag/models/operation/list_models_v1_models_get) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
|
|
@@ -572,14 +568,16 @@ class Chat(BaseSDK):
|
|
|
572
568
|
: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.
|
|
573
569
|
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
574
570
|
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
575
|
-
:param
|
|
576
|
-
:param
|
|
577
|
-
:param
|
|
578
|
-
:param
|
|
579
|
-
:param
|
|
571
|
+
:param metadata:
|
|
572
|
+
:param response_format: Specify the format that the model must output. By default it will use `{ \"type\": \"text\" }`. Setting to `{ \"type\": \"json_object\" }` enables JSON mode, which guarantees the message the model generates is in JSON. When using JSON mode you MUST also instruct the model to produce JSON yourself with a system or a user message. Setting to `{ \"type\": \"json_schema\" }` enables JSON schema mode, which guarantees the message the model generates is in JSON and follows the schema you provide.
|
|
573
|
+
:param tools: A list of tools the model may call. Use this to provide a list of functions the model may generate JSON inputs for.
|
|
574
|
+
:param tool_choice: Controls which (if any) tool is called by the model. `none` means the model will not call any tool and instead generates a message. `auto` means the model can pick between generating a message or calling one or more tools. `any` or `required` means the model must call one or more tools. Specifying a particular tool via `{\"type\": \"function\", \"function\": {\"name\": \"my_function\"}}` forces the model to call that tool.
|
|
575
|
+
:param presence_penalty: The `presence_penalty` determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
|
|
576
|
+
:param frequency_penalty: The `frequency_penalty` penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
|
|
580
577
|
:param n: Number of completions to return for each request, input tokens are only billed once.
|
|
581
|
-
:param prediction:
|
|
582
|
-
:param parallel_tool_calls:
|
|
578
|
+
:param prediction: Enable users to specify an expected completion, optimizing response times by leveraging known or predictable content.
|
|
579
|
+
:param parallel_tool_calls: Whether to enable parallel function calling during tool use, when enabled the model can call multiple tools in parallel.
|
|
580
|
+
:param prompt_mode: Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used.
|
|
583
581
|
:param retries: Override the default retry configuration for this method
|
|
584
582
|
:param server_url: Override the default server URL for this method
|
|
585
583
|
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
@@ -603,6 +601,7 @@ class Chat(BaseSDK):
|
|
|
603
601
|
stream=stream,
|
|
604
602
|
stop=stop,
|
|
605
603
|
random_seed=random_seed,
|
|
604
|
+
metadata=metadata,
|
|
606
605
|
messages=utils.get_pydantic_model(
|
|
607
606
|
messages, List[models.ChatCompletionRequestMessages]
|
|
608
607
|
),
|
|
@@ -620,6 +619,7 @@ class Chat(BaseSDK):
|
|
|
620
619
|
prediction, Optional[models.Prediction]
|
|
621
620
|
),
|
|
622
621
|
parallel_tool_calls=parallel_tool_calls,
|
|
622
|
+
prompt_mode=prompt_mode,
|
|
623
623
|
)
|
|
624
624
|
|
|
625
625
|
req = self._build_request_async(
|
|
@@ -638,6 +638,7 @@ class Chat(BaseSDK):
|
|
|
638
638
|
get_serialized_body=lambda: utils.serialize_request_body(
|
|
639
639
|
request, False, False, "json", models.ChatCompletionRequest
|
|
640
640
|
),
|
|
641
|
+
allow_empty_value=None,
|
|
641
642
|
timeout_ms=timeout_ms,
|
|
642
643
|
)
|
|
643
644
|
|
|
@@ -651,9 +652,10 @@ class Chat(BaseSDK):
|
|
|
651
652
|
|
|
652
653
|
http_res = await self.do_request_async(
|
|
653
654
|
hook_ctx=HookContext(
|
|
655
|
+
config=self.sdk_configuration,
|
|
654
656
|
base_url=base_url or "",
|
|
655
657
|
operation_id="chat_completion_v1_chat_completions_post",
|
|
656
|
-
oauth2_scopes=
|
|
658
|
+
oauth2_scopes=None,
|
|
657
659
|
security_source=self.sdk_configuration.security,
|
|
658
660
|
),
|
|
659
661
|
request=req,
|
|
@@ -663,30 +665,17 @@ class Chat(BaseSDK):
|
|
|
663
665
|
|
|
664
666
|
response_data: Any = None
|
|
665
667
|
if utils.match_response(http_res, "200", "application/json"):
|
|
666
|
-
return
|
|
667
|
-
http_res.text, Optional[models.ChatCompletionResponse]
|
|
668
|
-
)
|
|
668
|
+
return unmarshal_json_response(models.ChatCompletionResponse, http_res)
|
|
669
669
|
if utils.match_response(http_res, "422", "application/json"):
|
|
670
|
-
response_data =
|
|
671
|
-
|
|
670
|
+
response_data = unmarshal_json_response(
|
|
671
|
+
models.HTTPValidationErrorData, http_res
|
|
672
672
|
)
|
|
673
|
-
raise models.HTTPValidationError(
|
|
673
|
+
raise models.HTTPValidationError(response_data, http_res)
|
|
674
674
|
if utils.match_response(http_res, "4XX", "*"):
|
|
675
675
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
676
|
-
raise models.SDKError(
|
|
677
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
678
|
-
)
|
|
676
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
679
677
|
if utils.match_response(http_res, "5XX", "*"):
|
|
680
678
|
http_res_text = await utils.stream_to_text_async(http_res)
|
|
681
|
-
raise models.SDKError(
|
|
682
|
-
"API error occurred", http_res.status_code, http_res_text, http_res
|
|
683
|
-
)
|
|
679
|
+
raise models.SDKError("API error occurred", http_res, http_res_text)
|
|
684
680
|
|
|
685
|
-
|
|
686
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
687
|
-
raise models.SDKError(
|
|
688
|
-
f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
|
|
689
|
-
http_res.status_code,
|
|
690
|
-
http_res_text,
|
|
691
|
-
http_res,
|
|
692
|
-
)
|
|
681
|
+
raise models.SDKError("Unexpected response received", http_res)
|