mistralai 0.1.3__py3-none-any.whl → 0.1.7__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/async_client.py CHANGED
@@ -14,7 +14,7 @@ from httpx import (
14
14
  )
15
15
 
16
16
  from mistralai.client_base import ClientBase
17
- from mistralai.constants import ENDPOINT
17
+ from mistralai.constants import ENDPOINT, RETRY_STATUS_CODES
18
18
  from mistralai.exceptions import (
19
19
  MistralAPIException,
20
20
  MistralAPIStatusException,
@@ -52,6 +52,44 @@ class MistralAsyncClient(ClientBase):
52
52
  async def close(self) -> None:
53
53
  await self._client.aclose()
54
54
 
55
+ async def _check_response_status_codes(self, response: Response) -> None:
56
+ if response.status_code in RETRY_STATUS_CODES:
57
+ raise MistralAPIStatusException.from_response(
58
+ response,
59
+ message=f"Status: {response.status_code}. Message: {response.text}",
60
+ )
61
+ elif 400 <= response.status_code < 500:
62
+ if response.stream:
63
+ await response.aread()
64
+ raise MistralAPIException.from_response(
65
+ response,
66
+ message=f"Status: {response.status_code}. Message: {response.text}",
67
+ )
68
+ elif response.status_code >= 500:
69
+ if response.stream:
70
+ await response.aread()
71
+ raise MistralException(
72
+ message=f"Status: {response.status_code}. Message: {response.text}",
73
+ )
74
+
75
+ async def _check_streaming_response(self, response: Response) -> None:
76
+ await self._check_response_status_codes(response)
77
+
78
+ async def _check_response(self, response: Response) -> Dict[str, Any]:
79
+ await self._check_response_status_codes(response)
80
+
81
+ json_response: Dict[str, Any] = response.json()
82
+
83
+ if "object" not in json_response:
84
+ raise MistralException(message=f"Unexpected response: {json_response}")
85
+ if "error" == json_response["object"]: # has errors
86
+ raise MistralAPIException.from_response(
87
+ response,
88
+ message=json_response["message"],
89
+ )
90
+
91
+ return json_response
92
+
55
93
  async def _request(
56
94
  self,
57
95
  method: str,
@@ -82,7 +120,7 @@ class MistralAsyncClient(ClientBase):
82
120
  headers=headers,
83
121
  json=json,
84
122
  ) as response:
85
- self._check_streaming_response(response)
123
+ await self._check_streaming_response(response)
86
124
 
87
125
  async for line in response.aiter_lines():
88
126
  json_streamed_response = self._process_line(line)
@@ -97,7 +135,7 @@ class MistralAsyncClient(ClientBase):
97
135
  json=json,
98
136
  )
99
137
 
100
- yield self._check_response(response)
138
+ yield await self._check_response(response)
101
139
 
102
140
  except ConnectError as e:
103
141
  raise MistralConnectionException(str(e)) from e
mistralai/client.py CHANGED
@@ -7,7 +7,7 @@ from typing import Any, Dict, Iterable, Iterator, List, Optional, Union
7
7
  from httpx import Client, ConnectError, HTTPTransport, RequestError, Response
8
8
 
9
9
  from mistralai.client_base import ClientBase
10
- from mistralai.constants import ENDPOINT
10
+ from mistralai.constants import ENDPOINT, RETRY_STATUS_CODES
11
11
  from mistralai.exceptions import (
12
12
  MistralAPIException,
13
13
  MistralAPIStatusException,
@@ -45,6 +45,44 @@ class MistralClient(ClientBase):
45
45
  def __del__(self) -> None:
46
46
  self._client.close()
47
47
 
48
+ def _check_response_status_codes(self, response: Response) -> None:
49
+ if response.status_code in RETRY_STATUS_CODES:
50
+ raise MistralAPIStatusException.from_response(
51
+ response,
52
+ message=f"Status: {response.status_code}. Message: {response.text}",
53
+ )
54
+ elif 400 <= response.status_code < 500:
55
+ if response.stream:
56
+ response.read()
57
+ raise MistralAPIException.from_response(
58
+ response,
59
+ message=f"Status: {response.status_code}. Message: {response.text}",
60
+ )
61
+ elif response.status_code >= 500:
62
+ if response.stream:
63
+ response.read()
64
+ raise MistralException(
65
+ message=f"Status: {response.status_code}. Message: {response.text}",
66
+ )
67
+
68
+ def _check_streaming_response(self, response: Response) -> None:
69
+ self._check_response_status_codes(response)
70
+
71
+ def _check_response(self, response: Response) -> Dict[str, Any]:
72
+ self._check_response_status_codes(response)
73
+
74
+ json_response: Dict[str, Any] = response.json()
75
+
76
+ if "object" not in json_response:
77
+ raise MistralException(message=f"Unexpected response: {json_response}")
78
+ if "error" == json_response["object"]: # has errors
79
+ raise MistralAPIException.from_response(
80
+ response,
81
+ message=json_response["message"],
82
+ )
83
+
84
+ return json_response
85
+
48
86
  def _request(
49
87
  self,
50
88
  method: str,
mistralai/client_base.py CHANGED
@@ -4,12 +4,8 @@ from abc import ABC
4
4
  from typing import Any, Dict, List, Optional, Union
5
5
 
6
6
  import orjson
7
- from httpx import Response
8
7
 
9
- from mistralai.constants import RETRY_STATUS_CODES
10
8
  from mistralai.exceptions import (
11
- MistralAPIException,
12
- MistralAPIStatusException,
13
9
  MistralException,
14
10
  )
15
11
  from mistralai.models.chat_completion import ChatMessage, Function, ResponseFormat, ToolChoice
@@ -40,7 +36,7 @@ class ClientBase(ABC):
40
36
  self._default_model = "mistral"
41
37
 
42
38
  # This should be automatically updated by the deploy script
43
- self._version = "0.1.3"
39
+ self._version = "0.1.7"
44
40
 
45
41
  def _parse_tools(self, tools: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
46
42
  parsed_tools: List[Dict[str, Any]] = []
@@ -125,40 +121,6 @@ class ClientBase(ABC):
125
121
 
126
122
  return request_data
127
123
 
128
- def _check_response_status_codes(self, response: Response) -> None:
129
- if response.status_code in RETRY_STATUS_CODES:
130
- raise MistralAPIStatusException.from_response(
131
- response,
132
- message=f"Status: {response.status_code}. Message: {response.text}",
133
- )
134
- elif 400 <= response.status_code < 500:
135
- raise MistralAPIException.from_response(
136
- response,
137
- message=f"Status: {response.status_code}. Message: {response.text}",
138
- )
139
- elif response.status_code >= 500:
140
- raise MistralException(
141
- message=f"Status: {response.status_code}. Message: {response.text}",
142
- )
143
-
144
- def _check_streaming_response(self, response: Response) -> None:
145
- self._check_response_status_codes(response)
146
-
147
- def _check_response(self, response: Response) -> Dict[str, Any]:
148
- self._check_response_status_codes(response)
149
-
150
- json_response: Dict[str, Any] = response.json()
151
-
152
- if "object" not in json_response:
153
- raise MistralException(message=f"Unexpected response: {json_response}")
154
- if "error" == json_response["object"]: # has errors
155
- raise MistralAPIException.from_response(
156
- response,
157
- message=json_response["message"],
158
- )
159
-
160
- return json_response
161
-
162
124
  def _process_line(self, line: str) -> Optional[Dict[str, Any]]:
163
125
  if line.startswith("data: "):
164
126
  line = line[6:].strip()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mistralai
3
- Version: 0.1.3
3
+ Version: 0.1.7
4
4
  Summary:
5
5
  Author: Bam4d
6
6
  Author-email: bam4d@mistral.ai
@@ -12,8 +12,6 @@ Classifier: Programming Language :: Python :: 3.11
12
12
  Classifier: Programming Language :: Python :: 3.12
13
13
  Requires-Dist: httpx (>=0.25.2,<0.26.0)
14
14
  Requires-Dist: orjson (>=3.9.10,<4.0.0)
15
- Requires-Dist: pandas (>=2.2.0,<3.0.0)
16
- Requires-Dist: pyarrow (>=15.0.0,<16.0.0)
17
15
  Requires-Dist: pydantic (>=2.5.2,<3.0.0)
18
16
  Description-Content-Type: text/markdown
19
17
 
@@ -1,7 +1,7 @@
1
1
  mistralai/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- mistralai/async_client.py,sha256=-qAdHbYdFNmOyBOMnpD3Zdeyh211m1HcbeyEwmqSfgc,9830
3
- mistralai/client.py,sha256=xrbWUQ-gHKU1XSmYlFiDpy7BBE1uL3-y_8TxlHjWqeU,9639
4
- mistralai/client_base.py,sha256=OMB-8FbnO-Gmp_phzRJtjzxT2zWLjnawtEB6ik_sE0Q,6156
2
+ mistralai/async_client.py,sha256=dpaZ7W7R2Fmo19vvf1SfyViT6JbmjJUGzaT-keT1vTc,11411
3
+ mistralai/client.py,sha256=cneaYGtFOkrE0sUPh6GQeuX_eXKcCpNjomJjPlVWD4g,11164
4
+ mistralai/client_base.py,sha256=fAOrLK9FSgKMflI6YNCCxslqcPbFKuR2hlMsDfL_7AI,4645
5
5
  mistralai/constants.py,sha256=KK286HFjpoTxPKih8xdTp0lW4YMDPyYu2Shi3Nu5Vdw,86
6
6
  mistralai/exceptions.py,sha256=d1cli28ZaPEBQy2RKKcSh-dO2T20GXHNoaJrXXBmyIs,1664
7
7
  mistralai/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -10,7 +10,7 @@ mistralai/models/common.py,sha256=zatP4aV_LIEpzj3_igsKkJBICwGhmXG0LX3CdO3kn-o,17
10
10
  mistralai/models/embeddings.py,sha256=-VthLQBj6wrq7HXJbGmnkQEEanSemA3MAlaMFh94VBg,331
11
11
  mistralai/models/models.py,sha256=I4I1kQwP0tJ2_rd4lbSUwOkCJE5E-dSTIExQg2ZNFcw,713
12
12
  mistralai/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
- mistralai-0.1.3.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
14
- mistralai-0.1.3.dist-info/METADATA,sha256=FtZmP7OpC1xTs7dv2C8TPMpzN3fLXTlQEkv6-eYIdkg,1917
15
- mistralai-0.1.3.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
16
- mistralai-0.1.3.dist-info/RECORD,,
13
+ mistralai-0.1.7.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
14
+ mistralai-0.1.7.dist-info/METADATA,sha256=-_MdZmZ2d_bj0G4X90l9bICg1dqfAvnhw9iB9PCv8eI,1836
15
+ mistralai-0.1.7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
16
+ mistralai-0.1.7.dist-info/RECORD,,