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_gcp/chat.py
ADDED
|
@@ -0,0 +1,463 @@
|
|
|
1
|
+
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
+
|
|
3
|
+
from .basesdk import BaseSDK
|
|
4
|
+
from mistralai_gcp import models
|
|
5
|
+
from mistralai_gcp._hooks import HookContext
|
|
6
|
+
from mistralai_gcp.types import OptionalNullable, UNSET
|
|
7
|
+
import mistralai_gcp.utils as utils
|
|
8
|
+
from mistralai_gcp.utils import eventstreaming
|
|
9
|
+
from typing import Any, AsyncGenerator, Generator, List, Optional, Union
|
|
10
|
+
|
|
11
|
+
class Chat(BaseSDK):
|
|
12
|
+
r"""Chat Completion API."""
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def stream(
|
|
16
|
+
self, *,
|
|
17
|
+
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
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] = True,
|
|
24
|
+
stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
|
|
25
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
26
|
+
response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
|
|
27
|
+
tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
|
|
28
|
+
tool_choice: Optional[models.ToolChoice] = "auto",
|
|
29
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
30
|
+
server_url: Optional[str] = None,
|
|
31
|
+
timeout_ms: Optional[int] = None,
|
|
32
|
+
) -> Optional[Generator[models.CompletionEvent, None, None]]:
|
|
33
|
+
r"""Stream chat completion
|
|
34
|
+
|
|
35
|
+
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.
|
|
36
|
+
|
|
37
|
+
:param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
|
|
38
|
+
:param model: ID of the model to use. You can use the [List Available Models](/api#operation/listModels) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
|
|
39
|
+
: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.
|
|
40
|
+
: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.
|
|
41
|
+
: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.
|
|
42
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
43
|
+
:param stream:
|
|
44
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
45
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
46
|
+
:param response_format:
|
|
47
|
+
:param tools:
|
|
48
|
+
:param tool_choice:
|
|
49
|
+
:param retries: Override the default retry configuration for this method
|
|
50
|
+
:param server_url: Override the default server URL for this method
|
|
51
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
52
|
+
"""
|
|
53
|
+
base_url = None
|
|
54
|
+
url_variables = None
|
|
55
|
+
if timeout_ms is None:
|
|
56
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
57
|
+
|
|
58
|
+
if server_url is not None:
|
|
59
|
+
base_url = server_url
|
|
60
|
+
|
|
61
|
+
request = models.ChatCompletionStreamRequest(
|
|
62
|
+
model=model,
|
|
63
|
+
temperature=temperature,
|
|
64
|
+
top_p=top_p,
|
|
65
|
+
max_tokens=max_tokens,
|
|
66
|
+
min_tokens=min_tokens,
|
|
67
|
+
stream=stream,
|
|
68
|
+
stop=stop,
|
|
69
|
+
random_seed=random_seed,
|
|
70
|
+
messages=utils.get_pydantic_model(messages, List[models.Messages]),
|
|
71
|
+
response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
|
|
72
|
+
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
73
|
+
tool_choice=tool_choice,
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
req = self.build_request(
|
|
77
|
+
method="POST",
|
|
78
|
+
path="/streamRawPredict",
|
|
79
|
+
base_url=base_url,
|
|
80
|
+
url_variables=url_variables,
|
|
81
|
+
request=request,
|
|
82
|
+
request_body_required=True,
|
|
83
|
+
request_has_path_params=False,
|
|
84
|
+
request_has_query_params=True,
|
|
85
|
+
user_agent_header="user-agent",
|
|
86
|
+
accept_header_value="text/event-stream",
|
|
87
|
+
security=self.sdk_configuration.security,
|
|
88
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionStreamRequest),
|
|
89
|
+
timeout_ms=timeout_ms,
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
if retries == UNSET:
|
|
93
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
94
|
+
retries = self.sdk_configuration.retry_config
|
|
95
|
+
|
|
96
|
+
retry_config = None
|
|
97
|
+
if isinstance(retries, utils.RetryConfig):
|
|
98
|
+
retry_config = (retries, [
|
|
99
|
+
"429",
|
|
100
|
+
"500",
|
|
101
|
+
"502",
|
|
102
|
+
"503",
|
|
103
|
+
"504"
|
|
104
|
+
])
|
|
105
|
+
|
|
106
|
+
http_res = self.do_request(
|
|
107
|
+
hook_ctx=HookContext(operation_id="stream_chat", oauth2_scopes=[], security_source=self.sdk_configuration.security),
|
|
108
|
+
request=req,
|
|
109
|
+
error_status_codes=["422","4XX","5XX"],
|
|
110
|
+
stream=True,
|
|
111
|
+
retry_config=retry_config
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
data: Any = None
|
|
115
|
+
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
116
|
+
return eventstreaming.stream_events(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
|
|
117
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
118
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
119
|
+
raise models.HTTPValidationError(data=data)
|
|
120
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
121
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
122
|
+
|
|
123
|
+
content_type = http_res.headers.get("Content-Type")
|
|
124
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
async def stream_async(
|
|
129
|
+
self, *,
|
|
130
|
+
messages: Union[List[models.Messages], List[models.MessagesTypedDict]],
|
|
131
|
+
model: OptionalNullable[str] = UNSET,
|
|
132
|
+
temperature: Optional[float] = 0.7,
|
|
133
|
+
top_p: Optional[float] = 1,
|
|
134
|
+
max_tokens: OptionalNullable[int] = UNSET,
|
|
135
|
+
min_tokens: OptionalNullable[int] = UNSET,
|
|
136
|
+
stream: Optional[bool] = True,
|
|
137
|
+
stop: Optional[Union[models.Stop, models.StopTypedDict]] = None,
|
|
138
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
139
|
+
response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
|
|
140
|
+
tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
|
|
141
|
+
tool_choice: Optional[models.ToolChoice] = "auto",
|
|
142
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
143
|
+
server_url: Optional[str] = None,
|
|
144
|
+
timeout_ms: Optional[int] = None,
|
|
145
|
+
) -> Optional[AsyncGenerator[models.CompletionEvent, None]]:
|
|
146
|
+
r"""Stream chat completion
|
|
147
|
+
|
|
148
|
+
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.
|
|
149
|
+
|
|
150
|
+
:param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
|
|
151
|
+
:param model: ID of the model to use. You can use the [List Available Models](/api#operation/listModels) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
|
|
152
|
+
: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.
|
|
153
|
+
: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.
|
|
154
|
+
: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.
|
|
155
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
156
|
+
:param stream:
|
|
157
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
158
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
159
|
+
:param response_format:
|
|
160
|
+
:param tools:
|
|
161
|
+
:param tool_choice:
|
|
162
|
+
:param retries: Override the default retry configuration for this method
|
|
163
|
+
:param server_url: Override the default server URL for this method
|
|
164
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
165
|
+
"""
|
|
166
|
+
base_url = None
|
|
167
|
+
url_variables = None
|
|
168
|
+
if timeout_ms is None:
|
|
169
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
170
|
+
|
|
171
|
+
if server_url is not None:
|
|
172
|
+
base_url = server_url
|
|
173
|
+
|
|
174
|
+
request = models.ChatCompletionStreamRequest(
|
|
175
|
+
model=model,
|
|
176
|
+
temperature=temperature,
|
|
177
|
+
top_p=top_p,
|
|
178
|
+
max_tokens=max_tokens,
|
|
179
|
+
min_tokens=min_tokens,
|
|
180
|
+
stream=stream,
|
|
181
|
+
stop=stop,
|
|
182
|
+
random_seed=random_seed,
|
|
183
|
+
messages=utils.get_pydantic_model(messages, List[models.Messages]),
|
|
184
|
+
response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
|
|
185
|
+
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
186
|
+
tool_choice=tool_choice,
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
req = self.build_request(
|
|
190
|
+
method="POST",
|
|
191
|
+
path="/streamRawPredict",
|
|
192
|
+
base_url=base_url,
|
|
193
|
+
url_variables=url_variables,
|
|
194
|
+
request=request,
|
|
195
|
+
request_body_required=True,
|
|
196
|
+
request_has_path_params=False,
|
|
197
|
+
request_has_query_params=True,
|
|
198
|
+
user_agent_header="user-agent",
|
|
199
|
+
accept_header_value="text/event-stream",
|
|
200
|
+
security=self.sdk_configuration.security,
|
|
201
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionStreamRequest),
|
|
202
|
+
timeout_ms=timeout_ms,
|
|
203
|
+
)
|
|
204
|
+
|
|
205
|
+
if retries == UNSET:
|
|
206
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
207
|
+
retries = self.sdk_configuration.retry_config
|
|
208
|
+
|
|
209
|
+
retry_config = None
|
|
210
|
+
if isinstance(retries, utils.RetryConfig):
|
|
211
|
+
retry_config = (retries, [
|
|
212
|
+
"429",
|
|
213
|
+
"500",
|
|
214
|
+
"502",
|
|
215
|
+
"503",
|
|
216
|
+
"504"
|
|
217
|
+
])
|
|
218
|
+
|
|
219
|
+
http_res = await self.do_request_async(
|
|
220
|
+
hook_ctx=HookContext(operation_id="stream_chat", oauth2_scopes=[], security_source=self.sdk_configuration.security),
|
|
221
|
+
request=req,
|
|
222
|
+
error_status_codes=["422","4XX","5XX"],
|
|
223
|
+
stream=True,
|
|
224
|
+
retry_config=retry_config
|
|
225
|
+
)
|
|
226
|
+
|
|
227
|
+
data: Any = None
|
|
228
|
+
if utils.match_response(http_res, "200", "text/event-stream"):
|
|
229
|
+
return eventstreaming.stream_events_async(http_res, lambda raw: utils.unmarshal_json(raw, models.CompletionEvent), sentinel="[DONE]")
|
|
230
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
231
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
232
|
+
raise models.HTTPValidationError(data=data)
|
|
233
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
234
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
235
|
+
|
|
236
|
+
content_type = http_res.headers.get("Content-Type")
|
|
237
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
def create(
|
|
242
|
+
self, *,
|
|
243
|
+
messages: Union[List[models.ChatCompletionRequestMessages], List[models.ChatCompletionRequestMessagesTypedDict]],
|
|
244
|
+
model: OptionalNullable[str] = UNSET,
|
|
245
|
+
temperature: Optional[float] = 0.7,
|
|
246
|
+
top_p: Optional[float] = 1,
|
|
247
|
+
max_tokens: OptionalNullable[int] = UNSET,
|
|
248
|
+
min_tokens: OptionalNullable[int] = UNSET,
|
|
249
|
+
stream: Optional[bool] = False,
|
|
250
|
+
stop: Optional[Union[models.ChatCompletionRequestStop, models.ChatCompletionRequestStopTypedDict]] = None,
|
|
251
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
252
|
+
response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
|
|
253
|
+
tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
|
|
254
|
+
tool_choice: Optional[models.ChatCompletionRequestToolChoice] = "auto",
|
|
255
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
256
|
+
server_url: Optional[str] = None,
|
|
257
|
+
timeout_ms: Optional[int] = None,
|
|
258
|
+
) -> Optional[models.ChatCompletionResponse]:
|
|
259
|
+
r"""Chat Completion
|
|
260
|
+
|
|
261
|
+
Chat Completion
|
|
262
|
+
|
|
263
|
+
:param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
|
|
264
|
+
:param model: ID of the model to use. You can use the [List Available Models](/api#operation/listModels) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
|
|
265
|
+
: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.
|
|
266
|
+
: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.
|
|
267
|
+
: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.
|
|
268
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
269
|
+
: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.
|
|
270
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
271
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
272
|
+
:param response_format:
|
|
273
|
+
:param tools:
|
|
274
|
+
:param tool_choice:
|
|
275
|
+
:param retries: Override the default retry configuration for this method
|
|
276
|
+
:param server_url: Override the default server URL for this method
|
|
277
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
278
|
+
"""
|
|
279
|
+
base_url = None
|
|
280
|
+
url_variables = None
|
|
281
|
+
if timeout_ms is None:
|
|
282
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
283
|
+
|
|
284
|
+
if server_url is not None:
|
|
285
|
+
base_url = server_url
|
|
286
|
+
|
|
287
|
+
request = models.ChatCompletionRequest(
|
|
288
|
+
model=model,
|
|
289
|
+
temperature=temperature,
|
|
290
|
+
top_p=top_p,
|
|
291
|
+
max_tokens=max_tokens,
|
|
292
|
+
min_tokens=min_tokens,
|
|
293
|
+
stream=stream,
|
|
294
|
+
stop=stop,
|
|
295
|
+
random_seed=random_seed,
|
|
296
|
+
messages=utils.get_pydantic_model(messages, List[models.ChatCompletionRequestMessages]),
|
|
297
|
+
response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
|
|
298
|
+
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
299
|
+
tool_choice=tool_choice,
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
req = self.build_request(
|
|
303
|
+
method="POST",
|
|
304
|
+
path="/rawPredict",
|
|
305
|
+
base_url=base_url,
|
|
306
|
+
url_variables=url_variables,
|
|
307
|
+
request=request,
|
|
308
|
+
request_body_required=True,
|
|
309
|
+
request_has_path_params=False,
|
|
310
|
+
request_has_query_params=True,
|
|
311
|
+
user_agent_header="user-agent",
|
|
312
|
+
accept_header_value="application/json",
|
|
313
|
+
security=self.sdk_configuration.security,
|
|
314
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionRequest),
|
|
315
|
+
timeout_ms=timeout_ms,
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
if retries == UNSET:
|
|
319
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
320
|
+
retries = self.sdk_configuration.retry_config
|
|
321
|
+
|
|
322
|
+
retry_config = None
|
|
323
|
+
if isinstance(retries, utils.RetryConfig):
|
|
324
|
+
retry_config = (retries, [
|
|
325
|
+
"429",
|
|
326
|
+
"500",
|
|
327
|
+
"502",
|
|
328
|
+
"503",
|
|
329
|
+
"504"
|
|
330
|
+
])
|
|
331
|
+
|
|
332
|
+
http_res = self.do_request(
|
|
333
|
+
hook_ctx=HookContext(operation_id="chat_completion_v1_chat_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
|
|
334
|
+
request=req,
|
|
335
|
+
error_status_codes=["422","4XX","5XX"],
|
|
336
|
+
retry_config=retry_config
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
data: Any = None
|
|
340
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
341
|
+
return utils.unmarshal_json(http_res.text, Optional[models.ChatCompletionResponse])
|
|
342
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
343
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
344
|
+
raise models.HTTPValidationError(data=data)
|
|
345
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
346
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
347
|
+
|
|
348
|
+
content_type = http_res.headers.get("Content-Type")
|
|
349
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
async def create_async(
|
|
354
|
+
self, *,
|
|
355
|
+
messages: Union[List[models.ChatCompletionRequestMessages], List[models.ChatCompletionRequestMessagesTypedDict]],
|
|
356
|
+
model: OptionalNullable[str] = UNSET,
|
|
357
|
+
temperature: Optional[float] = 0.7,
|
|
358
|
+
top_p: Optional[float] = 1,
|
|
359
|
+
max_tokens: OptionalNullable[int] = UNSET,
|
|
360
|
+
min_tokens: OptionalNullable[int] = UNSET,
|
|
361
|
+
stream: Optional[bool] = False,
|
|
362
|
+
stop: Optional[Union[models.ChatCompletionRequestStop, models.ChatCompletionRequestStopTypedDict]] = None,
|
|
363
|
+
random_seed: OptionalNullable[int] = UNSET,
|
|
364
|
+
response_format: Optional[Union[models.ResponseFormat, models.ResponseFormatTypedDict]] = None,
|
|
365
|
+
tools: OptionalNullable[Union[List[models.Tool], List[models.ToolTypedDict]]] = UNSET,
|
|
366
|
+
tool_choice: Optional[models.ChatCompletionRequestToolChoice] = "auto",
|
|
367
|
+
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
368
|
+
server_url: Optional[str] = None,
|
|
369
|
+
timeout_ms: Optional[int] = None,
|
|
370
|
+
) -> Optional[models.ChatCompletionResponse]:
|
|
371
|
+
r"""Chat Completion
|
|
372
|
+
|
|
373
|
+
Chat Completion
|
|
374
|
+
|
|
375
|
+
:param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
|
|
376
|
+
:param model: ID of the model to use. You can use the [List Available Models](/api#operation/listModels) API to see all of your available models, or see our [Model overview](/models) for model descriptions.
|
|
377
|
+
: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.
|
|
378
|
+
: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.
|
|
379
|
+
: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.
|
|
380
|
+
:param min_tokens: The minimum number of tokens to generate in the completion.
|
|
381
|
+
: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.
|
|
382
|
+
:param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
|
|
383
|
+
:param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
|
|
384
|
+
:param response_format:
|
|
385
|
+
:param tools:
|
|
386
|
+
:param tool_choice:
|
|
387
|
+
:param retries: Override the default retry configuration for this method
|
|
388
|
+
:param server_url: Override the default server URL for this method
|
|
389
|
+
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
390
|
+
"""
|
|
391
|
+
base_url = None
|
|
392
|
+
url_variables = None
|
|
393
|
+
if timeout_ms is None:
|
|
394
|
+
timeout_ms = self.sdk_configuration.timeout_ms
|
|
395
|
+
|
|
396
|
+
if server_url is not None:
|
|
397
|
+
base_url = server_url
|
|
398
|
+
|
|
399
|
+
request = models.ChatCompletionRequest(
|
|
400
|
+
model=model,
|
|
401
|
+
temperature=temperature,
|
|
402
|
+
top_p=top_p,
|
|
403
|
+
max_tokens=max_tokens,
|
|
404
|
+
min_tokens=min_tokens,
|
|
405
|
+
stream=stream,
|
|
406
|
+
stop=stop,
|
|
407
|
+
random_seed=random_seed,
|
|
408
|
+
messages=utils.get_pydantic_model(messages, List[models.ChatCompletionRequestMessages]),
|
|
409
|
+
response_format=utils.get_pydantic_model(response_format, Optional[models.ResponseFormat]),
|
|
410
|
+
tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tool]]),
|
|
411
|
+
tool_choice=tool_choice,
|
|
412
|
+
)
|
|
413
|
+
|
|
414
|
+
req = self.build_request(
|
|
415
|
+
method="POST",
|
|
416
|
+
path="/rawPredict",
|
|
417
|
+
base_url=base_url,
|
|
418
|
+
url_variables=url_variables,
|
|
419
|
+
request=request,
|
|
420
|
+
request_body_required=True,
|
|
421
|
+
request_has_path_params=False,
|
|
422
|
+
request_has_query_params=True,
|
|
423
|
+
user_agent_header="user-agent",
|
|
424
|
+
accept_header_value="application/json",
|
|
425
|
+
security=self.sdk_configuration.security,
|
|
426
|
+
get_serialized_body=lambda: utils.serialize_request_body(request, False, False, "json", models.ChatCompletionRequest),
|
|
427
|
+
timeout_ms=timeout_ms,
|
|
428
|
+
)
|
|
429
|
+
|
|
430
|
+
if retries == UNSET:
|
|
431
|
+
if self.sdk_configuration.retry_config is not UNSET:
|
|
432
|
+
retries = self.sdk_configuration.retry_config
|
|
433
|
+
|
|
434
|
+
retry_config = None
|
|
435
|
+
if isinstance(retries, utils.RetryConfig):
|
|
436
|
+
retry_config = (retries, [
|
|
437
|
+
"429",
|
|
438
|
+
"500",
|
|
439
|
+
"502",
|
|
440
|
+
"503",
|
|
441
|
+
"504"
|
|
442
|
+
])
|
|
443
|
+
|
|
444
|
+
http_res = await self.do_request_async(
|
|
445
|
+
hook_ctx=HookContext(operation_id="chat_completion_v1_chat_completions_post", oauth2_scopes=[], security_source=self.sdk_configuration.security),
|
|
446
|
+
request=req,
|
|
447
|
+
error_status_codes=["422","4XX","5XX"],
|
|
448
|
+
retry_config=retry_config
|
|
449
|
+
)
|
|
450
|
+
|
|
451
|
+
data: Any = None
|
|
452
|
+
if utils.match_response(http_res, "200", "application/json"):
|
|
453
|
+
return utils.unmarshal_json(http_res.text, Optional[models.ChatCompletionResponse])
|
|
454
|
+
if utils.match_response(http_res, "422", "application/json"):
|
|
455
|
+
data = utils.unmarshal_json(http_res.text, models.HTTPValidationErrorData)
|
|
456
|
+
raise models.HTTPValidationError(data=data)
|
|
457
|
+
if utils.match_response(http_res, ["4XX","5XX"], "*"):
|
|
458
|
+
raise models.SDKError("API error occurred", http_res.status_code, http_res.text, http_res)
|
|
459
|
+
|
|
460
|
+
content_type = http_res.headers.get("Content-Type")
|
|
461
|
+
raise models.SDKError(f"Unexpected response received (code: {http_res.status_code}, type: {content_type})", http_res.status_code, http_res.text, http_res)
|
|
462
|
+
|
|
463
|
+
|