mistralai 0.4.2__py3-none-any.whl → 0.5.5a50__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/__init__.py +5 -0
- mistralai/_hooks/__init__.py +5 -0
- mistralai/_hooks/custom_user_agent.py +16 -0
- mistralai/_hooks/deprecation_warning.py +26 -0
- mistralai/_hooks/registration.py +17 -0
- mistralai/_hooks/sdkhooks.py +57 -0
- mistralai/_hooks/types.py +76 -0
- mistralai/async_client.py +5 -413
- mistralai/basesdk.py +216 -0
- mistralai/chat.py +475 -0
- mistralai/client.py +5 -414
- mistralai/embeddings.py +182 -0
- mistralai/files.py +600 -84
- mistralai/fim.py +439 -0
- mistralai/fine_tuning.py +855 -0
- mistralai/httpclient.py +78 -0
- mistralai/models/__init__.py +80 -0
- mistralai/models/archiveftmodelout.py +19 -0
- mistralai/models/assistantmessage.py +58 -0
- mistralai/models/chatcompletionchoice.py +33 -0
- mistralai/models/chatcompletionrequest.py +114 -0
- mistralai/models/chatcompletionresponse.py +27 -0
- mistralai/models/chatcompletionstreamrequest.py +112 -0
- mistralai/models/checkpointout.py +25 -0
- mistralai/models/completionchunk.py +27 -0
- mistralai/models/completionevent.py +15 -0
- mistralai/models/completionresponsestreamchoice.py +53 -0
- mistralai/models/contentchunk.py +17 -0
- mistralai/models/delete_model_v1_models_model_id_deleteop.py +16 -0
- mistralai/models/deletefileout.py +24 -0
- mistralai/models/deletemodelout.py +25 -0
- mistralai/models/deltamessage.py +52 -0
- mistralai/models/detailedjobout.py +96 -0
- mistralai/models/embeddingrequest.py +66 -0
- mistralai/models/embeddingresponse.py +24 -0
- mistralai/models/embeddingresponsedata.py +19 -0
- mistralai/models/eventout.py +55 -0
- mistralai/models/files_api_routes_delete_fileop.py +16 -0
- mistralai/models/files_api_routes_retrieve_fileop.py +16 -0
- mistralai/models/files_api_routes_upload_fileop.py +51 -0
- mistralai/models/fileschema.py +76 -0
- mistralai/models/fimcompletionrequest.py +99 -0
- mistralai/models/fimcompletionresponse.py +27 -0
- mistralai/models/fimcompletionstreamrequest.py +97 -0
- mistralai/models/finetuneablemodel.py +8 -0
- mistralai/models/ftmodelcapabilitiesout.py +21 -0
- mistralai/models/ftmodelout.py +70 -0
- mistralai/models/function.py +19 -0
- mistralai/models/functioncall.py +16 -0
- mistralai/models/githubrepositoryin.py +57 -0
- mistralai/models/githubrepositoryout.py +57 -0
- mistralai/models/httpvalidationerror.py +23 -0
- mistralai/models/jobin.py +78 -0
- mistralai/models/jobmetadataout.py +59 -0
- mistralai/models/jobout.py +112 -0
- mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +16 -0
- mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +18 -0
- mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +73 -0
- mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +18 -0
- mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +86 -0
- mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +16 -0
- mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +16 -0
- mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +19 -0
- mistralai/models/jobsout.py +20 -0
- mistralai/models/legacyjobmetadataout.py +85 -0
- mistralai/models/listfilesout.py +17 -0
- mistralai/models/metricout.py +55 -0
- mistralai/models/modelcapabilities.py +21 -0
- mistralai/models/modelcard.py +71 -0
- mistralai/models/modellist.py +18 -0
- mistralai/models/responseformat.py +18 -0
- mistralai/models/retrieve_model_v1_models_model_id_getop.py +16 -0
- mistralai/models/retrievefileout.py +76 -0
- mistralai/models/sampletype.py +7 -0
- mistralai/models/sdkerror.py +22 -0
- mistralai/models/security.py +16 -0
- mistralai/models/source.py +7 -0
- mistralai/models/systemmessage.py +26 -0
- mistralai/models/textchunk.py +17 -0
- mistralai/models/tool.py +18 -0
- mistralai/models/toolcall.py +20 -0
- mistralai/models/toolmessage.py +55 -0
- mistralai/models/trainingfile.py +17 -0
- mistralai/models/trainingparameters.py +53 -0
- mistralai/models/trainingparametersin.py +61 -0
- mistralai/models/unarchiveftmodelout.py +19 -0
- mistralai/models/updateftmodelin.py +49 -0
- mistralai/models/uploadfileout.py +76 -0
- mistralai/models/usageinfo.py +18 -0
- mistralai/models/usermessage.py +26 -0
- mistralai/models/validationerror.py +24 -0
- mistralai/models/wandbintegration.py +61 -0
- mistralai/models/wandbintegrationout.py +57 -0
- mistralai/models_.py +928 -0
- mistralai/py.typed +1 -0
- mistralai/sdk.py +111 -0
- mistralai/sdkconfiguration.py +53 -0
- mistralai/types/__init__.py +21 -0
- mistralai/types/basemodel.py +35 -0
- mistralai/utils/__init__.py +82 -0
- mistralai/utils/annotations.py +19 -0
- mistralai/utils/enums.py +34 -0
- mistralai/utils/eventstreaming.py +179 -0
- mistralai/utils/forms.py +207 -0
- mistralai/utils/headers.py +136 -0
- mistralai/utils/metadata.py +118 -0
- mistralai/utils/queryparams.py +203 -0
- mistralai/utils/requestbodies.py +66 -0
- mistralai/utils/retries.py +216 -0
- mistralai/utils/security.py +182 -0
- mistralai/utils/serializers.py +181 -0
- mistralai/utils/url.py +150 -0
- mistralai/utils/values.py +128 -0
- {mistralai-0.4.2.dist-info → mistralai-0.5.5a50.dist-info}/LICENSE +1 -1
- mistralai-0.5.5a50.dist-info/METADATA +626 -0
- mistralai-0.5.5a50.dist-info/RECORD +228 -0
- mistralai_azure/__init__.py +5 -0
- mistralai_azure/_hooks/__init__.py +5 -0
- mistralai_azure/_hooks/custom_user_agent.py +16 -0
- mistralai_azure/_hooks/registration.py +15 -0
- mistralai_azure/_hooks/sdkhooks.py +57 -0
- mistralai_azure/_hooks/types.py +76 -0
- mistralai_azure/basesdk.py +215 -0
- mistralai_azure/chat.py +475 -0
- mistralai_azure/httpclient.py +78 -0
- mistralai_azure/models/__init__.py +28 -0
- mistralai_azure/models/assistantmessage.py +58 -0
- mistralai_azure/models/chatcompletionchoice.py +33 -0
- mistralai_azure/models/chatcompletionrequest.py +114 -0
- mistralai_azure/models/chatcompletionresponse.py +27 -0
- mistralai_azure/models/chatcompletionstreamrequest.py +112 -0
- mistralai_azure/models/completionchunk.py +27 -0
- mistralai_azure/models/completionevent.py +15 -0
- mistralai_azure/models/completionresponsestreamchoice.py +53 -0
- mistralai_azure/models/contentchunk.py +17 -0
- mistralai_azure/models/deltamessage.py +52 -0
- mistralai_azure/models/function.py +19 -0
- mistralai_azure/models/functioncall.py +16 -0
- mistralai_azure/models/httpvalidationerror.py +23 -0
- mistralai_azure/models/responseformat.py +18 -0
- mistralai_azure/models/sdkerror.py +22 -0
- mistralai_azure/models/security.py +16 -0
- mistralai_azure/models/systemmessage.py +26 -0
- mistralai_azure/models/textchunk.py +17 -0
- mistralai_azure/models/tool.py +18 -0
- mistralai_azure/models/toolcall.py +20 -0
- mistralai_azure/models/toolmessage.py +55 -0
- mistralai_azure/models/usageinfo.py +18 -0
- mistralai_azure/models/usermessage.py +26 -0
- mistralai_azure/models/validationerror.py +24 -0
- mistralai_azure/py.typed +1 -0
- mistralai_azure/sdk.py +102 -0
- mistralai_azure/sdkconfiguration.py +53 -0
- mistralai_azure/types/__init__.py +21 -0
- mistralai_azure/types/basemodel.py +35 -0
- mistralai_azure/utils/__init__.py +80 -0
- mistralai_azure/utils/annotations.py +19 -0
- mistralai_azure/utils/enums.py +34 -0
- mistralai_azure/utils/eventstreaming.py +179 -0
- mistralai_azure/utils/forms.py +207 -0
- mistralai_azure/utils/headers.py +136 -0
- mistralai_azure/utils/metadata.py +118 -0
- mistralai_azure/utils/queryparams.py +203 -0
- mistralai_azure/utils/requestbodies.py +66 -0
- mistralai_azure/utils/retries.py +216 -0
- mistralai_azure/utils/security.py +168 -0
- mistralai_azure/utils/serializers.py +181 -0
- mistralai_azure/utils/url.py +150 -0
- mistralai_azure/utils/values.py +128 -0
- mistralai_gcp/__init__.py +5 -0
- mistralai_gcp/_hooks/__init__.py +5 -0
- mistralai_gcp/_hooks/custom_user_agent.py +16 -0
- mistralai_gcp/_hooks/registration.py +15 -0
- mistralai_gcp/_hooks/sdkhooks.py +57 -0
- mistralai_gcp/_hooks/types.py +76 -0
- mistralai_gcp/basesdk.py +215 -0
- mistralai_gcp/chat.py +463 -0
- mistralai_gcp/fim.py +439 -0
- mistralai_gcp/httpclient.py +78 -0
- mistralai_gcp/models/__init__.py +31 -0
- mistralai_gcp/models/assistantmessage.py +58 -0
- mistralai_gcp/models/chatcompletionchoice.py +33 -0
- mistralai_gcp/models/chatcompletionrequest.py +110 -0
- mistralai_gcp/models/chatcompletionresponse.py +27 -0
- mistralai_gcp/models/chatcompletionstreamrequest.py +108 -0
- mistralai_gcp/models/completionchunk.py +27 -0
- mistralai_gcp/models/completionevent.py +15 -0
- mistralai_gcp/models/completionresponsestreamchoice.py +53 -0
- mistralai_gcp/models/contentchunk.py +17 -0
- mistralai_gcp/models/deltamessage.py +52 -0
- mistralai_gcp/models/fimcompletionrequest.py +99 -0
- mistralai_gcp/models/fimcompletionresponse.py +27 -0
- mistralai_gcp/models/fimcompletionstreamrequest.py +97 -0
- mistralai_gcp/models/function.py +19 -0
- mistralai_gcp/models/functioncall.py +16 -0
- mistralai_gcp/models/httpvalidationerror.py +23 -0
- mistralai_gcp/models/responseformat.py +18 -0
- mistralai_gcp/models/sdkerror.py +22 -0
- mistralai_gcp/models/security.py +16 -0
- mistralai_gcp/models/systemmessage.py +26 -0
- mistralai_gcp/models/textchunk.py +17 -0
- mistralai_gcp/models/tool.py +18 -0
- mistralai_gcp/models/toolcall.py +20 -0
- mistralai_gcp/models/toolmessage.py +55 -0
- mistralai_gcp/models/usageinfo.py +18 -0
- mistralai_gcp/models/usermessage.py +26 -0
- mistralai_gcp/models/validationerror.py +24 -0
- mistralai_gcp/py.typed +1 -0
- mistralai_gcp/sdk.py +165 -0
- mistralai_gcp/sdkconfiguration.py +53 -0
- mistralai_gcp/types/__init__.py +21 -0
- mistralai_gcp/types/basemodel.py +35 -0
- mistralai_gcp/utils/__init__.py +80 -0
- mistralai_gcp/utils/annotations.py +19 -0
- mistralai_gcp/utils/enums.py +34 -0
- mistralai_gcp/utils/eventstreaming.py +179 -0
- mistralai_gcp/utils/forms.py +207 -0
- mistralai_gcp/utils/headers.py +136 -0
- mistralai_gcp/utils/metadata.py +118 -0
- mistralai_gcp/utils/queryparams.py +203 -0
- mistralai_gcp/utils/requestbodies.py +66 -0
- mistralai_gcp/utils/retries.py +216 -0
- mistralai_gcp/utils/security.py +168 -0
- mistralai_gcp/utils/serializers.py +181 -0
- mistralai_gcp/utils/url.py +150 -0
- mistralai_gcp/utils/values.py +128 -0
- py.typed +1 -0
- mistralai/client_base.py +0 -211
- mistralai/constants.py +0 -5
- mistralai/exceptions.py +0 -54
- mistralai/jobs.py +0 -172
- mistralai/models/chat_completion.py +0 -93
- mistralai/models/common.py +0 -9
- mistralai/models/embeddings.py +0 -19
- mistralai/models/files.py +0 -23
- mistralai/models/jobs.py +0 -100
- mistralai/models/models.py +0 -39
- mistralai-0.4.2.dist-info/METADATA +0 -82
- mistralai-0.4.2.dist-info/RECORD +0 -20
- {mistralai-0.4.2.dist-info → mistralai-0.5.5a50.dist-info}/WHEEL +0 -0
mistralai/fim.py
ADDED
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from .basesdk import BaseSDK
|
|
4
|
+
from mistralai import models
|
|
5
|
+
from mistralai._hooks import HookContext
|
|
6
|
+
from mistralai.types import OptionalNullable, UNSET
|
|
7
|
+
import mistralai.utils as utils
|
|
8
|
+
from mistralai.utils import eventstreaming
|
|
9
|
+
from typing import Any, AsyncGenerator, Generator, Optional, Union
|
|
10
|
+
|
|
11
|
+
class Fim(BaseSDK):
|
|
12
|
+
r"""Fill-in-the-middle API."""
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def create(
|
|
16
|
+
self, *,
|
|
17
|
+
prompt: str,
|
|
18
|
+
model: OptionalNullable[str] = UNSET,
|
|
19
|
+
temperature: Optional[float] = 0.7,
|
|
20
|
+
top_p: Optional[float] = 1,
|
|
21
|
+
max_tokens: OptionalNullable[int] = UNSET,
|
|
22
|
+
min_tokens: OptionalNullable[int] = UNSET,
|
|
23
|
+
stream: Optional[bool] = False,
|
|
24
|
+
stop: Optional[Union[models.FIMCompletionRequestStop, models.FIMCompletionRequestStopTypedDict]] = None,
|
|
25
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
26
|
+
suffix: OptionalNullable[str] = UNSET,
|
|
27
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
28
|
+
server_url: Optional[str] = None,
|
|
29
|
+
timeout_ms: Optional[int] = None,
|
|
30
|
+
) -> Optional[models.FIMCompletionResponse]:
|
|
31
|
+
r"""Fim Completion
|
|
32
|
+
|
|
33
|
+
FIM completion.
|
|
34
|
+
|
|
35
|
+
:param prompt: The text/code to complete.
|
|
36
|
+
:param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
|
|
37
|
+
:param temperature: What sampling temperature to use, between 0.0 and 1.0. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
|
|
38
|
+
:param top_p: Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
|
|
39
|
+
: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.
|
|
40
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
41
|
+
: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.
|
|
42
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
43
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
44
|
+
:param suffix: Optional text/code that adds more context for the model. When given a `prompt` and a `suffix` the model will fill what is between them. When `suffix` is not provided, the model will simply execute completion starting with `prompt`.
|
|
45
|
+
:param retries: Override the default retry configuration for this method
|
|
46
|
+
:param server_url: Override the default server URL for this method
|
|
47
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
48
|
+
"""
|
|
49
|
+
base_url = None
|
|
50
|
+
url_variables = None
|
|
51
|
+
if timeout_ms is None:
|
|
52
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
53
|
+
|
|
54
|
+
if server_url is not None:
|
|
55
|
+
base_url = server_url
|
|
56
|
+
|
|
57
|
+
request = models.FIMCompletionRequest(
|
|
58
|
+
model=model,
|
|
59
|
+
temperature=temperature,
|
|
60
|
+
top_p=top_p,
|
|
61
|
+
max_tokens=max_tokens,
|
|
62
|
+
min_tokens=min_tokens,
|
|
63
|
+
stream=stream,
|
|
64
|
+
stop=stop,
|
|
65
|
+
random_seed=random_seed,
|
|
66
|
+
prompt=prompt,
|
|
67
|
+
suffix=suffix,
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
req = self.build_request(
|
|
71
|
+
method="POST",
|
|
72
|
+
path="/v1/fim/completions",
|
|
73
|
+
base_url=base_url,
|
|
74
|
+
url_variables=url_variables,
|
|
75
|
+
request=request,
|
|
76
|
+
request_body_required=True,
|
|
77
|
+
request_has_path_params=False,
|
|
78
|
+
request_has_query_params=True,
|
|
79
|
+
user_agent_header="user-agent",
|
|
80
|
+
accept_header_value="application/json",
|
|
81
|
+
security=self.sdk_configuration.security,
|
|
82
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionRequest),
|
|
83
|
+
timeout_ms=timeout_ms,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
if retries == UNSET:
|
|
87
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
88
|
+
retries = self.sdk_configuration.retry_config
|
|
89
|
+
|
|
90
|
+
retry_config = None
|
|
91
|
+
if isinstance(retries, utils.RetryConfig):
|
|
92
|
+
retry_config = (retries, [
|
|
93
|
+
"429",
|
|
94
|
+
"500",
|
|
95
|
+
"502",
|
|
96
|
+
"503",
|
|
97
|
+
"504"
|
|
98
|
+
])
|
|
99
|
+
|
|
100
|
+
http_res = self.do_request(
|
|
101
|
+
hook_ctx=HookContext(operation_id="fim_completion_v1_fim_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
|
|
102
|
+
request=req,
|
|
103
|
+
error_status_codes=["422","4XX","5XX"],
|
|
104
|
+
retry_config=retry_config
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
data: Any = None
|
|
108
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
109
|
+
return utils.unmarshal_json(http_res.text, Optional[models.FIMCompletionResponse])
|
|
110
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
111
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
112
|
+
raise models.HTTPValidationError(data=data)
|
|
113
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
114
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
115
|
+
|
|
116
|
+
content_type = http_res.headers.get("Content-Type")
|
|
117
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
async def create_async(
|
|
122
|
+
self, *,
|
|
123
|
+
prompt: str,
|
|
124
|
+
model: OptionalNullable[str] = UNSET,
|
|
125
|
+
temperature: Optional[float] = 0.7,
|
|
126
|
+
top_p: Optional[float] = 1,
|
|
127
|
+
max_tokens: OptionalNullable[int] = UNSET,
|
|
128
|
+
min_tokens: OptionalNullable[int] = UNSET,
|
|
129
|
+
stream: Optional[bool] = False,
|
|
130
|
+
stop: Optional[Union[models.FIMCompletionRequestStop, models.FIMCompletionRequestStopTypedDict]] = None,
|
|
131
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
132
|
+
suffix: OptionalNullable[str] = UNSET,
|
|
133
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
134
|
+
server_url: Optional[str] = None,
|
|
135
|
+
timeout_ms: Optional[int] = None,
|
|
136
|
+
) -> Optional[models.FIMCompletionResponse]:
|
|
137
|
+
r"""Fim Completion
|
|
138
|
+
|
|
139
|
+
FIM completion.
|
|
140
|
+
|
|
141
|
+
:param prompt: The text/code to complete.
|
|
142
|
+
:param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
|
|
143
|
+
:param temperature: What sampling temperature to use, between 0.0 and 1.0. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
|
|
144
|
+
:param top_p: Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
|
|
145
|
+
: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.
|
|
146
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
147
|
+
: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.
|
|
148
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
149
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
150
|
+
:param suffix: Optional text/code that adds more context for the model. When given a `prompt` and a `suffix` the model will fill what is between them. When `suffix` is not provided, the model will simply execute completion starting with `prompt`.
|
|
151
|
+
:param retries: Override the default retry configuration for this method
|
|
152
|
+
:param server_url: Override the default server URL for this method
|
|
153
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
154
|
+
"""
|
|
155
|
+
base_url = None
|
|
156
|
+
url_variables = None
|
|
157
|
+
if timeout_ms is None:
|
|
158
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
159
|
+
|
|
160
|
+
if server_url is not None:
|
|
161
|
+
base_url = server_url
|
|
162
|
+
|
|
163
|
+
request = models.FIMCompletionRequest(
|
|
164
|
+
model=model,
|
|
165
|
+
temperature=temperature,
|
|
166
|
+
top_p=top_p,
|
|
167
|
+
max_tokens=max_tokens,
|
|
168
|
+
min_tokens=min_tokens,
|
|
169
|
+
stream=stream,
|
|
170
|
+
stop=stop,
|
|
171
|
+
random_seed=random_seed,
|
|
172
|
+
prompt=prompt,
|
|
173
|
+
suffix=suffix,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
req = self.build_request(
|
|
177
|
+
method="POST",
|
|
178
|
+
path="/v1/fim/completions",
|
|
179
|
+
base_url=base_url,
|
|
180
|
+
url_variables=url_variables,
|
|
181
|
+
request=request,
|
|
182
|
+
request_body_required=True,
|
|
183
|
+
request_has_path_params=False,
|
|
184
|
+
request_has_query_params=True,
|
|
185
|
+
user_agent_header="user-agent",
|
|
186
|
+
accept_header_value="application/json",
|
|
187
|
+
security=self.sdk_configuration.security,
|
|
188
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionRequest),
|
|
189
|
+
timeout_ms=timeout_ms,
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
if retries == UNSET:
|
|
193
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
194
|
+
retries = self.sdk_configuration.retry_config
|
|
195
|
+
|
|
196
|
+
retry_config = None
|
|
197
|
+
if isinstance(retries, utils.RetryConfig):
|
|
198
|
+
retry_config = (retries, [
|
|
199
|
+
"429",
|
|
200
|
+
"500",
|
|
201
|
+
"502",
|
|
202
|
+
"503",
|
|
203
|
+
"504"
|
|
204
|
+
])
|
|
205
|
+
|
|
206
|
+
http_res = await self.do_request_async(
|
|
207
|
+
hook_ctx=HookContext(operation_id="fim_completion_v1_fim_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
|
|
208
|
+
request=req,
|
|
209
|
+
error_status_codes=["422","4XX","5XX"],
|
|
210
|
+
retry_config=retry_config
|
|
211
|
+
)
|
|
212
|
+
|
|
213
|
+
data: Any = None
|
|
214
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
215
|
+
return utils.unmarshal_json(http_res.text, Optional[models.FIMCompletionResponse])
|
|
216
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
217
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
218
|
+
raise models.HTTPValidationError(data=data)
|
|
219
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
220
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
221
|
+
|
|
222
|
+
content_type = http_res.headers.get("Content-Type")
|
|
223
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def stream(
|
|
228
|
+
self, *,
|
|
229
|
+
prompt: str,
|
|
230
|
+
model: OptionalNullable[str] = UNSET,
|
|
231
|
+
temperature: Optional[float] = 0.7,
|
|
232
|
+
top_p: Optional[float] = 1,
|
|
233
|
+
max_tokens: OptionalNullable[int] = UNSET,
|
|
234
|
+
min_tokens: OptionalNullable[int] = UNSET,
|
|
235
|
+
stream: Optional[bool] = True,
|
|
236
|
+
stop: Optional[Union[models.FIMCompletionStreamRequestStop, models.FIMCompletionStreamRequestStopTypedDict]] = None,
|
|
237
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
238
|
+
suffix: OptionalNullable[str] = UNSET,
|
|
239
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
240
|
+
server_url: Optional[str] = None,
|
|
241
|
+
timeout_ms: Optional[int] = None,
|
|
242
|
+
) -> Optional[Generator[models.CompletionEvent, None, None]]:
|
|
243
|
+
r"""Stream fim completion
|
|
244
|
+
|
|
245
|
+
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.
|
|
246
|
+
|
|
247
|
+
:param prompt: The text/code to complete.
|
|
248
|
+
:param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
|
|
249
|
+
:param temperature: What sampling temperature to use, between 0.0 and 1.0. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
|
|
250
|
+
:param top_p: Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
|
|
251
|
+
: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.
|
|
252
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
253
|
+
:param stream:
|
|
254
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
255
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
256
|
+
:param suffix: Optional text/code that adds more context for the model. When given a `prompt` and a `suffix` the model will fill what is between them. When `suffix` is not provided, the model will simply execute completion starting with `prompt`.
|
|
257
|
+
:param retries: Override the default retry configuration for this method
|
|
258
|
+
:param server_url: Override the default server URL for this method
|
|
259
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
260
|
+
"""
|
|
261
|
+
base_url = None
|
|
262
|
+
url_variables = None
|
|
263
|
+
if timeout_ms is None:
|
|
264
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
265
|
+
|
|
266
|
+
if server_url is not None:
|
|
267
|
+
base_url = server_url
|
|
268
|
+
|
|
269
|
+
request = models.FIMCompletionStreamRequest(
|
|
270
|
+
model=model,
|
|
271
|
+
temperature=temperature,
|
|
272
|
+
top_p=top_p,
|
|
273
|
+
max_tokens=max_tokens,
|
|
274
|
+
min_tokens=min_tokens,
|
|
275
|
+
stream=stream,
|
|
276
|
+
stop=stop,
|
|
277
|
+
random_seed=random_seed,
|
|
278
|
+
prompt=prompt,
|
|
279
|
+
suffix=suffix,
|
|
280
|
+
)
|
|
281
|
+
|
|
282
|
+
req = self.build_request(
|
|
283
|
+
method="POST",
|
|
284
|
+
path="/v1/fim/completions#stream",
|
|
285
|
+
base_url=base_url,
|
|
286
|
+
url_variables=url_variables,
|
|
287
|
+
request=request,
|
|
288
|
+
request_body_required=True,
|
|
289
|
+
request_has_path_params=False,
|
|
290
|
+
request_has_query_params=True,
|
|
291
|
+
user_agent_header="user-agent",
|
|
292
|
+
accept_header_value="text/event-stream",
|
|
293
|
+
security=self.sdk_configuration.security,
|
|
294
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionStreamRequest),
|
|
295
|
+
timeout_ms=timeout_ms,
|
|
296
|
+
)
|
|
297
|
+
|
|
298
|
+
if retries == UNSET:
|
|
299
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
300
|
+
retries = self.sdk_configuration.retry_config
|
|
301
|
+
|
|
302
|
+
retry_config = None
|
|
303
|
+
if isinstance(retries, utils.RetryConfig):
|
|
304
|
+
retry_config = (retries, [
|
|
305
|
+
"429",
|
|
306
|
+
"500",
|
|
307
|
+
"502",
|
|
308
|
+
"503",
|
|
309
|
+
"504"
|
|
310
|
+
])
|
|
311
|
+
|
|
312
|
+
http_res = self.do_request(
|
|
313
|
+
hook_ctx=HookContext(operation_id="stream_fim", oauth2_scopes=[], security_source=self.sdk_configuration.security),
|
|
314
|
+
request=req,
|
|
315
|
+
error_status_codes=["422","4XX","5XX"],
|
|
316
|
+
stream=True,
|
|
317
|
+
retry_config=retry_config
|
|
318
|
+
)
|
|
319
|
+
|
|
320
|
+
data: Any = None
|
|
321
|
+
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
322
|
+
return eventstreaming.stream_events(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
|
|
323
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
324
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
325
|
+
raise models.HTTPValidationError(data=data)
|
|
326
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
327
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
328
|
+
|
|
329
|
+
content_type = http_res.headers.get("Content-Type")
|
|
330
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
async def stream_async(
|
|
335
|
+
self, *,
|
|
336
|
+
prompt: str,
|
|
337
|
+
model: OptionalNullable[str] = UNSET,
|
|
338
|
+
temperature: Optional[float] = 0.7,
|
|
339
|
+
top_p: Optional[float] = 1,
|
|
340
|
+
max_tokens: OptionalNullable[int] = UNSET,
|
|
341
|
+
min_tokens: OptionalNullable[int] = UNSET,
|
|
342
|
+
stream: Optional[bool] = True,
|
|
343
|
+
stop: Optional[Union[models.FIMCompletionStreamRequestStop, models.FIMCompletionStreamRequestStopTypedDict]] = None,
|
|
344
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
345
|
+
suffix: OptionalNullable[str] = UNSET,
|
|
346
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
347
|
+
server_url: Optional[str] = None,
|
|
348
|
+
timeout_ms: Optional[int] = None,
|
|
349
|
+
) -> Optional[AsyncGenerator[models.CompletionEvent, None]]:
|
|
350
|
+
r"""Stream fim completion
|
|
351
|
+
|
|
352
|
+
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.
|
|
353
|
+
|
|
354
|
+
:param prompt: The text/code to complete.
|
|
355
|
+
:param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
|
|
356
|
+
:param temperature: What sampling temperature to use, between 0.0 and 1.0. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both.
|
|
357
|
+
:param top_p: Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
|
|
358
|
+
: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.
|
|
359
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
360
|
+
:param stream:
|
|
361
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
362
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
363
|
+
:param suffix: Optional text/code that adds more context for the model. When given a `prompt` and a `suffix` the model will fill what is between them. When `suffix` is not provided, the model will simply execute completion starting with `prompt`.
|
|
364
|
+
:param retries: Override the default retry configuration for this method
|
|
365
|
+
:param server_url: Override the default server URL for this method
|
|
366
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
367
|
+
"""
|
|
368
|
+
base_url = None
|
|
369
|
+
url_variables = None
|
|
370
|
+
if timeout_ms is None:
|
|
371
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
372
|
+
|
|
373
|
+
if server_url is not None:
|
|
374
|
+
base_url = server_url
|
|
375
|
+
|
|
376
|
+
request = models.FIMCompletionStreamRequest(
|
|
377
|
+
model=model,
|
|
378
|
+
temperature=temperature,
|
|
379
|
+
top_p=top_p,
|
|
380
|
+
max_tokens=max_tokens,
|
|
381
|
+
min_tokens=min_tokens,
|
|
382
|
+
stream=stream,
|
|
383
|
+
stop=stop,
|
|
384
|
+
random_seed=random_seed,
|
|
385
|
+
prompt=prompt,
|
|
386
|
+
suffix=suffix,
|
|
387
|
+
)
|
|
388
|
+
|
|
389
|
+
req = self.build_request(
|
|
390
|
+
method="POST",
|
|
391
|
+
path="/v1/fim/completions#stream",
|
|
392
|
+
base_url=base_url,
|
|
393
|
+
url_variables=url_variables,
|
|
394
|
+
request=request,
|
|
395
|
+
request_body_required=True,
|
|
396
|
+
request_has_path_params=False,
|
|
397
|
+
request_has_query_params=True,
|
|
398
|
+
user_agent_header="user-agent",
|
|
399
|
+
accept_header_value="text/event-stream",
|
|
400
|
+
security=self.sdk_configuration.security,
|
|
401
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.FIMCompletionStreamRequest),
|
|
402
|
+
timeout_ms=timeout_ms,
|
|
403
|
+
)
|
|
404
|
+
|
|
405
|
+
if retries == UNSET:
|
|
406
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
407
|
+
retries = self.sdk_configuration.retry_config
|
|
408
|
+
|
|
409
|
+
retry_config = None
|
|
410
|
+
if isinstance(retries, utils.RetryConfig):
|
|
411
|
+
retry_config = (retries, [
|
|
412
|
+
"429",
|
|
413
|
+
"500",
|
|
414
|
+
"502",
|
|
415
|
+
"503",
|
|
416
|
+
"504"
|
|
417
|
+
])
|
|
418
|
+
|
|
419
|
+
http_res = await self.do_request_async(
|
|
420
|
+
hook_ctx=HookContext(operation_id="stream_fim", oauth2_scopes=[], security_source=self.sdk_configuration.security),
|
|
421
|
+
request=req,
|
|
422
|
+
error_status_codes=["422","4XX","5XX"],
|
|
423
|
+
stream=True,
|
|
424
|
+
retry_config=retry_config
|
|
425
|
+
)
|
|
426
|
+
|
|
427
|
+
data: Any = None
|
|
428
|
+
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
429
|
+
return eventstreaming.stream_events_async(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
|
|
430
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
431
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
432
|
+
raise models.HTTPValidationError(data=data)
|
|
433
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
434
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
435
|
+
|
|
436
|
+
content_type = http_res.headers.get("Content-Type")
|
|
437
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
438
|
+
|
|
439
|
+
|