mistralai 0.4.2__py3-none-any.whl → 1.0.0__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/agents.py +434 -0
- mistralai/async_client.py +5 -413
- mistralai/basesdk.py +253 -0
- mistralai/chat.py +470 -0
- mistralai/client.py +5 -414
- mistralai/embeddings.py +182 -0
- mistralai/files.py +600 -84
- mistralai/fim.py +438 -0
- mistralai/fine_tuning.py +16 -0
- mistralai/httpclient.py +78 -0
- mistralai/jobs.py +822 -150
- mistralai/models/__init__.py +82 -0
- mistralai/models/agentscompletionrequest.py +96 -0
- mistralai/models/agentscompletionstreamrequest.py +92 -0
- mistralai/models/archiveftmodelout.py +19 -0
- mistralai/models/assistantmessage.py +53 -0
- mistralai/models/chatcompletionchoice.py +22 -0
- mistralai/models/chatcompletionrequest.py +109 -0
- mistralai/models/chatcompletionresponse.py +27 -0
- mistralai/models/chatcompletionstreamrequest.py +107 -0
- mistralai/models/checkpointout.py +25 -0
- mistralai/models/completionchunk.py +27 -0
- mistralai/models/completionevent.py +15 -0
- mistralai/models/completionresponsestreamchoice.py +48 -0
- mistralai/models/contentchunk.py +17 -0
- mistralai/models/delete_model_v1_models_model_id_deleteop.py +18 -0
- mistralai/models/deletefileout.py +24 -0
- mistralai/models/deletemodelout.py +25 -0
- mistralai/models/deltamessage.py +47 -0
- mistralai/models/detailedjobout.py +91 -0
- mistralai/models/embeddingrequest.py +61 -0
- mistralai/models/embeddingresponse.py +24 -0
- mistralai/models/embeddingresponsedata.py +19 -0
- mistralai/models/eventout.py +50 -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 +71 -0
- mistralai/models/fimcompletionrequest.py +94 -0
- mistralai/models/fimcompletionresponse.py +27 -0
- mistralai/models/fimcompletionstreamrequest.py +92 -0
- mistralai/models/finetuneablemodel.py +8 -0
- mistralai/models/ftmodelcapabilitiesout.py +21 -0
- mistralai/models/ftmodelout.py +65 -0
- mistralai/models/function.py +19 -0
- mistralai/models/functioncall.py +22 -0
- mistralai/models/githubrepositoryin.py +52 -0
- mistralai/models/githubrepositoryout.py +52 -0
- mistralai/models/httpvalidationerror.py +23 -0
- mistralai/models/jobin.py +73 -0
- mistralai/models/jobmetadataout.py +54 -0
- mistralai/models/jobout.py +107 -0
- mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +18 -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 +15 -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 +81 -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 +18 -0
- mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +21 -0
- mistralai/models/jobsout.py +20 -0
- mistralai/models/legacyjobmetadataout.py +80 -0
- mistralai/models/listfilesout.py +17 -0
- mistralai/models/metricout.py +50 -0
- mistralai/models/modelcapabilities.py +21 -0
- mistralai/models/modelcard.py +66 -0
- mistralai/models/modellist.py +18 -0
- mistralai/models/responseformat.py +18 -0
- mistralai/models/retrieve_model_v1_models_model_id_getop.py +18 -0
- mistralai/models/retrievefileout.py +71 -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 +50 -0
- mistralai/models/trainingfile.py +17 -0
- mistralai/models/trainingparameters.py +48 -0
- mistralai/models/trainingparametersin.py +56 -0
- mistralai/models/unarchiveftmodelout.py +19 -0
- mistralai/models/updateftmodelin.py +44 -0
- mistralai/models/uploadfileout.py +71 -0
- mistralai/models/usageinfo.py +18 -0
- mistralai/models/usermessage.py +26 -0
- mistralai/models/validationerror.py +24 -0
- mistralai/models/wandbintegration.py +56 -0
- mistralai/models/wandbintegrationout.py +52 -0
- mistralai/models_.py +928 -0
- mistralai/py.typed +1 -0
- mistralai/sdk.py +119 -0
- mistralai/sdkconfiguration.py +54 -0
- mistralai/types/__init__.py +21 -0
- mistralai/types/basemodel.py +39 -0
- mistralai/utils/__init__.py +86 -0
- mistralai/utils/annotations.py +19 -0
- mistralai/utils/enums.py +34 -0
- mistralai/utils/eventstreaming.py +178 -0
- mistralai/utils/forms.py +207 -0
- mistralai/utils/headers.py +136 -0
- mistralai/utils/logger.py +16 -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 +185 -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-1.0.0.dist-info}/LICENSE +1 -1
- mistralai-1.0.0.dist-info/METADATA +695 -0
- mistralai-1.0.0.dist-info/RECORD +235 -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 +253 -0
- mistralai_azure/chat.py +470 -0
- mistralai_azure/httpclient.py +78 -0
- mistralai_azure/models/__init__.py +28 -0
- mistralai_azure/models/assistantmessage.py +53 -0
- mistralai_azure/models/chatcompletionchoice.py +22 -0
- mistralai_azure/models/chatcompletionrequest.py +109 -0
- mistralai_azure/models/chatcompletionresponse.py +27 -0
- mistralai_azure/models/chatcompletionstreamrequest.py +107 -0
- mistralai_azure/models/completionchunk.py +27 -0
- mistralai_azure/models/completionevent.py +15 -0
- mistralai_azure/models/completionresponsestreamchoice.py +48 -0
- mistralai_azure/models/contentchunk.py +17 -0
- mistralai_azure/models/deltamessage.py +47 -0
- mistralai_azure/models/function.py +19 -0
- mistralai_azure/models/functioncall.py +22 -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 +50 -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 +107 -0
- mistralai_azure/sdkconfiguration.py +54 -0
- mistralai_azure/types/__init__.py +21 -0
- mistralai_azure/types/basemodel.py +39 -0
- mistralai_azure/utils/__init__.py +84 -0
- mistralai_azure/utils/annotations.py +19 -0
- mistralai_azure/utils/enums.py +34 -0
- mistralai_azure/utils/eventstreaming.py +178 -0
- mistralai_azure/utils/forms.py +207 -0
- mistralai_azure/utils/headers.py +136 -0
- mistralai_azure/utils/logger.py +16 -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 +253 -0
- mistralai_gcp/chat.py +458 -0
- mistralai_gcp/fim.py +438 -0
- mistralai_gcp/httpclient.py +78 -0
- mistralai_gcp/models/__init__.py +31 -0
- mistralai_gcp/models/assistantmessage.py +53 -0
- mistralai_gcp/models/chatcompletionchoice.py +22 -0
- mistralai_gcp/models/chatcompletionrequest.py +105 -0
- mistralai_gcp/models/chatcompletionresponse.py +27 -0
- mistralai_gcp/models/chatcompletionstreamrequest.py +103 -0
- mistralai_gcp/models/completionchunk.py +27 -0
- mistralai_gcp/models/completionevent.py +15 -0
- mistralai_gcp/models/completionresponsestreamchoice.py +48 -0
- mistralai_gcp/models/contentchunk.py +17 -0
- mistralai_gcp/models/deltamessage.py +47 -0
- mistralai_gcp/models/fimcompletionrequest.py +94 -0
- mistralai_gcp/models/fimcompletionresponse.py +27 -0
- mistralai_gcp/models/fimcompletionstreamrequest.py +92 -0
- mistralai_gcp/models/function.py +19 -0
- mistralai_gcp/models/functioncall.py +22 -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 +50 -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 +174 -0
- mistralai_gcp/sdkconfiguration.py +54 -0
- mistralai_gcp/types/__init__.py +21 -0
- mistralai_gcp/types/basemodel.py +39 -0
- mistralai_gcp/utils/__init__.py +84 -0
- mistralai_gcp/utils/annotations.py +19 -0
- mistralai_gcp/utils/enums.py +34 -0
- mistralai_gcp/utils/eventstreaming.py +178 -0
- mistralai_gcp/utils/forms.py +207 -0
- mistralai_gcp/utils/headers.py +136 -0
- mistralai_gcp/utils/logger.py +16 -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/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-1.0.0.dist-info}/WHEEL +0 -0
mistralai/__init__.py
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# MAKE SURE YOU UPDATE THE COPIES OF THIS FILES IN THE PROVIDERS'S PACKAGES WHEN YOU MAKE CHANGES HERE
|
|
2
|
+
from typing import Union
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
from .types import BeforeRequestContext, BeforeRequestHook
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CustomUserAgentHook(BeforeRequestHook):
|
|
10
|
+
def before_request(
|
|
11
|
+
self, hook_ctx: BeforeRequestContext, request: httpx.Request
|
|
12
|
+
) -> Union[httpx.Request, Exception]:
|
|
13
|
+
request.headers["user-agent"] = (
|
|
14
|
+
"mistral-client-python/" + request.headers["user-agent"].split(" ")[1]
|
|
15
|
+
)
|
|
16
|
+
return request
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
from typing import Union
|
|
3
|
+
|
|
4
|
+
import httpx
|
|
5
|
+
|
|
6
|
+
from .types import AfterSuccessContext, AfterSuccessHook
|
|
7
|
+
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
9
|
+
|
|
10
|
+
HEADER_MODEL_DEPRECATION_TIMESTAMP = "x-model-deprecation-timestamp"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DeprecationWarningHook(AfterSuccessHook):
|
|
14
|
+
|
|
15
|
+
def after_success(
|
|
16
|
+
self, hook_ctx: AfterSuccessContext, response: httpx.Response
|
|
17
|
+
) -> Union[httpx.Response, Exception]:
|
|
18
|
+
if HEADER_MODEL_DEPRECATION_TIMESTAMP in response.headers:
|
|
19
|
+
model = response.json()["model"]
|
|
20
|
+
# pylint: disable=logging-fstring-interpolation
|
|
21
|
+
logger.warning(
|
|
22
|
+
"WARNING: The model %s is deprecated and will be removed on %s. Please refer to https://docs.mistral.ai/getting-started/models/#api-versioning for more information.",
|
|
23
|
+
model,
|
|
24
|
+
response.headers[HEADER_MODEL_DEPRECATION_TIMESTAMP],
|
|
25
|
+
)
|
|
26
|
+
return response
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from .custom_user_agent import CustomUserAgentHook
|
|
2
|
+
from .deprecation_warning import DeprecationWarningHook
|
|
3
|
+
from .types import Hooks
|
|
4
|
+
|
|
5
|
+
# This file is only ever generated once on the first generation and then is free to be modified.
|
|
6
|
+
# Any hooks you wish to add should be registered in the init_hooks function. Feel free to define them
|
|
7
|
+
# in this file or in separate files in the hooks folder.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def init_hooks(hooks: Hooks):
|
|
11
|
+
# pylint: disable=unused-argument
|
|
12
|
+
"""Add hooks by calling hooks.register{sdk_init/before_request/after_success/after_error}Hook
|
|
13
|
+
with an instance of a hook that implements that specific Hook interface
|
|
14
|
+
Hooks are registered per SDK instance, and are valid for the lifetime of the SDK instance
|
|
15
|
+
"""
|
|
16
|
+
hooks.register_before_request_hook(CustomUserAgentHook())
|
|
17
|
+
hooks.register_after_success_hook(DeprecationWarningHook())
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
import httpx
|
|
4
|
+
from .types import SDKInitHook, BeforeRequestContext, BeforeRequestHook, AfterSuccessContext, AfterSuccessHook, AfterErrorContext, AfterErrorHook, Hooks
|
|
5
|
+
from .registration import init_hooks
|
|
6
|
+
from typing import List, Optional, Tuple
|
|
7
|
+
from mistralai.httpclient import HttpClient
|
|
8
|
+
|
|
9
|
+
class SDKHooks(Hooks):
|
|
10
|
+
def __init__(self) -> None:
|
|
11
|
+
self.sdk_init_hooks: List[SDKInitHook] = []
|
|
12
|
+
self.before_request_hooks: List[BeforeRequestHook] = []
|
|
13
|
+
self.after_success_hooks: List[AfterSuccessHook] = []
|
|
14
|
+
self.after_error_hooks: List[AfterErrorHook] = []
|
|
15
|
+
init_hooks(self)
|
|
16
|
+
|
|
17
|
+
def register_sdk_init_hook(self, hook: SDKInitHook) -> None:
|
|
18
|
+
self.sdk_init_hooks.append(hook)
|
|
19
|
+
|
|
20
|
+
def register_before_request_hook(self, hook: BeforeRequestHook) -> None:
|
|
21
|
+
self.before_request_hooks.append(hook)
|
|
22
|
+
|
|
23
|
+
def register_after_success_hook(self, hook: AfterSuccessHook) -> None:
|
|
24
|
+
self.after_success_hooks.append(hook)
|
|
25
|
+
|
|
26
|
+
def register_after_error_hook(self, hook: AfterErrorHook) -> None:
|
|
27
|
+
self.after_error_hooks.append(hook)
|
|
28
|
+
|
|
29
|
+
def sdk_init(self, base_url: str, client: HttpClient) -> Tuple[str, HttpClient]:
|
|
30
|
+
for hook in self.sdk_init_hooks:
|
|
31
|
+
base_url, client = hook.sdk_init(base_url, client)
|
|
32
|
+
return base_url, client
|
|
33
|
+
|
|
34
|
+
def before_request(self, hook_ctx: BeforeRequestContext, request: httpx.Request) -> httpx.Request:
|
|
35
|
+
for hook in self.before_request_hooks:
|
|
36
|
+
out = hook.before_request(hook_ctx, request)
|
|
37
|
+
if isinstance(out, Exception):
|
|
38
|
+
raise out
|
|
39
|
+
request = out
|
|
40
|
+
|
|
41
|
+
return request
|
|
42
|
+
|
|
43
|
+
def after_success(self, hook_ctx: AfterSuccessContext, response: httpx.Response) -> httpx.Response:
|
|
44
|
+
for hook in self.after_success_hooks:
|
|
45
|
+
out = hook.after_success(hook_ctx, response)
|
|
46
|
+
if isinstance(out, Exception):
|
|
47
|
+
raise out
|
|
48
|
+
response = out
|
|
49
|
+
return response
|
|
50
|
+
|
|
51
|
+
def after_error(self, hook_ctx: AfterErrorContext, response: Optional[httpx.Response], error: Optional[Exception]) -> Tuple[Optional[httpx.Response], Optional[Exception]]:
|
|
52
|
+
for hook in self.after_error_hooks:
|
|
53
|
+
result = hook.after_error(hook_ctx, response, error)
|
|
54
|
+
if isinstance(result, Exception):
|
|
55
|
+
raise result
|
|
56
|
+
response, error = result
|
|
57
|
+
return response, error
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from abc import ABC, abstractmethod
|
|
5
|
+
import httpx
|
|
6
|
+
from mistralai.httpclient import HttpClient
|
|
7
|
+
from typing import Any, Callable, List, Optional, Tuple, Union
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class HookContext:
|
|
11
|
+
operation_id: str
|
|
12
|
+
oauth2_scopes: Optional[List[str]] = None
|
|
13
|
+
security_source: Optional[Union[Any, Callable[[], Any]]] = None
|
|
14
|
+
|
|
15
|
+
def __init__(self, operation_id: str, oauth2_scopes: Optional[List[str]], security_source: Optional[Union[Any, Callable[[], Any]]]):
|
|
16
|
+
self.operation_id = operation_id
|
|
17
|
+
self.oauth2_scopes = oauth2_scopes
|
|
18
|
+
self.security_source = security_source
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class BeforeRequestContext(HookContext):
|
|
22
|
+
def __init__(self, hook_ctx: HookContext):
|
|
23
|
+
super().__init__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AfterSuccessContext(HookContext):
|
|
27
|
+
def __init__(self, hook_ctx: HookContext):
|
|
28
|
+
super().__init__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class AfterErrorContext(HookContext):
|
|
33
|
+
def __init__(self, hook_ctx: HookContext):
|
|
34
|
+
super().__init__(hook_ctx.operation_id, hook_ctx.oauth2_scopes, hook_ctx.security_source)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class SDKInitHook(ABC):
|
|
38
|
+
@abstractmethod
|
|
39
|
+
def sdk_init(self, base_url: str, client: HttpClient) -> Tuple[str, HttpClient]:
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class BeforeRequestHook(ABC):
|
|
44
|
+
@abstractmethod
|
|
45
|
+
def before_request(self, hook_ctx: BeforeRequestContext, request: httpx.Request) -> Union[httpx.Request, Exception]:
|
|
46
|
+
pass
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
class AfterSuccessHook(ABC):
|
|
50
|
+
@abstractmethod
|
|
51
|
+
def after_success(self, hook_ctx: AfterSuccessContext, response: httpx.Response) -> Union[httpx.Response, Exception]:
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class AfterErrorHook(ABC):
|
|
56
|
+
@abstractmethod
|
|
57
|
+
def after_error(self, hook_ctx: AfterErrorContext, response: Optional[httpx.Response], error: Optional[Exception]) -> Union[Tuple[Optional[httpx.Response], Optional[Exception]], Exception]:
|
|
58
|
+
pass
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class Hooks(ABC):
|
|
62
|
+
@abstractmethod
|
|
63
|
+
def register_sdk_init_hook(self, hook: SDKInitHook):
|
|
64
|
+
pass
|
|
65
|
+
|
|
66
|
+
@abstractmethod
|
|
67
|
+
def register_before_request_hook(self, hook: BeforeRequestHook):
|
|
68
|
+
pass
|
|
69
|
+
|
|
70
|
+
@abstractmethod
|
|
71
|
+
def register_after_success_hook(self, hook: AfterSuccessHook):
|
|
72
|
+
pass
|
|
73
|
+
|
|
74
|
+
@abstractmethod
|
|
75
|
+
def register_after_error_hook(self, hook: AfterErrorHook):
|
|
76
|
+
pass
|
mistralai/agents.py
ADDED
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from .basesdk import BaseSDK
|
|
4
|
+
from mistralai import models, utils
|
|
5
|
+
from mistralai._hooks import HookContext
|
|
6
|
+
from mistralai.types import Nullable, OptionalNullable, UNSET
|
|
7
|
+
from mistralai.utils import eventstreaming, get_security_from_env
|
|
8
|
+
from typing import Any, AsyncGenerator, Generator, List, Optional, Union
|
|
9
|
+
|
|
10
|
+
class Agents(BaseSDK):
|
|
11
|
+
r"""Agents API."""
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def complete(
|
|
15
|
+
self, *,
|
|
16
|
+
messages: Union[List[models.AgentsCompletionRequestMessages], List[models.AgentsCompletionRequestMessagesTypedDict]],
|
|
17
|
+
agent_id: str,
|
|
18
|
+
max_tokens: OptionalNullable[int] = UNSET,
|
|
19
|
+
min_tokens: OptionalNullable[int] = UNSET,
|
|
20
|
+
stream: Optional[bool] = False,
|
|
21
|
+
stop: Optional[Union[models.AgentsCompletionRequestStop, models.AgentsCompletionRequestStopTypedDict]] = None,
|
|
22
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
23
|
+
response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
|
|
24
|
+
tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
|
|
25
|
+
tool_choice: Optional[models.AgentsCompletionRequestToolChoice] = "auto",
|
|
26
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
27
|
+
server_url: Optional[str] = None,
|
|
28
|
+
timeout_ms: Optional[int] = None,
|
|
29
|
+
) -> Optional[models.ChatCompletionResponse]:
|
|
30
|
+
r"""Agents Completion
|
|
31
|
+
|
|
32
|
+
:param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
|
|
33
|
+
:param agent_id: The ID of the agent to use for this completion.
|
|
34
|
+
: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.
|
|
35
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
36
|
+
: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.
|
|
37
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
38
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
39
|
+
:param response_format:
|
|
40
|
+
:param tools:
|
|
41
|
+
:param tool_choice:
|
|
42
|
+
:param retries: Override the default retry configuration for this method
|
|
43
|
+
:param server_url: Override the default server URL for this method
|
|
44
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
45
|
+
"""
|
|
46
|
+
base_url = None
|
|
47
|
+
url_variables = None
|
|
48
|
+
if timeout_ms is None:
|
|
49
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
50
|
+
|
|
51
|
+
if server_url is not None:
|
|
52
|
+
base_url = server_url
|
|
53
|
+
|
|
54
|
+
request = models.AgentsCompletionRequest(
|
|
55
|
+
max_tokens=max_tokens,
|
|
56
|
+
min_tokens=min_tokens,
|
|
57
|
+
stream=stream,
|
|
58
|
+
stop=stop,
|
|
59
|
+
random_seed=random_seed,
|
|
60
|
+
messages=utils.get_pydantic_model(messages, List[models.AgentsCompletionRequestMessages]),
|
|
61
|
+
response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
|
|
62
|
+
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
63
|
+
tool_choice=tool_choice,
|
|
64
|
+
agent_id=agent_id,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
req = self.build_request(
|
|
68
|
+
method="POST",
|
|
69
|
+
path="/v1/agents/completions",
|
|
70
|
+
base_url=base_url,
|
|
71
|
+
url_variables=url_variables,
|
|
72
|
+
request=request,
|
|
73
|
+
request_body_required=True,
|
|
74
|
+
request_has_path_params=False,
|
|
75
|
+
request_has_query_params=True,
|
|
76
|
+
user_agent_header="user-agent",
|
|
77
|
+
accept_header_value="application/json",
|
|
78
|
+
security=self.sdk_configuration.security,
|
|
79
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.AgentsCompletionRequest),
|
|
80
|
+
timeout_ms=timeout_ms,
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
if retries == UNSET:
|
|
84
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
85
|
+
retries = self.sdk_configuration.retry_config
|
|
86
|
+
|
|
87
|
+
retry_config = None
|
|
88
|
+
if isinstance(retries, utils.RetryConfig):
|
|
89
|
+
retry_config = (retries, [
|
|
90
|
+
"429",
|
|
91
|
+
"500",
|
|
92
|
+
"502",
|
|
93
|
+
"503",
|
|
94
|
+
"504"
|
|
95
|
+
])
|
|
96
|
+
|
|
97
|
+
http_res = self.do_request(
|
|
98
|
+
hook_ctx=HookContext(operation_id="agents_completion_v1_agents_completions_post", oauth2_scopes=[], security_source=get_security_from_env(self.sdk_configuration.security, models.Security)),
|
|
99
|
+
request=req,
|
|
100
|
+
error_status_codes=["422","4XX","5XX"],
|
|
101
|
+
retry_config=retry_config
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
data: Any = None
|
|
105
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
106
|
+
return utils.unmarshal_json(http_res.text, Optional[models.ChatCompletionResponse])
|
|
107
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
108
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
109
|
+
raise models.HTTPValidationError(data=data)
|
|
110
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
111
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
112
|
+
|
|
113
|
+
content_type = http_res.headers.get("Content-Type")
|
|
114
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
async def complete_async(
|
|
119
|
+
self, *,
|
|
120
|
+
messages: Union[List[models.AgentsCompletionRequestMessages], List[models.AgentsCompletionRequestMessagesTypedDict]],
|
|
121
|
+
agent_id: str,
|
|
122
|
+
max_tokens: OptionalNullable[int] = UNSET,
|
|
123
|
+
min_tokens: OptionalNullable[int] = UNSET,
|
|
124
|
+
stream: Optional[bool] = False,
|
|
125
|
+
stop: Optional[Union[models.AgentsCompletionRequestStop, models.AgentsCompletionRequestStopTypedDict]] = None,
|
|
126
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
127
|
+
response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
|
|
128
|
+
tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
|
|
129
|
+
tool_choice: Optional[models.AgentsCompletionRequestToolChoice] = "auto",
|
|
130
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
131
|
+
server_url: Optional[str] = None,
|
|
132
|
+
timeout_ms: Optional[int] = None,
|
|
133
|
+
) -> Optional[models.ChatCompletionResponse]:
|
|
134
|
+
r"""Agents Completion
|
|
135
|
+
|
|
136
|
+
:param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
|
|
137
|
+
:param agent_id: The ID of the agent to use for this completion.
|
|
138
|
+
: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.
|
|
139
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
140
|
+
: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.
|
|
141
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
142
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
143
|
+
:param response_format:
|
|
144
|
+
:param tools:
|
|
145
|
+
:param tool_choice:
|
|
146
|
+
:param retries: Override the default retry configuration for this method
|
|
147
|
+
:param server_url: Override the default server URL for this method
|
|
148
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
149
|
+
"""
|
|
150
|
+
base_url = None
|
|
151
|
+
url_variables = None
|
|
152
|
+
if timeout_ms is None:
|
|
153
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
154
|
+
|
|
155
|
+
if server_url is not None:
|
|
156
|
+
base_url = server_url
|
|
157
|
+
|
|
158
|
+
request = models.AgentsCompletionRequest(
|
|
159
|
+
max_tokens=max_tokens,
|
|
160
|
+
min_tokens=min_tokens,
|
|
161
|
+
stream=stream,
|
|
162
|
+
stop=stop,
|
|
163
|
+
random_seed=random_seed,
|
|
164
|
+
messages=utils.get_pydantic_model(messages, List[models.AgentsCompletionRequestMessages]),
|
|
165
|
+
response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
|
|
166
|
+
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
167
|
+
tool_choice=tool_choice,
|
|
168
|
+
agent_id=agent_id,
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
req = self.build_request(
|
|
172
|
+
method="POST",
|
|
173
|
+
path="/v1/agents/completions",
|
|
174
|
+
base_url=base_url,
|
|
175
|
+
url_variables=url_variables,
|
|
176
|
+
request=request,
|
|
177
|
+
request_body_required=True,
|
|
178
|
+
request_has_path_params=False,
|
|
179
|
+
request_has_query_params=True,
|
|
180
|
+
user_agent_header="user-agent",
|
|
181
|
+
accept_header_value="application/json",
|
|
182
|
+
security=self.sdk_configuration.security,
|
|
183
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.AgentsCompletionRequest),
|
|
184
|
+
timeout_ms=timeout_ms,
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
if retries == UNSET:
|
|
188
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
189
|
+
retries = self.sdk_configuration.retry_config
|
|
190
|
+
|
|
191
|
+
retry_config = None
|
|
192
|
+
if isinstance(retries, utils.RetryConfig):
|
|
193
|
+
retry_config = (retries, [
|
|
194
|
+
"429",
|
|
195
|
+
"500",
|
|
196
|
+
"502",
|
|
197
|
+
"503",
|
|
198
|
+
"504"
|
|
199
|
+
])
|
|
200
|
+
|
|
201
|
+
http_res = await self.do_request_async(
|
|
202
|
+
hook_ctx=HookContext(operation_id="agents_completion_v1_agents_completions_post", oauth2_scopes=[], security_source=get_security_from_env(self.sdk_configuration.security, models.Security)),
|
|
203
|
+
request=req,
|
|
204
|
+
error_status_codes=["422","4XX","5XX"],
|
|
205
|
+
retry_config=retry_config
|
|
206
|
+
)
|
|
207
|
+
|
|
208
|
+
data: Any = None
|
|
209
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
210
|
+
return utils.unmarshal_json(http_res.text, Optional[models.ChatCompletionResponse])
|
|
211
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
212
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
213
|
+
raise models.HTTPValidationError(data=data)
|
|
214
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
215
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
216
|
+
|
|
217
|
+
content_type = http_res.headers.get("Content-Type")
|
|
218
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
def stream(
|
|
223
|
+
self, *,
|
|
224
|
+
model: Nullable[str],
|
|
225
|
+
prompt: str,
|
|
226
|
+
temperature: Optional[float] = 0.7,
|
|
227
|
+
top_p: Optional[float] = 1,
|
|
228
|
+
max_tokens: OptionalNullable[int] = UNSET,
|
|
229
|
+
min_tokens: OptionalNullable[int] = UNSET,
|
|
230
|
+
stream: Optional[bool] = True,
|
|
231
|
+
stop: Optional[Union[models.AgentsCompletionStreamRequestStop, models.AgentsCompletionStreamRequestStopTypedDict]] = None,
|
|
232
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
233
|
+
suffix: OptionalNullable[str] = UNSET,
|
|
234
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
235
|
+
server_url: Optional[str] = None,
|
|
236
|
+
timeout_ms: Optional[int] = None,
|
|
237
|
+
) -> Optional[Generator[models.CompletionEvent, None, None]]:
|
|
238
|
+
r"""Stream Agents completion
|
|
239
|
+
|
|
240
|
+
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.
|
|
241
|
+
|
|
242
|
+
:param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
|
|
243
|
+
:param prompt: The text/code to complete.
|
|
244
|
+
: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.
|
|
245
|
+
: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.
|
|
246
|
+
: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.
|
|
247
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
248
|
+
:param stream:
|
|
249
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
250
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
251
|
+
: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`.
|
|
252
|
+
:param retries: Override the default retry configuration for this method
|
|
253
|
+
:param server_url: Override the default server URL for this method
|
|
254
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
255
|
+
"""
|
|
256
|
+
base_url = None
|
|
257
|
+
url_variables = None
|
|
258
|
+
if timeout_ms is None:
|
|
259
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
260
|
+
|
|
261
|
+
if server_url is not None:
|
|
262
|
+
base_url = server_url
|
|
263
|
+
|
|
264
|
+
request = models.AgentsCompletionStreamRequest(
|
|
265
|
+
model=model,
|
|
266
|
+
temperature=temperature,
|
|
267
|
+
top_p=top_p,
|
|
268
|
+
max_tokens=max_tokens,
|
|
269
|
+
min_tokens=min_tokens,
|
|
270
|
+
stream=stream,
|
|
271
|
+
stop=stop,
|
|
272
|
+
random_seed=random_seed,
|
|
273
|
+
prompt=prompt,
|
|
274
|
+
suffix=suffix,
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
req = self.build_request(
|
|
278
|
+
method="POST",
|
|
279
|
+
path="/v1/agents/completions#stream",
|
|
280
|
+
base_url=base_url,
|
|
281
|
+
url_variables=url_variables,
|
|
282
|
+
request=request,
|
|
283
|
+
request_body_required=True,
|
|
284
|
+
request_has_path_params=False,
|
|
285
|
+
request_has_query_params=True,
|
|
286
|
+
user_agent_header="user-agent",
|
|
287
|
+
accept_header_value="text/event-stream",
|
|
288
|
+
security=self.sdk_configuration.security,
|
|
289
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.AgentsCompletionStreamRequest),
|
|
290
|
+
timeout_ms=timeout_ms,
|
|
291
|
+
)
|
|
292
|
+
|
|
293
|
+
if retries == UNSET:
|
|
294
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
295
|
+
retries = self.sdk_configuration.retry_config
|
|
296
|
+
|
|
297
|
+
retry_config = None
|
|
298
|
+
if isinstance(retries, utils.RetryConfig):
|
|
299
|
+
retry_config = (retries, [
|
|
300
|
+
"429",
|
|
301
|
+
"500",
|
|
302
|
+
"502",
|
|
303
|
+
"503",
|
|
304
|
+
"504"
|
|
305
|
+
])
|
|
306
|
+
|
|
307
|
+
http_res = self.do_request(
|
|
308
|
+
hook_ctx=HookContext(operation_id="stream_agents", oauth2_scopes=[], security_source=get_security_from_env(self.sdk_configuration.security, models.Security)),
|
|
309
|
+
request=req,
|
|
310
|
+
error_status_codes=["422","4XX","5XX"],
|
|
311
|
+
stream=True,
|
|
312
|
+
retry_config=retry_config
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
data: Any = None
|
|
316
|
+
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
317
|
+
return eventstreaming.stream_events(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
|
|
318
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
319
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
320
|
+
raise models.HTTPValidationError(data=data)
|
|
321
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
322
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
323
|
+
|
|
324
|
+
content_type = http_res.headers.get("Content-Type")
|
|
325
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
async def stream_async(
|
|
330
|
+
self, *,
|
|
331
|
+
model: Nullable[str],
|
|
332
|
+
prompt: str,
|
|
333
|
+
temperature: Optional[float] = 0.7,
|
|
334
|
+
top_p: Optional[float] = 1,
|
|
335
|
+
max_tokens: OptionalNullable[int] = UNSET,
|
|
336
|
+
min_tokens: OptionalNullable[int] = UNSET,
|
|
337
|
+
stream: Optional[bool] = True,
|
|
338
|
+
stop: Optional[Union[models.AgentsCompletionStreamRequestStop, models.AgentsCompletionStreamRequestStopTypedDict]] = None,
|
|
339
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
340
|
+
suffix: OptionalNullable[str] = UNSET,
|
|
341
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
342
|
+
server_url: Optional[str] = None,
|
|
343
|
+
timeout_ms: Optional[int] = None,
|
|
344
|
+
) -> Optional[AsyncGenerator[models.CompletionEvent, None]]:
|
|
345
|
+
r"""Stream Agents completion
|
|
346
|
+
|
|
347
|
+
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.
|
|
348
|
+
|
|
349
|
+
:param model: ID of the model to use. Only compatible for now with: - `codestral-2405` - `codestral-latest`
|
|
350
|
+
:param prompt: The text/code to complete.
|
|
351
|
+
: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.
|
|
352
|
+
: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.
|
|
353
|
+
: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.
|
|
354
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
355
|
+
:param stream:
|
|
356
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
357
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
358
|
+
: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`.
|
|
359
|
+
:param retries: Override the default retry configuration for this method
|
|
360
|
+
:param server_url: Override the default server URL for this method
|
|
361
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
362
|
+
"""
|
|
363
|
+
base_url = None
|
|
364
|
+
url_variables = None
|
|
365
|
+
if timeout_ms is None:
|
|
366
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
367
|
+
|
|
368
|
+
if server_url is not None:
|
|
369
|
+
base_url = server_url
|
|
370
|
+
|
|
371
|
+
request = models.AgentsCompletionStreamRequest(
|
|
372
|
+
model=model,
|
|
373
|
+
temperature=temperature,
|
|
374
|
+
top_p=top_p,
|
|
375
|
+
max_tokens=max_tokens,
|
|
376
|
+
min_tokens=min_tokens,
|
|
377
|
+
stream=stream,
|
|
378
|
+
stop=stop,
|
|
379
|
+
random_seed=random_seed,
|
|
380
|
+
prompt=prompt,
|
|
381
|
+
suffix=suffix,
|
|
382
|
+
)
|
|
383
|
+
|
|
384
|
+
req = self.build_request(
|
|
385
|
+
method="POST",
|
|
386
|
+
path="/v1/agents/completions#stream",
|
|
387
|
+
base_url=base_url,
|
|
388
|
+
url_variables=url_variables,
|
|
389
|
+
request=request,
|
|
390
|
+
request_body_required=True,
|
|
391
|
+
request_has_path_params=False,
|
|
392
|
+
request_has_query_params=True,
|
|
393
|
+
user_agent_header="user-agent",
|
|
394
|
+
accept_header_value="text/event-stream",
|
|
395
|
+
security=self.sdk_configuration.security,
|
|
396
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.AgentsCompletionStreamRequest),
|
|
397
|
+
timeout_ms=timeout_ms,
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
if retries == UNSET:
|
|
401
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
402
|
+
retries = self.sdk_configuration.retry_config
|
|
403
|
+
|
|
404
|
+
retry_config = None
|
|
405
|
+
if isinstance(retries, utils.RetryConfig):
|
|
406
|
+
retry_config = (retries, [
|
|
407
|
+
"429",
|
|
408
|
+
"500",
|
|
409
|
+
"502",
|
|
410
|
+
"503",
|
|
411
|
+
"504"
|
|
412
|
+
])
|
|
413
|
+
|
|
414
|
+
http_res = await self.do_request_async(
|
|
415
|
+
hook_ctx=HookContext(operation_id="stream_agents", oauth2_scopes=[], security_source=get_security_from_env(self.sdk_configuration.security, models.Security)),
|
|
416
|
+
request=req,
|
|
417
|
+
error_status_codes=["422","4XX","5XX"],
|
|
418
|
+
stream=True,
|
|
419
|
+
retry_config=retry_config
|
|
420
|
+
)
|
|
421
|
+
|
|
422
|
+
data: Any = None
|
|
423
|
+
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
424
|
+
return eventstreaming.stream_events_async(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
|
|
425
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
426
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
427
|
+
raise models.HTTPValidationError(data=data)
|
|
428
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
429
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
430
|
+
|
|
431
|
+
content_type = http_res.headers.get("Content-Type")
|
|
432
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
433
|
+
|
|
434
|
+
|