mistralai 0.2.0__tar.gz → 0.3.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.
- {mistralai-0.2.0 → mistralai-0.3.0}/PKG-INFO +1 -1
- {mistralai-0.2.0 → mistralai-0.3.0}/pyproject.toml +1 -1
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/async_client.py +72 -1
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/client.py +75 -1
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/client_base.py +63 -8
- {mistralai-0.2.0 → mistralai-0.3.0}/LICENSE +0 -0
- {mistralai-0.2.0 → mistralai-0.3.0}/README.md +0 -0
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/__init__.py +0 -0
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/constants.py +0 -0
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/exceptions.py +0 -0
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/models/__init__.py +0 -0
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/models/chat_completion.py +0 -0
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/models/common.py +0 -0
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/models/embeddings.py +0 -0
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/models/models.py +0 -0
- {mistralai-0.2.0 → mistralai-0.3.0}/src/mistralai/py.typed +0 -0
|
@@ -92,7 +92,7 @@ class MistralAsyncClient(ClientBase):
|
|
|
92
92
|
async def _request(
|
|
93
93
|
self,
|
|
94
94
|
method: str,
|
|
95
|
-
json: Dict[str, Any],
|
|
95
|
+
json: Optional[Dict[str, Any]],
|
|
96
96
|
path: str,
|
|
97
97
|
stream: bool = False,
|
|
98
98
|
attempt: int = 1,
|
|
@@ -291,3 +291,74 @@ class MistralAsyncClient(ClientBase):
|
|
|
291
291
|
return ModelList(**response)
|
|
292
292
|
|
|
293
293
|
raise MistralException("No response received")
|
|
294
|
+
|
|
295
|
+
async def completion(
|
|
296
|
+
self,
|
|
297
|
+
model: str,
|
|
298
|
+
prompt: str,
|
|
299
|
+
suffix: Optional[str] = None,
|
|
300
|
+
temperature: Optional[float] = None,
|
|
301
|
+
max_tokens: Optional[int] = None,
|
|
302
|
+
top_p: Optional[float] = None,
|
|
303
|
+
random_seed: Optional[int] = None,
|
|
304
|
+
stop: Optional[List[str]] = None,
|
|
305
|
+
) -> ChatCompletionResponse:
|
|
306
|
+
"""An asynchronous completion endpoint that returns a single response.
|
|
307
|
+
|
|
308
|
+
Args:
|
|
309
|
+
model (str): model the name of the model to get completions with, e.g. codestral-latest
|
|
310
|
+
prompt (str): the prompt to complete
|
|
311
|
+
suffix (Optional[str]): the suffix to append to the prompt for fill-in-the-middle completion
|
|
312
|
+
temperature (Optional[float], optional): temperature the temperature to use for sampling, e.g. 0.5.
|
|
313
|
+
max_tokens (Optional[int], optional): the maximum number of tokens to generate, e.g. 100. Defaults to None.
|
|
314
|
+
top_p (Optional[float], optional): the cumulative probability of tokens to generate, e.g. 0.9.
|
|
315
|
+
Defaults to None.
|
|
316
|
+
random_seed (Optional[int], optional): the random seed to use for sampling, e.g. 42. Defaults to None.
|
|
317
|
+
stop (Optional[List[str]], optional): a list of tokens to stop generation at, e.g. ['/n/n']
|
|
318
|
+
Returns:
|
|
319
|
+
Dict[str, Any]: a response object containing the generated text.
|
|
320
|
+
"""
|
|
321
|
+
request = self._make_completion_request(
|
|
322
|
+
prompt, model, suffix, temperature, max_tokens, top_p, random_seed, stop
|
|
323
|
+
)
|
|
324
|
+
single_response = self._request("post", request, "v1/fim/completions")
|
|
325
|
+
|
|
326
|
+
async for response in single_response:
|
|
327
|
+
return ChatCompletionResponse(**response)
|
|
328
|
+
|
|
329
|
+
raise MistralException("No response received")
|
|
330
|
+
|
|
331
|
+
async def completion_stream(
|
|
332
|
+
self,
|
|
333
|
+
model: str,
|
|
334
|
+
prompt: str,
|
|
335
|
+
suffix: Optional[str] = None,
|
|
336
|
+
temperature: Optional[float] = None,
|
|
337
|
+
max_tokens: Optional[int] = None,
|
|
338
|
+
top_p: Optional[float] = None,
|
|
339
|
+
random_seed: Optional[int] = None,
|
|
340
|
+
stop: Optional[List[str]] = None,
|
|
341
|
+
) -> AsyncGenerator[ChatCompletionStreamResponse, None]:
|
|
342
|
+
"""An asynchronous completion endpoint that returns a streaming response.
|
|
343
|
+
|
|
344
|
+
Args:
|
|
345
|
+
model (str): model the name of the model to get completions with, e.g. codestral-latest
|
|
346
|
+
prompt (str): the prompt to complete
|
|
347
|
+
suffix (Optional[str]): the suffix to append to the prompt for fill-in-the-middle completion
|
|
348
|
+
temperature (Optional[float], optional): temperature the temperature to use for sampling, e.g. 0.5.
|
|
349
|
+
max_tokens (Optional[int], optional): the maximum number of tokens to generate, e.g. 100. Defaults to None.
|
|
350
|
+
top_p (Optional[float], optional): the cumulative probability of tokens to generate, e.g. 0.9.
|
|
351
|
+
Defaults to None.
|
|
352
|
+
random_seed (Optional[int], optional): the random seed to use for sampling, e.g. 42. Defaults to None.
|
|
353
|
+
stop (Optional[List[str]], optional): a list of tokens to stop generation at, e.g. ['/n/n']
|
|
354
|
+
|
|
355
|
+
Returns:
|
|
356
|
+
Dict[str, Any]: a response object containing the generated text.
|
|
357
|
+
"""
|
|
358
|
+
request = self._make_completion_request(
|
|
359
|
+
prompt, model, suffix, temperature, max_tokens, top_p, random_seed, stop, stream=True
|
|
360
|
+
)
|
|
361
|
+
async_response = self._request("post", request, "v1/fim/completions", stream=True)
|
|
362
|
+
|
|
363
|
+
async for json_response in async_response:
|
|
364
|
+
yield ChatCompletionStreamResponse(**json_response)
|
|
@@ -85,7 +85,7 @@ class MistralClient(ClientBase):
|
|
|
85
85
|
def _request(
|
|
86
86
|
self,
|
|
87
87
|
method: str,
|
|
88
|
-
json: Dict[str, Any],
|
|
88
|
+
json: Optional[Dict[str, Any]],
|
|
89
89
|
path: str,
|
|
90
90
|
stream: bool = False,
|
|
91
91
|
attempt: int = 1,
|
|
@@ -285,3 +285,77 @@ class MistralClient(ClientBase):
|
|
|
285
285
|
return ModelList(**response)
|
|
286
286
|
|
|
287
287
|
raise MistralException("No response received")
|
|
288
|
+
|
|
289
|
+
def completion(
|
|
290
|
+
self,
|
|
291
|
+
model: str,
|
|
292
|
+
prompt: str,
|
|
293
|
+
suffix: Optional[str] = None,
|
|
294
|
+
temperature: Optional[float] = None,
|
|
295
|
+
max_tokens: Optional[int] = None,
|
|
296
|
+
top_p: Optional[float] = None,
|
|
297
|
+
random_seed: Optional[int] = None,
|
|
298
|
+
stop: Optional[List[str]] = None,
|
|
299
|
+
) -> ChatCompletionResponse:
|
|
300
|
+
"""A completion endpoint that returns a single response.
|
|
301
|
+
|
|
302
|
+
Args:
|
|
303
|
+
model (str): model the name of the model to get completion with, e.g. codestral-latest
|
|
304
|
+
prompt (str): the prompt to complete
|
|
305
|
+
suffix (Optional[str]): the suffix to append to the prompt for fill-in-the-middle completion
|
|
306
|
+
temperature (Optional[float], optional): temperature the temperature to use for sampling, e.g. 0.5.
|
|
307
|
+
max_tokens (Optional[int], optional): the maximum number of tokens to generate, e.g. 100. Defaults to None.
|
|
308
|
+
top_p (Optional[float], optional): the cumulative probability of tokens to generate, e.g. 0.9.
|
|
309
|
+
Defaults to None.
|
|
310
|
+
random_seed (Optional[int], optional): the random seed to use for sampling, e.g. 42. Defaults to None.
|
|
311
|
+
stop (Optional[List[str]], optional): a list of tokens to stop generation at, e.g. ['/n/n']
|
|
312
|
+
|
|
313
|
+
Returns:
|
|
314
|
+
Dict[str, Any]: a response object containing the generated text.
|
|
315
|
+
"""
|
|
316
|
+
request = self._make_completion_request(
|
|
317
|
+
prompt, model, suffix, temperature, max_tokens, top_p, random_seed, stop
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
single_response = self._request("post", request, "v1/fim/completions", stream=False)
|
|
321
|
+
|
|
322
|
+
for response in single_response:
|
|
323
|
+
return ChatCompletionResponse(**response)
|
|
324
|
+
|
|
325
|
+
raise MistralException("No response received")
|
|
326
|
+
|
|
327
|
+
def completion_stream(
|
|
328
|
+
self,
|
|
329
|
+
model: str,
|
|
330
|
+
prompt: str,
|
|
331
|
+
suffix: Optional[str] = None,
|
|
332
|
+
temperature: Optional[float] = None,
|
|
333
|
+
max_tokens: Optional[int] = None,
|
|
334
|
+
top_p: Optional[float] = None,
|
|
335
|
+
random_seed: Optional[int] = None,
|
|
336
|
+
stop: Optional[List[str]] = None,
|
|
337
|
+
) -> Iterable[ChatCompletionStreamResponse]:
|
|
338
|
+
"""An asynchronous completion endpoint that streams responses.
|
|
339
|
+
|
|
340
|
+
Args:
|
|
341
|
+
model (str): model the name of the model to get completions with, e.g. codestral-latest
|
|
342
|
+
prompt (str): the prompt to complete
|
|
343
|
+
suffix (Optional[str]): the suffix to append to the prompt for fill-in-the-middle completion
|
|
344
|
+
temperature (Optional[float], optional): temperature the temperature to use for sampling, e.g. 0.5.
|
|
345
|
+
max_tokens (Optional[int], optional): the maximum number of tokens to generate, e.g. 100. Defaults to None.
|
|
346
|
+
top_p (Optional[float], optional): the cumulative probability of tokens to generate, e.g. 0.9.
|
|
347
|
+
Defaults to None.
|
|
348
|
+
random_seed (Optional[int], optional): the random seed to use for sampling, e.g. 42. Defaults to None.
|
|
349
|
+
stop (Optional[List[str]], optional): a list of tokens to stop generation at, e.g. ['/n/n']
|
|
350
|
+
|
|
351
|
+
Returns:
|
|
352
|
+
Iterable[Dict[str, Any]]: a generator that yields response objects containing the generated text.
|
|
353
|
+
"""
|
|
354
|
+
request = self._make_completion_request(
|
|
355
|
+
prompt, model, suffix, temperature, max_tokens, top_p, random_seed, stop, stream=True
|
|
356
|
+
)
|
|
357
|
+
|
|
358
|
+
response = self._request("post", request, "v1/fim/completions", stream=True)
|
|
359
|
+
|
|
360
|
+
for json_streamed_response in response:
|
|
361
|
+
yield ChatCompletionStreamResponse(**json_streamed_response)
|
|
@@ -73,6 +73,63 @@ class ClientBase(ABC):
|
|
|
73
73
|
|
|
74
74
|
return parsed_messages
|
|
75
75
|
|
|
76
|
+
def _make_completion_request(
|
|
77
|
+
self,
|
|
78
|
+
prompt: str,
|
|
79
|
+
model: Optional[str] = None,
|
|
80
|
+
suffix: Optional[str] = None,
|
|
81
|
+
temperature: Optional[float] = None,
|
|
82
|
+
max_tokens: Optional[int] = None,
|
|
83
|
+
top_p: Optional[float] = None,
|
|
84
|
+
random_seed: Optional[int] = None,
|
|
85
|
+
stop: Optional[List[str]] = None,
|
|
86
|
+
stream: Optional[bool] = False,
|
|
87
|
+
) -> Dict[str, Any]:
|
|
88
|
+
request_data: Dict[str, Any] = {
|
|
89
|
+
"prompt": prompt,
|
|
90
|
+
"suffix": suffix,
|
|
91
|
+
"model": model,
|
|
92
|
+
"stream": stream,
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if stop is not None:
|
|
96
|
+
request_data["stop"] = stop
|
|
97
|
+
|
|
98
|
+
if model is not None:
|
|
99
|
+
request_data["model"] = model
|
|
100
|
+
else:
|
|
101
|
+
if self._default_model is None:
|
|
102
|
+
raise MistralException(message="model must be provided")
|
|
103
|
+
request_data["model"] = self._default_model
|
|
104
|
+
|
|
105
|
+
request_data.update(
|
|
106
|
+
self._build_sampling_params(
|
|
107
|
+
temperature=temperature, max_tokens=max_tokens, top_p=top_p, random_seed=random_seed
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
self._logger.debug(f"Completion request: {request_data}")
|
|
112
|
+
|
|
113
|
+
return request_data
|
|
114
|
+
|
|
115
|
+
def _build_sampling_params(
|
|
116
|
+
self,
|
|
117
|
+
max_tokens: Optional[int],
|
|
118
|
+
random_seed: Optional[int],
|
|
119
|
+
temperature: Optional[float],
|
|
120
|
+
top_p: Optional[float],
|
|
121
|
+
) -> Dict[str, Any]:
|
|
122
|
+
params = {}
|
|
123
|
+
if temperature is not None:
|
|
124
|
+
params["temperature"] = temperature
|
|
125
|
+
if max_tokens is not None:
|
|
126
|
+
params["max_tokens"] = max_tokens
|
|
127
|
+
if top_p is not None:
|
|
128
|
+
params["top_p"] = top_p
|
|
129
|
+
if random_seed is not None:
|
|
130
|
+
params["random_seed"] = random_seed
|
|
131
|
+
return params
|
|
132
|
+
|
|
76
133
|
def _make_chat_request(
|
|
77
134
|
self,
|
|
78
135
|
messages: List[Any],
|
|
@@ -99,16 +156,14 @@ class ClientBase(ABC):
|
|
|
99
156
|
raise MistralException(message="model must be provided")
|
|
100
157
|
request_data["model"] = self._default_model
|
|
101
158
|
|
|
159
|
+
request_data.update(
|
|
160
|
+
self._build_sampling_params(
|
|
161
|
+
temperature=temperature, max_tokens=max_tokens, top_p=top_p, random_seed=random_seed
|
|
162
|
+
)
|
|
163
|
+
)
|
|
164
|
+
|
|
102
165
|
if tools is not None:
|
|
103
166
|
request_data["tools"] = self._parse_tools(tools)
|
|
104
|
-
if temperature is not None:
|
|
105
|
-
request_data["temperature"] = temperature
|
|
106
|
-
if max_tokens is not None:
|
|
107
|
-
request_data["max_tokens"] = max_tokens
|
|
108
|
-
if top_p is not None:
|
|
109
|
-
request_data["top_p"] = top_p
|
|
110
|
-
if random_seed is not None:
|
|
111
|
-
request_data["random_seed"] = random_seed
|
|
112
167
|
if stream is not None:
|
|
113
168
|
request_data["stream"] = stream
|
|
114
169
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|