openrouter 0.1.2__py3-none-any.whl → 0.6.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.
- openrouter/_version.py +2 -2
- openrouter/analytics.py +28 -2
- openrouter/api_keys.py +210 -14
- openrouter/chat.py +192 -200
- openrouter/components/__init__.py +229 -285
- openrouter/components/_schema10.py +39 -0
- openrouter/components/_schema14.py +11 -0
- openrouter/components/_schema17.py +154 -0
- openrouter/components/{_schema3.py → _schema19.py} +28 -22
- openrouter/components/{_schema0.py → _schema5.py} +7 -5
- openrouter/components/assistantmessage.py +32 -1
- openrouter/components/chatgenerationparams.py +57 -343
- openrouter/components/chatmessagecontentitemimage.py +4 -4
- openrouter/components/chatresponsechoice.py +1 -6
- openrouter/components/chatstreamingmessagechunk.py +3 -3
- openrouter/components/developermessage.py +41 -0
- openrouter/components/message.py +6 -39
- openrouter/components/model.py +7 -1
- openrouter/components/openresponsesrequest.py +31 -39
- openrouter/components/outputmodality.py +1 -0
- openrouter/components/providername.py +2 -0
- openrouter/components/providerpreferences.py +2 -10
- openrouter/components/publicendpoint.py +8 -24
- openrouter/components/publicpricing.py +3 -24
- openrouter/credits.py +86 -14
- openrouter/embeddings.py +92 -20
- openrouter/endpoints.py +62 -2
- openrouter/generations.py +26 -0
- openrouter/guardrails.py +3367 -0
- openrouter/models_.py +120 -12
- openrouter/oauth.py +90 -22
- openrouter/operations/__init__.py +601 -30
- openrouter/operations/bulkassignkeystoguardrail.py +116 -0
- openrouter/operations/bulkassignmemberstoguardrail.py +116 -0
- openrouter/operations/bulkunassignkeysfromguardrail.py +116 -0
- openrouter/operations/bulkunassignmembersfromguardrail.py +116 -0
- openrouter/operations/createauthkeyscode.py +81 -3
- openrouter/operations/createcoinbasecharge.py +82 -2
- openrouter/operations/createembeddings.py +82 -3
- openrouter/operations/createguardrail.py +325 -0
- openrouter/operations/createkeys.py +81 -3
- openrouter/operations/createresponses.py +84 -3
- openrouter/operations/deleteguardrail.py +104 -0
- openrouter/operations/deletekeys.py +69 -3
- openrouter/operations/exchangeauthcodeforapikey.py +81 -3
- openrouter/operations/getcredits.py +70 -1
- openrouter/operations/getcurrentkey.py +81 -3
- openrouter/operations/getgeneration.py +248 -3
- openrouter/operations/getguardrail.py +228 -0
- openrouter/operations/getkey.py +64 -1
- openrouter/operations/getmodels.py +95 -5
- openrouter/operations/getuseractivity.py +62 -1
- openrouter/operations/list.py +63 -1
- openrouter/operations/listembeddingsmodels.py +74 -0
- openrouter/operations/listendpoints.py +65 -2
- openrouter/operations/listendpointszdr.py +70 -2
- openrouter/operations/listguardrailkeyassignments.py +192 -0
- openrouter/operations/listguardrailmemberassignments.py +187 -0
- openrouter/operations/listguardrails.py +238 -0
- openrouter/operations/listkeyassignments.py +180 -0
- openrouter/operations/listmemberassignments.py +175 -0
- openrouter/operations/listmodelscount.py +74 -0
- openrouter/operations/listmodelsuser.py +70 -2
- openrouter/operations/listproviders.py +70 -2
- openrouter/operations/sendchatcompletionrequest.py +87 -3
- openrouter/operations/updateguardrail.py +334 -0
- openrouter/operations/updatekeys.py +63 -0
- openrouter/providers.py +36 -2
- openrouter/responses.py +178 -148
- openrouter/sdk.py +5 -8
- openrouter/types/models.py +378 -0
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/METADATA +5 -1
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/RECORD +76 -63
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/WHEEL +1 -1
- openrouter/completions.py +0 -361
- openrouter/components/completionchoice.py +0 -82
- openrouter/components/completioncreateparams.py +0 -277
- openrouter/components/completionlogprobs.py +0 -54
- openrouter/components/completionresponse.py +0 -46
- openrouter/components/completionusage.py +0 -19
- openrouter/operations/getparameters.py +0 -123
- openrouter/parameters.py +0 -237
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/licenses/LICENSE +0 -0
- {openrouter-0.1.2.dist-info → openrouter-0.6.0.dist-info}/top_level.txt +0 -0
openrouter/completions.py
DELETED
|
@@ -1,361 +0,0 @@
|
|
|
1
|
-
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
-
|
|
3
|
-
from .basesdk import BaseSDK
|
|
4
|
-
from openrouter import components, errors, utils
|
|
5
|
-
from openrouter._hooks import HookContext
|
|
6
|
-
from openrouter.types import OptionalNullable, UNSET
|
|
7
|
-
from openrouter.utils import get_security_from_env
|
|
8
|
-
from openrouter.utils.unmarshal_json_response import unmarshal_json_response
|
|
9
|
-
from typing import Any, Dict, List, Mapping, Optional, Union
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class Completions(BaseSDK):
|
|
13
|
-
def generate(
|
|
14
|
-
self,
|
|
15
|
-
*,
|
|
16
|
-
prompt: Union[components.Prompt, components.PromptTypedDict],
|
|
17
|
-
model: Optional[str] = None,
|
|
18
|
-
models: Optional[List[str]] = None,
|
|
19
|
-
best_of: OptionalNullable[int] = UNSET,
|
|
20
|
-
echo: OptionalNullable[bool] = UNSET,
|
|
21
|
-
frequency_penalty: OptionalNullable[float] = UNSET,
|
|
22
|
-
logit_bias: OptionalNullable[Dict[str, float]] = UNSET,
|
|
23
|
-
logprobs: OptionalNullable[int] = UNSET,
|
|
24
|
-
max_tokens: OptionalNullable[int] = UNSET,
|
|
25
|
-
n: OptionalNullable[int] = UNSET,
|
|
26
|
-
presence_penalty: OptionalNullable[float] = UNSET,
|
|
27
|
-
seed: OptionalNullable[int] = UNSET,
|
|
28
|
-
stop: OptionalNullable[
|
|
29
|
-
Union[
|
|
30
|
-
components.CompletionCreateParamsStop,
|
|
31
|
-
components.CompletionCreateParamsStopTypedDict,
|
|
32
|
-
]
|
|
33
|
-
] = UNSET,
|
|
34
|
-
stream: Optional[bool] = False,
|
|
35
|
-
stream_options: OptionalNullable[
|
|
36
|
-
Union[components.StreamOptions, components.StreamOptionsTypedDict]
|
|
37
|
-
] = UNSET,
|
|
38
|
-
suffix: OptionalNullable[str] = UNSET,
|
|
39
|
-
temperature: OptionalNullable[float] = UNSET,
|
|
40
|
-
top_p: OptionalNullable[float] = UNSET,
|
|
41
|
-
user: Optional[str] = None,
|
|
42
|
-
metadata: OptionalNullable[Dict[str, str]] = UNSET,
|
|
43
|
-
response_format: OptionalNullable[
|
|
44
|
-
Union[
|
|
45
|
-
components.CompletionCreateParamsResponseFormatUnion,
|
|
46
|
-
components.CompletionCreateParamsResponseFormatUnionTypedDict,
|
|
47
|
-
]
|
|
48
|
-
] = UNSET,
|
|
49
|
-
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
50
|
-
server_url: Optional[str] = None,
|
|
51
|
-
timeout_ms: Optional[int] = None,
|
|
52
|
-
http_headers: Optional[Mapping[str, str]] = None,
|
|
53
|
-
) -> components.CompletionResponse:
|
|
54
|
-
r"""Create a completion
|
|
55
|
-
|
|
56
|
-
Creates a completion for the provided prompt and parameters. Supports both streaming and non-streaming modes.
|
|
57
|
-
|
|
58
|
-
:param prompt:
|
|
59
|
-
:param model:
|
|
60
|
-
:param models:
|
|
61
|
-
:param best_of:
|
|
62
|
-
:param echo:
|
|
63
|
-
:param frequency_penalty:
|
|
64
|
-
:param logit_bias:
|
|
65
|
-
:param logprobs:
|
|
66
|
-
:param max_tokens:
|
|
67
|
-
:param n:
|
|
68
|
-
:param presence_penalty:
|
|
69
|
-
:param seed:
|
|
70
|
-
:param stop:
|
|
71
|
-
:param stream:
|
|
72
|
-
:param stream_options:
|
|
73
|
-
:param suffix:
|
|
74
|
-
:param temperature:
|
|
75
|
-
:param top_p:
|
|
76
|
-
:param user:
|
|
77
|
-
:param metadata:
|
|
78
|
-
:param response_format:
|
|
79
|
-
:param retries: Override the default retry configuration for this method
|
|
80
|
-
:param server_url: Override the default server URL for this method
|
|
81
|
-
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
82
|
-
:param http_headers: Additional headers to set or replace on requests.
|
|
83
|
-
"""
|
|
84
|
-
base_url = None
|
|
85
|
-
url_variables = None
|
|
86
|
-
if timeout_ms is None:
|
|
87
|
-
timeout_ms = self.sdk_configuration.timeout_ms
|
|
88
|
-
|
|
89
|
-
if server_url is not None:
|
|
90
|
-
base_url = server_url
|
|
91
|
-
else:
|
|
92
|
-
base_url = self._get_url(base_url, url_variables)
|
|
93
|
-
|
|
94
|
-
request = components.CompletionCreateParams(
|
|
95
|
-
model=model,
|
|
96
|
-
models=models,
|
|
97
|
-
prompt=prompt,
|
|
98
|
-
best_of=best_of,
|
|
99
|
-
echo=echo,
|
|
100
|
-
frequency_penalty=frequency_penalty,
|
|
101
|
-
logit_bias=logit_bias,
|
|
102
|
-
logprobs=logprobs,
|
|
103
|
-
max_tokens=max_tokens,
|
|
104
|
-
n=n,
|
|
105
|
-
presence_penalty=presence_penalty,
|
|
106
|
-
seed=seed,
|
|
107
|
-
stop=stop,
|
|
108
|
-
stream=stream,
|
|
109
|
-
stream_options=utils.get_pydantic_model(
|
|
110
|
-
stream_options, OptionalNullable[components.StreamOptions]
|
|
111
|
-
),
|
|
112
|
-
suffix=suffix,
|
|
113
|
-
temperature=temperature,
|
|
114
|
-
top_p=top_p,
|
|
115
|
-
user=user,
|
|
116
|
-
metadata=metadata,
|
|
117
|
-
response_format=utils.get_pydantic_model(
|
|
118
|
-
response_format,
|
|
119
|
-
OptionalNullable[components.CompletionCreateParamsResponseFormatUnion],
|
|
120
|
-
),
|
|
121
|
-
)
|
|
122
|
-
|
|
123
|
-
req = self._build_request(
|
|
124
|
-
method="POST",
|
|
125
|
-
path="/completions",
|
|
126
|
-
base_url=base_url,
|
|
127
|
-
url_variables=url_variables,
|
|
128
|
-
request=request,
|
|
129
|
-
request_body_required=True,
|
|
130
|
-
request_has_path_params=False,
|
|
131
|
-
request_has_query_params=True,
|
|
132
|
-
user_agent_header="user-agent",
|
|
133
|
-
accept_header_value="application/json",
|
|
134
|
-
http_headers=http_headers,
|
|
135
|
-
security=self.sdk_configuration.security,
|
|
136
|
-
get_serialized_body=lambda: utils.serialize_request_body(
|
|
137
|
-
request, False, False, "json", components.CompletionCreateParams
|
|
138
|
-
),
|
|
139
|
-
allow_empty_value=None,
|
|
140
|
-
timeout_ms=timeout_ms,
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
if retries == UNSET:
|
|
144
|
-
if self.sdk_configuration.retry_config is not UNSET:
|
|
145
|
-
retries = self.sdk_configuration.retry_config
|
|
146
|
-
|
|
147
|
-
retry_config = None
|
|
148
|
-
if isinstance(retries, utils.RetryConfig):
|
|
149
|
-
retry_config = (retries, ["429", "500", "502", "503", "504"])
|
|
150
|
-
|
|
151
|
-
http_res = self.do_request(
|
|
152
|
-
hook_ctx=HookContext(
|
|
153
|
-
config=self.sdk_configuration,
|
|
154
|
-
base_url=base_url or "",
|
|
155
|
-
operation_id="createCompletions",
|
|
156
|
-
oauth2_scopes=None,
|
|
157
|
-
security_source=get_security_from_env(
|
|
158
|
-
self.sdk_configuration.security, components.Security
|
|
159
|
-
),
|
|
160
|
-
),
|
|
161
|
-
request=req,
|
|
162
|
-
error_status_codes=["400", "401", "429", "4XX", "500", "5XX"],
|
|
163
|
-
retry_config=retry_config,
|
|
164
|
-
)
|
|
165
|
-
|
|
166
|
-
response_data: Any = None
|
|
167
|
-
if utils.match_response(http_res, "200", "application/json"):
|
|
168
|
-
return unmarshal_json_response(components.CompletionResponse, http_res)
|
|
169
|
-
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
|
|
170
|
-
response_data = unmarshal_json_response(errors.ChatErrorData, http_res)
|
|
171
|
-
raise errors.ChatError(response_data, http_res)
|
|
172
|
-
if utils.match_response(http_res, "500", "application/json"):
|
|
173
|
-
response_data = unmarshal_json_response(errors.ChatErrorData, http_res)
|
|
174
|
-
raise errors.ChatError(response_data, http_res)
|
|
175
|
-
if utils.match_response(http_res, "4XX", "*"):
|
|
176
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
177
|
-
raise errors.OpenRouterDefaultError(
|
|
178
|
-
"API error occurred", http_res, http_res_text
|
|
179
|
-
)
|
|
180
|
-
if utils.match_response(http_res, "5XX", "*"):
|
|
181
|
-
http_res_text = utils.stream_to_text(http_res)
|
|
182
|
-
raise errors.OpenRouterDefaultError(
|
|
183
|
-
"API error occurred", http_res, http_res_text
|
|
184
|
-
)
|
|
185
|
-
|
|
186
|
-
raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
|
|
187
|
-
|
|
188
|
-
async def generate_async(
|
|
189
|
-
self,
|
|
190
|
-
*,
|
|
191
|
-
prompt: Union[components.Prompt, components.PromptTypedDict],
|
|
192
|
-
model: Optional[str] = None,
|
|
193
|
-
models: Optional[List[str]] = None,
|
|
194
|
-
best_of: OptionalNullable[int] = UNSET,
|
|
195
|
-
echo: OptionalNullable[bool] = UNSET,
|
|
196
|
-
frequency_penalty: OptionalNullable[float] = UNSET,
|
|
197
|
-
logit_bias: OptionalNullable[Dict[str, float]] = UNSET,
|
|
198
|
-
logprobs: OptionalNullable[int] = UNSET,
|
|
199
|
-
max_tokens: OptionalNullable[int] = UNSET,
|
|
200
|
-
n: OptionalNullable[int] = UNSET,
|
|
201
|
-
presence_penalty: OptionalNullable[float] = UNSET,
|
|
202
|
-
seed: OptionalNullable[int] = UNSET,
|
|
203
|
-
stop: OptionalNullable[
|
|
204
|
-
Union[
|
|
205
|
-
components.CompletionCreateParamsStop,
|
|
206
|
-
components.CompletionCreateParamsStopTypedDict,
|
|
207
|
-
]
|
|
208
|
-
] = UNSET,
|
|
209
|
-
stream: Optional[bool] = False,
|
|
210
|
-
stream_options: OptionalNullable[
|
|
211
|
-
Union[components.StreamOptions, components.StreamOptionsTypedDict]
|
|
212
|
-
] = UNSET,
|
|
213
|
-
suffix: OptionalNullable[str] = UNSET,
|
|
214
|
-
temperature: OptionalNullable[float] = UNSET,
|
|
215
|
-
top_p: OptionalNullable[float] = UNSET,
|
|
216
|
-
user: Optional[str] = None,
|
|
217
|
-
metadata: OptionalNullable[Dict[str, str]] = UNSET,
|
|
218
|
-
response_format: OptionalNullable[
|
|
219
|
-
Union[
|
|
220
|
-
components.CompletionCreateParamsResponseFormatUnion,
|
|
221
|
-
components.CompletionCreateParamsResponseFormatUnionTypedDict,
|
|
222
|
-
]
|
|
223
|
-
] = UNSET,
|
|
224
|
-
retries: OptionalNullable[utils.RetryConfig] = UNSET,
|
|
225
|
-
server_url: Optional[str] = None,
|
|
226
|
-
timeout_ms: Optional[int] = None,
|
|
227
|
-
http_headers: Optional[Mapping[str, str]] = None,
|
|
228
|
-
) -> components.CompletionResponse:
|
|
229
|
-
r"""Create a completion
|
|
230
|
-
|
|
231
|
-
Creates a completion for the provided prompt and parameters. Supports both streaming and non-streaming modes.
|
|
232
|
-
|
|
233
|
-
:param prompt:
|
|
234
|
-
:param model:
|
|
235
|
-
:param models:
|
|
236
|
-
:param best_of:
|
|
237
|
-
:param echo:
|
|
238
|
-
:param frequency_penalty:
|
|
239
|
-
:param logit_bias:
|
|
240
|
-
:param logprobs:
|
|
241
|
-
:param max_tokens:
|
|
242
|
-
:param n:
|
|
243
|
-
:param presence_penalty:
|
|
244
|
-
:param seed:
|
|
245
|
-
:param stop:
|
|
246
|
-
:param stream:
|
|
247
|
-
:param stream_options:
|
|
248
|
-
:param suffix:
|
|
249
|
-
:param temperature:
|
|
250
|
-
:param top_p:
|
|
251
|
-
:param user:
|
|
252
|
-
:param metadata:
|
|
253
|
-
:param response_format:
|
|
254
|
-
:param retries: Override the default retry configuration for this method
|
|
255
|
-
:param server_url: Override the default server URL for this method
|
|
256
|
-
:param timeout_ms: Override the default request timeout configuration for this method in milliseconds
|
|
257
|
-
:param http_headers: Additional headers to set or replace on requests.
|
|
258
|
-
"""
|
|
259
|
-
base_url = None
|
|
260
|
-
url_variables = None
|
|
261
|
-
if timeout_ms is None:
|
|
262
|
-
timeout_ms = self.sdk_configuration.timeout_ms
|
|
263
|
-
|
|
264
|
-
if server_url is not None:
|
|
265
|
-
base_url = server_url
|
|
266
|
-
else:
|
|
267
|
-
base_url = self._get_url(base_url, url_variables)
|
|
268
|
-
|
|
269
|
-
request = components.CompletionCreateParams(
|
|
270
|
-
model=model,
|
|
271
|
-
models=models,
|
|
272
|
-
prompt=prompt,
|
|
273
|
-
best_of=best_of,
|
|
274
|
-
echo=echo,
|
|
275
|
-
frequency_penalty=frequency_penalty,
|
|
276
|
-
logit_bias=logit_bias,
|
|
277
|
-
logprobs=logprobs,
|
|
278
|
-
max_tokens=max_tokens,
|
|
279
|
-
n=n,
|
|
280
|
-
presence_penalty=presence_penalty,
|
|
281
|
-
seed=seed,
|
|
282
|
-
stop=stop,
|
|
283
|
-
stream=stream,
|
|
284
|
-
stream_options=utils.get_pydantic_model(
|
|
285
|
-
stream_options, OptionalNullable[components.StreamOptions]
|
|
286
|
-
),
|
|
287
|
-
suffix=suffix,
|
|
288
|
-
temperature=temperature,
|
|
289
|
-
top_p=top_p,
|
|
290
|
-
user=user,
|
|
291
|
-
metadata=metadata,
|
|
292
|
-
response_format=utils.get_pydantic_model(
|
|
293
|
-
response_format,
|
|
294
|
-
OptionalNullable[components.CompletionCreateParamsResponseFormatUnion],
|
|
295
|
-
),
|
|
296
|
-
)
|
|
297
|
-
|
|
298
|
-
req = self._build_request_async(
|
|
299
|
-
method="POST",
|
|
300
|
-
path="/completions",
|
|
301
|
-
base_url=base_url,
|
|
302
|
-
url_variables=url_variables,
|
|
303
|
-
request=request,
|
|
304
|
-
request_body_required=True,
|
|
305
|
-
request_has_path_params=False,
|
|
306
|
-
request_has_query_params=True,
|
|
307
|
-
user_agent_header="user-agent",
|
|
308
|
-
accept_header_value="application/json",
|
|
309
|
-
http_headers=http_headers,
|
|
310
|
-
security=self.sdk_configuration.security,
|
|
311
|
-
get_serialized_body=lambda: utils.serialize_request_body(
|
|
312
|
-
request, False, False, "json", components.CompletionCreateParams
|
|
313
|
-
),
|
|
314
|
-
allow_empty_value=None,
|
|
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, ["429", "500", "502", "503", "504"])
|
|
325
|
-
|
|
326
|
-
http_res = await self.do_request_async(
|
|
327
|
-
hook_ctx=HookContext(
|
|
328
|
-
config=self.sdk_configuration,
|
|
329
|
-
base_url=base_url or "",
|
|
330
|
-
operation_id="createCompletions",
|
|
331
|
-
oauth2_scopes=None,
|
|
332
|
-
security_source=get_security_from_env(
|
|
333
|
-
self.sdk_configuration.security, components.Security
|
|
334
|
-
),
|
|
335
|
-
),
|
|
336
|
-
request=req,
|
|
337
|
-
error_status_codes=["400", "401", "429", "4XX", "500", "5XX"],
|
|
338
|
-
retry_config=retry_config,
|
|
339
|
-
)
|
|
340
|
-
|
|
341
|
-
response_data: Any = None
|
|
342
|
-
if utils.match_response(http_res, "200", "application/json"):
|
|
343
|
-
return unmarshal_json_response(components.CompletionResponse, http_res)
|
|
344
|
-
if utils.match_response(http_res, ["400", "401", "429"], "application/json"):
|
|
345
|
-
response_data = unmarshal_json_response(errors.ChatErrorData, http_res)
|
|
346
|
-
raise errors.ChatError(response_data, http_res)
|
|
347
|
-
if utils.match_response(http_res, "500", "application/json"):
|
|
348
|
-
response_data = unmarshal_json_response(errors.ChatErrorData, http_res)
|
|
349
|
-
raise errors.ChatError(response_data, http_res)
|
|
350
|
-
if utils.match_response(http_res, "4XX", "*"):
|
|
351
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
352
|
-
raise errors.OpenRouterDefaultError(
|
|
353
|
-
"API error occurred", http_res, http_res_text
|
|
354
|
-
)
|
|
355
|
-
if utils.match_response(http_res, "5XX", "*"):
|
|
356
|
-
http_res_text = await utils.stream_to_text_async(http_res)
|
|
357
|
-
raise errors.OpenRouterDefaultError(
|
|
358
|
-
"API error occurred", http_res, http_res_text
|
|
359
|
-
)
|
|
360
|
-
|
|
361
|
-
raise errors.OpenRouterDefaultError("Unexpected response received", http_res)
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
from .completionlogprobs import CompletionLogprobs, CompletionLogprobsTypedDict
|
|
5
|
-
from openrouter.types import (
|
|
6
|
-
BaseModel,
|
|
7
|
-
Nullable,
|
|
8
|
-
OptionalNullable,
|
|
9
|
-
UNSET,
|
|
10
|
-
UNSET_SENTINEL,
|
|
11
|
-
UnrecognizedStr,
|
|
12
|
-
)
|
|
13
|
-
from openrouter.utils import validate_open_enum
|
|
14
|
-
from pydantic import model_serializer
|
|
15
|
-
from pydantic.functional_validators import PlainValidator
|
|
16
|
-
from typing import Literal, Optional, Union
|
|
17
|
-
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
CompletionFinishReason = Union[
|
|
21
|
-
Literal[
|
|
22
|
-
"stop",
|
|
23
|
-
"length",
|
|
24
|
-
"content_filter",
|
|
25
|
-
],
|
|
26
|
-
UnrecognizedStr,
|
|
27
|
-
]
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class CompletionChoiceTypedDict(TypedDict):
|
|
31
|
-
text: str
|
|
32
|
-
index: float
|
|
33
|
-
logprobs: Nullable[CompletionLogprobsTypedDict]
|
|
34
|
-
finish_reason: Nullable[CompletionFinishReason]
|
|
35
|
-
native_finish_reason: NotRequired[str]
|
|
36
|
-
reasoning: NotRequired[Nullable[str]]
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
class CompletionChoice(BaseModel):
|
|
40
|
-
text: str
|
|
41
|
-
|
|
42
|
-
index: float
|
|
43
|
-
|
|
44
|
-
logprobs: Nullable[CompletionLogprobs]
|
|
45
|
-
|
|
46
|
-
finish_reason: Annotated[
|
|
47
|
-
Nullable[CompletionFinishReason], PlainValidator(validate_open_enum(False))
|
|
48
|
-
]
|
|
49
|
-
|
|
50
|
-
native_finish_reason: Optional[str] = None
|
|
51
|
-
|
|
52
|
-
reasoning: OptionalNullable[str] = UNSET
|
|
53
|
-
|
|
54
|
-
@model_serializer(mode="wrap")
|
|
55
|
-
def serialize_model(self, handler):
|
|
56
|
-
optional_fields = ["native_finish_reason", "reasoning"]
|
|
57
|
-
nullable_fields = ["logprobs", "finish_reason", "reasoning"]
|
|
58
|
-
null_default_fields = []
|
|
59
|
-
|
|
60
|
-
serialized = handler(self)
|
|
61
|
-
|
|
62
|
-
m = {}
|
|
63
|
-
|
|
64
|
-
for n, f in type(self).model_fields.items():
|
|
65
|
-
k = f.alias or n
|
|
66
|
-
val = serialized.get(k)
|
|
67
|
-
serialized.pop(k, None)
|
|
68
|
-
|
|
69
|
-
optional_nullable = k in optional_fields and k in nullable_fields
|
|
70
|
-
is_set = (
|
|
71
|
-
self.__pydantic_fields_set__.intersection({n})
|
|
72
|
-
or k in null_default_fields
|
|
73
|
-
) # pylint: disable=no-member
|
|
74
|
-
|
|
75
|
-
if val is not None and val != UNSET_SENTINEL:
|
|
76
|
-
m[k] = val
|
|
77
|
-
elif val != UNSET_SENTINEL and (
|
|
78
|
-
not k in optional_fields or (optional_nullable and is_set)
|
|
79
|
-
):
|
|
80
|
-
m[k] = val
|
|
81
|
-
|
|
82
|
-
return m
|