mistralai 0.1.8__tar.gz → 0.2.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: mistralai
3
- Version: 0.1.8
3
+ Version: 0.2.0
4
4
  Summary:
5
5
  Author: Bam4d
6
6
  Author-email: bam4d@mistral.ai
@@ -10,7 +10,7 @@ Classifier: Programming Language :: Python :: 3.9
10
10
  Classifier: Programming Language :: Python :: 3.10
11
11
  Classifier: Programming Language :: Python :: 3.11
12
12
  Classifier: Programming Language :: Python :: 3.12
13
- Requires-Dist: httpx (>=0.25.2,<0.26.0)
13
+ Requires-Dist: httpx (>=0.25.2,<1)
14
14
  Requires-Dist: orjson (>=3.9.10,<4.0.0)
15
15
  Requires-Dist: pydantic (>=2.5.2,<3.0.0)
16
16
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "mistralai"
3
- version = "0.1.8"
3
+ version = "0.2.0"
4
4
  description = ""
5
5
  authors = ["Bam4d <bam4d@mistral.ai>"]
6
6
  readme = "README.md"
@@ -26,7 +26,7 @@ exclude = ["docs", "tests", "examples", "tools", "build"]
26
26
  python = "^3.9"
27
27
  orjson = "^3.9.10"
28
28
  pydantic = "^2.5.2"
29
- httpx = "^0.25.2"
29
+ httpx = ">= 0.25.2, < 1"
30
30
 
31
31
 
32
32
  [tool.poetry.group.dev.dependencies]
@@ -1,6 +1,5 @@
1
- import os
1
+ import asyncio
2
2
  import posixpath
3
- import time
4
3
  from json import JSONDecodeError
5
4
  from typing import Any, AsyncGenerator, Dict, List, Optional, Union
6
5
 
@@ -34,7 +33,7 @@ from mistralai.models.models import ModelList
34
33
  class MistralAsyncClient(ClientBase):
35
34
  def __init__(
36
35
  self,
37
- api_key: Optional[str] = os.environ.get("MISTRAL_API_KEY", None),
36
+ api_key: Optional[str] = None,
38
37
  endpoint: str = ENDPOINT,
39
38
  max_retries: int = 5,
40
39
  timeout: int = 120,
@@ -151,7 +150,7 @@ class MistralAsyncClient(ClientBase):
151
150
  if attempt > self._max_retries:
152
151
  raise MistralAPIStatusException.from_response(response, message=str(e)) from e
153
152
  backoff = 2.0**attempt # exponential backoff
154
- time.sleep(backoff)
153
+ await asyncio.sleep(backoff)
155
154
 
156
155
  # Retry as a generator
157
156
  async for r in self._request(method, json, path, stream=stream, attempt=attempt):
@@ -1,4 +1,3 @@
1
- import os
2
1
  import posixpath
3
2
  import time
4
3
  from json import JSONDecodeError
@@ -31,7 +30,7 @@ class MistralClient(ClientBase):
31
30
 
32
31
  def __init__(
33
32
  self,
34
- api_key: Optional[str] = os.environ.get("MISTRAL_API_KEY", None),
33
+ api_key: Optional[str] = None,
35
34
  endpoint: str = ENDPOINT,
36
35
  max_retries: int = 5,
37
36
  timeout: int = 120,
@@ -10,10 +10,7 @@ from mistralai.exceptions import (
10
10
  )
11
11
  from mistralai.models.chat_completion import ChatMessage, Function, ResponseFormat, ToolChoice
12
12
 
13
- logging.basicConfig(
14
- format="%(asctime)s %(levelname)s %(name)s: %(message)s",
15
- level=os.getenv("LOG_LEVEL", "ERROR"),
16
- )
13
+ CLIENT_VERSION = "0.2.0"
17
14
 
18
15
 
19
16
  class ClientBase(ABC):
@@ -27,16 +24,19 @@ class ClientBase(ABC):
27
24
  self._max_retries = max_retries
28
25
  self._timeout = timeout
29
26
 
30
- self._endpoint = endpoint
27
+ if api_key is None:
28
+ api_key = os.environ.get("MISTRAL_API_KEY")
29
+ if api_key is None:
30
+ raise MistralException(message="API key not provided. Please set MISTRAL_API_KEY environment variable.")
31
31
  self._api_key = api_key
32
+ self._endpoint = endpoint
32
33
  self._logger = logging.getLogger(__name__)
33
34
 
34
35
  # For azure endpoints, we default to the mistral model
35
36
  if "inference.azure.com" in self._endpoint:
36
37
  self._default_model = "mistral"
37
38
 
38
- # This should be automatically updated by the deploy script
39
- self._version = "0.1.8"
39
+ self._version = CLIENT_VERSION
40
40
 
41
41
  def _parse_tools(self, tools: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
42
42
  parsed_tools: List[Dict[str, Any]] = []
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  RETRY_STATUS_CODES = {429, 500, 502, 503, 504}
4
2
 
5
3
  ENDPOINT = "https://api.mistral.ai"
@@ -35,9 +35,7 @@ class MistralAPIException(MistralException):
35
35
  self.headers = headers or {}
36
36
 
37
37
  @classmethod
38
- def from_response(
39
- cls, response: Response, message: Optional[str] = None
40
- ) -> MistralAPIException:
38
+ def from_response(cls, response: Response, message: Optional[str] = None) -> MistralAPIException:
41
39
  return cls(
42
40
  message=message or response.text,
43
41
  http_status=response.status_code,
@@ -47,8 +45,10 @@ class MistralAPIException(MistralException):
47
45
  def __repr__(self) -> str:
48
46
  return f"{self.__class__.__name__}(message={str(self)}, http_status={self.http_status})"
49
47
 
48
+
50
49
  class MistralAPIStatusException(MistralAPIException):
51
50
  """Returned when we receive a non-200 response from the API that we should retry"""
52
51
 
52
+
53
53
  class MistralConnectionException(MistralException):
54
54
  """Returned when the SDK can not reach the API server for any reason"""
@@ -47,6 +47,7 @@ class ChatMessage(BaseModel):
47
47
  content: Union[str, List[str]]
48
48
  name: Optional[str] = None
49
49
  tool_calls: Optional[List[ToolCall]] = None
50
+ tool_call_id: Optional[str] = None
50
51
 
51
52
 
52
53
  class DeltaMessage(BaseModel):
@@ -17,6 +17,7 @@ class ModelPermission(BaseModel):
17
17
  group: Optional[str] = None
18
18
  is_blocking: bool = False
19
19
 
20
+
20
21
  class ModelCard(BaseModel):
21
22
  id: str
22
23
  object: str
File without changes
File without changes