openrouter 0.0.18__py3-none-any.whl → 0.0.19__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 +3 -3
- openrouter/analytics.py +0 -2
- openrouter/api_keys.py +4 -24
- openrouter/basesdk.py +0 -6
- openrouter/chat.py +14 -212
- openrouter/completions.py +0 -2
- openrouter/components/__init__.py +105 -447
- openrouter/components/chatgenerationparams.py +17 -559
- openrouter/components/chatgenerationtokenusage.py +0 -3
- openrouter/components/chatmessagecontentitem.py +1 -1
- openrouter/components/chatmessagecontentitemaudio.py +25 -6
- openrouter/components/chatmessagecontentitemtext.py +2 -9
- openrouter/components/chatmessagecontentitemvideo.py +5 -9
- openrouter/components/chatmessagetokenlogprob.py +4 -4
- openrouter/components/chatresponsechoice.py +67 -6
- openrouter/components/chatstreamingmessagechunk.py +1 -12
- openrouter/components/chatstreamingresponsechunk.py +1 -1
- openrouter/components/completionchoice.py +5 -18
- openrouter/components/completioncreateparams.py +10 -10
- openrouter/components/completionresponse.py +0 -3
- openrouter/components/message.py +9 -10
- openrouter/components/openairesponsesannotation.py +4 -11
- openrouter/components/openairesponsesreasoningeffort.py +0 -1
- openrouter/components/openresponseseasyinputmessage.py +20 -93
- openrouter/components/openresponsesinput.py +2 -2
- openrouter/components/openresponsesinputmessageitem.py +14 -87
- openrouter/components/openresponsesnonstreamingresponse.py +19 -33
- openrouter/components/openresponsesreasoning.py +0 -1
- openrouter/components/openresponsesrequest.py +119 -246
- openrouter/components/openresponsesstreamevent.py +39 -110
- openrouter/components/outputmessage.py +4 -10
- openrouter/components/parameter.py +0 -1
- openrouter/components/providername.py +2 -10
- openrouter/components/providersort.py +1 -0
- openrouter/components/publicendpoint.py +49 -60
- openrouter/components/publicpricing.py +49 -49
- openrouter/components/responseformattextconfig.py +7 -9
- openrouter/components/responseoutputtext.py +1 -36
- openrouter/components/responsesoutputitem.py +11 -13
- openrouter/components/responsesoutputitemreasoning.py +3 -43
- openrouter/components/responsesoutputmessage.py +5 -10
- openrouter/credits.py +0 -4
- openrouter/embeddings.py +8 -10
- openrouter/endpoints.py +0 -4
- openrouter/generations.py +0 -2
- openrouter/models_.py +0 -6
- openrouter/oauth.py +0 -4
- openrouter/operations/__init__.py +34 -10
- openrouter/operations/createembeddings.py +247 -16
- openrouter/operations/getcredits.py +0 -19
- openrouter/operations/getgeneration.py +0 -6
- openrouter/operations/getparameters.py +71 -5
- openrouter/operations/updatekeys.py +2 -2
- openrouter/parameters.py +2 -4
- openrouter/providers.py +0 -2
- openrouter/responses.py +36 -188
- openrouter/sdk.py +0 -13
- openrouter/sdkconfiguration.py +0 -2
- openrouter/utils/forms.py +10 -21
- openrouter/utils/queryparams.py +2 -14
- openrouter/utils/retries.py +5 -69
- {openrouter-0.0.18.dist-info → openrouter-0.0.19.dist-info}/METADATA +1 -1
- {openrouter-0.0.18.dist-info → openrouter-0.0.19.dist-info}/RECORD +66 -87
- openrouter/components/_schema0.py +0 -94
- openrouter/components/_schema3.py +0 -229
- openrouter/components/chatcompletionfinishreason.py +0 -17
- openrouter/components/chatmessagecontentitemcachecontrol.py +0 -32
- openrouter/components/chatstreamingchoice.py +0 -72
- openrouter/components/pdfparserengine.py +0 -16
- openrouter/components/pdfparseroptions.py +0 -25
- openrouter/components/percentilelatencycutoffs.py +0 -71
- openrouter/components/percentilestats.py +0 -34
- openrouter/components/percentilethroughputcutoffs.py +0 -71
- openrouter/components/preferredmaxlatency.py +0 -21
- openrouter/components/preferredminthroughput.py +0 -22
- openrouter/components/providerpreferences.py +0 -355
- openrouter/components/providersortconfig.py +0 -71
- openrouter/components/providersortunion.py +0 -23
- openrouter/components/responseinputvideo.py +0 -26
- openrouter/components/responsesoutputmodality.py +0 -14
- openrouter/components/websearchengine.py +0 -15
- openrouter/models/__init__.py +0 -3
- openrouter/models/internal/__init__.py +0 -54
- openrouter/models/internal/globals.py +0 -41
- {openrouter-0.0.18.dist-info → openrouter-0.0.19.dist-info}/WHEEL +0 -0
- {openrouter-0.0.18.dist-info → openrouter-0.0.19.dist-info}/licenses/LICENSE +0 -0
- {openrouter-0.0.18.dist-info → openrouter-0.0.19.dist-info}/top_level.txt +0 -0
|
@@ -1,23 +1,42 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
-
from openrouter.types import BaseModel
|
|
5
|
-
from openrouter.utils import validate_const
|
|
4
|
+
from openrouter.types import BaseModel, UnrecognizedStr
|
|
5
|
+
from openrouter.utils import validate_const, validate_open_enum
|
|
6
6
|
import pydantic
|
|
7
|
-
from pydantic.functional_validators import AfterValidator
|
|
8
|
-
from typing import Literal
|
|
7
|
+
from pydantic.functional_validators import AfterValidator, PlainValidator
|
|
8
|
+
from typing import Literal, Union
|
|
9
9
|
from typing_extensions import Annotated, TypedDict
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
ChatMessageContentItemAudioFormat = Union[
|
|
13
|
+
Literal[
|
|
14
|
+
"wav",
|
|
15
|
+
"mp3",
|
|
16
|
+
"flac",
|
|
17
|
+
"m4a",
|
|
18
|
+
"ogg",
|
|
19
|
+
"pcm16",
|
|
20
|
+
"pcm24",
|
|
21
|
+
],
|
|
22
|
+
UnrecognizedStr,
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
|
|
12
26
|
class ChatMessageContentItemAudioInputAudioTypedDict(TypedDict):
|
|
13
27
|
data: str
|
|
14
|
-
format_:
|
|
28
|
+
format_: ChatMessageContentItemAudioFormat
|
|
15
29
|
|
|
16
30
|
|
|
17
31
|
class ChatMessageContentItemAudioInputAudio(BaseModel):
|
|
18
32
|
data: str
|
|
19
33
|
|
|
20
|
-
format_: Annotated[
|
|
34
|
+
format_: Annotated[
|
|
35
|
+
Annotated[
|
|
36
|
+
ChatMessageContentItemAudioFormat, PlainValidator(validate_open_enum(False))
|
|
37
|
+
],
|
|
38
|
+
pydantic.Field(alias="format"),
|
|
39
|
+
]
|
|
21
40
|
|
|
22
41
|
|
|
23
42
|
class ChatMessageContentItemAudioTypedDict(TypedDict):
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
-
from .chatmessagecontentitemcachecontrol import (
|
|
5
|
-
ChatMessageContentItemCacheControl,
|
|
6
|
-
ChatMessageContentItemCacheControlTypedDict,
|
|
7
|
-
)
|
|
8
4
|
from openrouter.types import BaseModel
|
|
9
5
|
from openrouter.utils import validate_const
|
|
10
6
|
import pydantic
|
|
11
7
|
from pydantic.functional_validators import AfterValidator
|
|
12
|
-
from typing import Literal
|
|
13
|
-
from typing_extensions import Annotated,
|
|
8
|
+
from typing import Literal
|
|
9
|
+
from typing_extensions import Annotated, TypedDict
|
|
14
10
|
|
|
15
11
|
|
|
16
12
|
class ChatMessageContentItemTextTypedDict(TypedDict):
|
|
17
13
|
text: str
|
|
18
14
|
type: Literal["text"]
|
|
19
|
-
cache_control: NotRequired[ChatMessageContentItemCacheControlTypedDict]
|
|
20
15
|
|
|
21
16
|
|
|
22
17
|
class ChatMessageContentItemText(BaseModel):
|
|
@@ -26,5 +21,3 @@ class ChatMessageContentItemText(BaseModel):
|
|
|
26
21
|
Annotated[Literal["text"], AfterValidator(validate_const("text"))],
|
|
27
22
|
pydantic.Field(alias="type"),
|
|
28
23
|
] = "text"
|
|
29
|
-
|
|
30
|
-
cache_control: Optional[ChatMessageContentItemCacheControl] = None
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
from openrouter.types import BaseModel
|
|
5
|
-
from openrouter.utils import
|
|
5
|
+
from openrouter.utils import validate_const
|
|
6
6
|
import pydantic
|
|
7
|
-
from pydantic import Discriminator, Tag
|
|
8
7
|
from pydantic.functional_validators import AfterValidator
|
|
9
8
|
from typing import Literal, Union
|
|
10
9
|
from typing_extensions import Annotated, TypeAliasType, TypedDict
|
|
@@ -65,10 +64,7 @@ ChatMessageContentItemVideoTypedDict = TypeAliasType(
|
|
|
65
64
|
)
|
|
66
65
|
|
|
67
66
|
|
|
68
|
-
ChatMessageContentItemVideo =
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
],
|
|
73
|
-
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
|
74
|
-
]
|
|
67
|
+
ChatMessageContentItemVideo = TypeAliasType(
|
|
68
|
+
"ChatMessageContentItemVideo",
|
|
69
|
+
Union[ChatMessageContentItemVideoInputVideo, ChatMessageContentItemVideoVideoURL],
|
|
70
|
+
)
|
|
@@ -8,13 +8,13 @@ from typing import List
|
|
|
8
8
|
from typing_extensions import Annotated, TypedDict
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
class
|
|
11
|
+
class TopLogprobTypedDict(TypedDict):
|
|
12
12
|
token: str
|
|
13
13
|
logprob: float
|
|
14
14
|
bytes_: Nullable[List[float]]
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
class
|
|
17
|
+
class TopLogprob(BaseModel):
|
|
18
18
|
token: str
|
|
19
19
|
|
|
20
20
|
logprob: float
|
|
@@ -56,7 +56,7 @@ class ChatMessageTokenLogprobTypedDict(TypedDict):
|
|
|
56
56
|
token: str
|
|
57
57
|
logprob: float
|
|
58
58
|
bytes_: Nullable[List[float]]
|
|
59
|
-
top_logprobs: List[
|
|
59
|
+
top_logprobs: List[TopLogprobTypedDict]
|
|
60
60
|
|
|
61
61
|
|
|
62
62
|
class ChatMessageTokenLogprob(BaseModel):
|
|
@@ -66,7 +66,7 @@ class ChatMessageTokenLogprob(BaseModel):
|
|
|
66
66
|
|
|
67
67
|
bytes_: Annotated[Nullable[List[float]], pydantic.Field(alias="bytes")]
|
|
68
68
|
|
|
69
|
-
top_logprobs: List[
|
|
69
|
+
top_logprobs: List[TopLogprob]
|
|
70
70
|
|
|
71
71
|
@model_serializer(mode="wrap")
|
|
72
72
|
def serialize_model(self, handler):
|
|
@@ -1,32 +1,46 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
-
from ._schema3 import Schema3, Schema3TypedDict
|
|
5
4
|
from .assistantmessage import AssistantMessage, AssistantMessageTypedDict
|
|
6
|
-
from .chatcompletionfinishreason import ChatCompletionFinishReason
|
|
7
5
|
from .chatmessagetokenlogprobs import (
|
|
8
6
|
ChatMessageTokenLogprobs,
|
|
9
7
|
ChatMessageTokenLogprobsTypedDict,
|
|
10
8
|
)
|
|
9
|
+
from .chatstreamingmessagechunk import (
|
|
10
|
+
ChatStreamingMessageChunk,
|
|
11
|
+
ChatStreamingMessageChunkTypedDict,
|
|
12
|
+
)
|
|
11
13
|
from openrouter.types import (
|
|
12
14
|
BaseModel,
|
|
13
15
|
Nullable,
|
|
14
16
|
OptionalNullable,
|
|
15
17
|
UNSET,
|
|
16
18
|
UNSET_SENTINEL,
|
|
19
|
+
UnrecognizedStr,
|
|
17
20
|
)
|
|
18
21
|
from openrouter.utils import validate_open_enum
|
|
19
22
|
from pydantic import model_serializer
|
|
20
23
|
from pydantic.functional_validators import PlainValidator
|
|
21
|
-
from typing import
|
|
24
|
+
from typing import Literal, Union
|
|
22
25
|
from typing_extensions import Annotated, NotRequired, TypedDict
|
|
23
26
|
|
|
24
27
|
|
|
28
|
+
ChatCompletionFinishReason = Union[
|
|
29
|
+
Literal[
|
|
30
|
+
"tool_calls",
|
|
31
|
+
"stop",
|
|
32
|
+
"length",
|
|
33
|
+
"content_filter",
|
|
34
|
+
"error",
|
|
35
|
+
],
|
|
36
|
+
UnrecognizedStr,
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
|
|
25
40
|
class ChatResponseChoiceTypedDict(TypedDict):
|
|
26
41
|
finish_reason: Nullable[ChatCompletionFinishReason]
|
|
27
42
|
index: float
|
|
28
43
|
message: AssistantMessageTypedDict
|
|
29
|
-
reasoning_details: NotRequired[List[Schema3TypedDict]]
|
|
30
44
|
logprobs: NotRequired[Nullable[ChatMessageTokenLogprobsTypedDict]]
|
|
31
45
|
|
|
32
46
|
|
|
@@ -39,13 +53,60 @@ class ChatResponseChoice(BaseModel):
|
|
|
39
53
|
|
|
40
54
|
message: AssistantMessage
|
|
41
55
|
|
|
42
|
-
|
|
56
|
+
logprobs: OptionalNullable[ChatMessageTokenLogprobs] = UNSET
|
|
57
|
+
|
|
58
|
+
@model_serializer(mode="wrap")
|
|
59
|
+
def serialize_model(self, handler):
|
|
60
|
+
optional_fields = ["logprobs"]
|
|
61
|
+
nullable_fields = ["finish_reason", "logprobs"]
|
|
62
|
+
null_default_fields = []
|
|
63
|
+
|
|
64
|
+
serialized = handler(self)
|
|
65
|
+
|
|
66
|
+
m = {}
|
|
67
|
+
|
|
68
|
+
for n, f in type(self).model_fields.items():
|
|
69
|
+
k = f.alias or n
|
|
70
|
+
val = serialized.get(k)
|
|
71
|
+
serialized.pop(k, None)
|
|
72
|
+
|
|
73
|
+
optional_nullable = k in optional_fields and k in nullable_fields
|
|
74
|
+
is_set = (
|
|
75
|
+
self.__pydantic_fields_set__.intersection({n})
|
|
76
|
+
or k in null_default_fields
|
|
77
|
+
) # pylint: disable=no-member
|
|
78
|
+
|
|
79
|
+
if val is not None and val != UNSET_SENTINEL:
|
|
80
|
+
m[k] = val
|
|
81
|
+
elif val != UNSET_SENTINEL and (
|
|
82
|
+
not k in optional_fields or (optional_nullable and is_set)
|
|
83
|
+
):
|
|
84
|
+
m[k] = val
|
|
85
|
+
|
|
86
|
+
return m
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
class ChatStreamingChoiceTypedDict(TypedDict):
|
|
90
|
+
delta: ChatStreamingMessageChunkTypedDict
|
|
91
|
+
finish_reason: Nullable[ChatCompletionFinishReason]
|
|
92
|
+
index: float
|
|
93
|
+
logprobs: NotRequired[Nullable[ChatMessageTokenLogprobsTypedDict]]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class ChatStreamingChoice(BaseModel):
|
|
97
|
+
delta: ChatStreamingMessageChunk
|
|
98
|
+
|
|
99
|
+
finish_reason: Annotated[
|
|
100
|
+
Nullable[ChatCompletionFinishReason], PlainValidator(validate_open_enum(False))
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
index: float
|
|
43
104
|
|
|
44
105
|
logprobs: OptionalNullable[ChatMessageTokenLogprobs] = UNSET
|
|
45
106
|
|
|
46
107
|
@model_serializer(mode="wrap")
|
|
47
108
|
def serialize_model(self, handler):
|
|
48
|
-
optional_fields = ["
|
|
109
|
+
optional_fields = ["logprobs"]
|
|
49
110
|
nullable_fields = ["finish_reason", "logprobs"]
|
|
50
111
|
null_default_fields = []
|
|
51
112
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
|
-
from ._schema3 import Schema3, Schema3TypedDict
|
|
5
4
|
from .chatstreamingmessagetoolcall import (
|
|
6
5
|
ChatStreamingMessageToolCall,
|
|
7
6
|
ChatStreamingMessageToolCallTypedDict,
|
|
@@ -27,7 +26,6 @@ class ChatStreamingMessageChunkTypedDict(TypedDict):
|
|
|
27
26
|
reasoning: NotRequired[Nullable[str]]
|
|
28
27
|
refusal: NotRequired[Nullable[str]]
|
|
29
28
|
tool_calls: NotRequired[List[ChatStreamingMessageToolCallTypedDict]]
|
|
30
|
-
reasoning_details: NotRequired[List[Schema3TypedDict]]
|
|
31
29
|
|
|
32
30
|
|
|
33
31
|
class ChatStreamingMessageChunk(BaseModel):
|
|
@@ -41,18 +39,9 @@ class ChatStreamingMessageChunk(BaseModel):
|
|
|
41
39
|
|
|
42
40
|
tool_calls: Optional[List[ChatStreamingMessageToolCall]] = None
|
|
43
41
|
|
|
44
|
-
reasoning_details: Optional[List[Schema3]] = None
|
|
45
|
-
|
|
46
42
|
@model_serializer(mode="wrap")
|
|
47
43
|
def serialize_model(self, handler):
|
|
48
|
-
optional_fields = [
|
|
49
|
-
"role",
|
|
50
|
-
"content",
|
|
51
|
-
"reasoning",
|
|
52
|
-
"refusal",
|
|
53
|
-
"tool_calls",
|
|
54
|
-
"reasoning_details",
|
|
55
|
-
]
|
|
44
|
+
optional_fields = ["role", "content", "reasoning", "refusal", "tool_calls"]
|
|
56
45
|
nullable_fields = ["content", "reasoning", "refusal"]
|
|
57
46
|
null_default_fields = []
|
|
58
47
|
|
|
@@ -5,7 +5,7 @@ from .chatgenerationtokenusage import (
|
|
|
5
5
|
ChatGenerationTokenUsage,
|
|
6
6
|
ChatGenerationTokenUsageTypedDict,
|
|
7
7
|
)
|
|
8
|
-
from .
|
|
8
|
+
from .chatresponsechoice import ChatStreamingChoice, ChatStreamingChoiceTypedDict
|
|
9
9
|
from openrouter.types import (
|
|
10
10
|
BaseModel,
|
|
11
11
|
Nullable,
|
|
@@ -2,19 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
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
|
-
)
|
|
5
|
+
from openrouter.types import BaseModel, Nullable, UNSET_SENTINEL, UnrecognizedStr
|
|
13
6
|
from openrouter.utils import validate_open_enum
|
|
14
7
|
from pydantic import model_serializer
|
|
15
8
|
from pydantic.functional_validators import PlainValidator
|
|
16
|
-
from typing import Literal,
|
|
17
|
-
from typing_extensions import Annotated,
|
|
9
|
+
from typing import Literal, Union
|
|
10
|
+
from typing_extensions import Annotated, TypedDict
|
|
18
11
|
|
|
19
12
|
|
|
20
13
|
CompletionFinishReason = Union[
|
|
@@ -32,8 +25,6 @@ class CompletionChoiceTypedDict(TypedDict):
|
|
|
32
25
|
index: float
|
|
33
26
|
logprobs: Nullable[CompletionLogprobsTypedDict]
|
|
34
27
|
finish_reason: Nullable[CompletionFinishReason]
|
|
35
|
-
native_finish_reason: NotRequired[str]
|
|
36
|
-
reasoning: NotRequired[Nullable[str]]
|
|
37
28
|
|
|
38
29
|
|
|
39
30
|
class CompletionChoice(BaseModel):
|
|
@@ -47,14 +38,10 @@ class CompletionChoice(BaseModel):
|
|
|
47
38
|
Nullable[CompletionFinishReason], PlainValidator(validate_open_enum(False))
|
|
48
39
|
]
|
|
49
40
|
|
|
50
|
-
native_finish_reason: Optional[str] = None
|
|
51
|
-
|
|
52
|
-
reasoning: OptionalNullable[str] = UNSET
|
|
53
|
-
|
|
54
41
|
@model_serializer(mode="wrap")
|
|
55
42
|
def serialize_model(self, handler):
|
|
56
|
-
optional_fields = [
|
|
57
|
-
nullable_fields = ["logprobs", "finish_reason"
|
|
43
|
+
optional_fields = []
|
|
44
|
+
nullable_fields = ["logprobs", "finish_reason"]
|
|
58
45
|
null_default_fields = []
|
|
59
46
|
|
|
60
47
|
serialized = handler(self)
|
|
@@ -16,9 +16,9 @@ from openrouter.types import (
|
|
|
16
16
|
UNSET,
|
|
17
17
|
UNSET_SENTINEL,
|
|
18
18
|
)
|
|
19
|
-
from openrouter.utils import
|
|
19
|
+
from openrouter.utils import validate_const
|
|
20
20
|
import pydantic
|
|
21
|
-
from pydantic import
|
|
21
|
+
from pydantic import model_serializer
|
|
22
22
|
from pydantic.functional_validators import AfterValidator
|
|
23
23
|
from typing import Dict, List, Literal, Optional, Union
|
|
24
24
|
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
|
@@ -127,16 +127,16 @@ CompletionCreateParamsResponseFormatUnionTypedDict = TypeAliasType(
|
|
|
127
127
|
)
|
|
128
128
|
|
|
129
129
|
|
|
130
|
-
CompletionCreateParamsResponseFormatUnion =
|
|
130
|
+
CompletionCreateParamsResponseFormatUnion = TypeAliasType(
|
|
131
|
+
"CompletionCreateParamsResponseFormatUnion",
|
|
131
132
|
Union[
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
CompletionCreateParamsResponseFormatText,
|
|
134
|
+
CompletionCreateParamsResponseFormatJSONObject,
|
|
135
|
+
CompletionCreateParamsResponseFormatPython,
|
|
136
|
+
ResponseFormatJSONSchema,
|
|
137
|
+
ResponseFormatTextGrammar,
|
|
137
138
|
],
|
|
138
|
-
|
|
139
|
-
]
|
|
139
|
+
)
|
|
140
140
|
|
|
141
141
|
|
|
142
142
|
class CompletionCreateParamsTypedDict(TypedDict):
|
|
@@ -17,7 +17,6 @@ class CompletionResponseTypedDict(TypedDict):
|
|
|
17
17
|
model: str
|
|
18
18
|
choices: List[CompletionChoiceTypedDict]
|
|
19
19
|
object: Literal["text_completion"]
|
|
20
|
-
provider: NotRequired[str]
|
|
21
20
|
system_fingerprint: NotRequired[str]
|
|
22
21
|
usage: NotRequired[CompletionUsageTypedDict]
|
|
23
22
|
|
|
@@ -39,8 +38,6 @@ class CompletionResponse(BaseModel):
|
|
|
39
38
|
pydantic.Field(alias="object"),
|
|
40
39
|
] = "text_completion"
|
|
41
40
|
|
|
42
|
-
provider: Optional[str] = None
|
|
43
|
-
|
|
44
41
|
system_fingerprint: Optional[str] = None
|
|
45
42
|
|
|
46
43
|
usage: Optional[CompletionUsage] = None
|
openrouter/components/message.py
CHANGED
|
@@ -10,9 +10,8 @@ from .systemmessage import SystemMessage, SystemMessageTypedDict
|
|
|
10
10
|
from .toolresponsemessage import ToolResponseMessage, ToolResponseMessageTypedDict
|
|
11
11
|
from .usermessage import UserMessage, UserMessageTypedDict
|
|
12
12
|
from openrouter.types import BaseModel
|
|
13
|
-
from openrouter.utils import
|
|
13
|
+
from openrouter.utils import validate_const
|
|
14
14
|
import pydantic
|
|
15
|
-
from pydantic import Discriminator, Tag
|
|
16
15
|
from pydantic.functional_validators import AfterValidator
|
|
17
16
|
from typing import List, Literal, Optional, Union
|
|
18
17
|
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
|
@@ -57,13 +56,13 @@ MessageTypedDict = TypeAliasType(
|
|
|
57
56
|
)
|
|
58
57
|
|
|
59
58
|
|
|
60
|
-
Message =
|
|
59
|
+
Message = TypeAliasType(
|
|
60
|
+
"Message",
|
|
61
61
|
Union[
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
SystemMessage,
|
|
63
|
+
UserMessage,
|
|
64
|
+
MessageDeveloper,
|
|
65
|
+
ToolResponseMessage,
|
|
66
|
+
AssistantMessage,
|
|
67
67
|
],
|
|
68
|
-
|
|
69
|
-
]
|
|
68
|
+
)
|
|
@@ -4,10 +4,8 @@ from __future__ import annotations
|
|
|
4
4
|
from .filecitation import FileCitation, FileCitationTypedDict
|
|
5
5
|
from .filepath import FilePath, FilePathTypedDict
|
|
6
6
|
from .urlcitation import URLCitation, URLCitationTypedDict
|
|
7
|
-
from openrouter.utils import get_discriminator
|
|
8
|
-
from pydantic import Discriminator, Tag
|
|
9
7
|
from typing import Union
|
|
10
|
-
from typing_extensions import
|
|
8
|
+
from typing_extensions import TypeAliasType
|
|
11
9
|
|
|
12
10
|
|
|
13
11
|
OpenAIResponsesAnnotationTypedDict = TypeAliasType(
|
|
@@ -16,11 +14,6 @@ OpenAIResponsesAnnotationTypedDict = TypeAliasType(
|
|
|
16
14
|
)
|
|
17
15
|
|
|
18
16
|
|
|
19
|
-
OpenAIResponsesAnnotation =
|
|
20
|
-
Union[
|
|
21
|
-
|
|
22
|
-
Annotated[URLCitation, Tag("url_citation")],
|
|
23
|
-
Annotated[FilePath, Tag("file_path")],
|
|
24
|
-
],
|
|
25
|
-
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
|
26
|
-
]
|
|
17
|
+
OpenAIResponsesAnnotation = TypeAliasType(
|
|
18
|
+
"OpenAIResponsesAnnotation", Union[FilePath, FileCitation, URLCitation]
|
|
19
|
+
)
|
|
@@ -3,24 +3,16 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
from .responseinputaudio import ResponseInputAudio, ResponseInputAudioTypedDict
|
|
5
5
|
from .responseinputfile import ResponseInputFile, ResponseInputFileTypedDict
|
|
6
|
+
from .responseinputimage import ResponseInputImage, ResponseInputImageTypedDict
|
|
6
7
|
from .responseinputtext import ResponseInputText, ResponseInputTextTypedDict
|
|
7
|
-
from .
|
|
8
|
-
from openrouter.
|
|
9
|
-
|
|
10
|
-
Nullable,
|
|
11
|
-
OptionalNullable,
|
|
12
|
-
UNSET,
|
|
13
|
-
UNSET_SENTINEL,
|
|
14
|
-
UnrecognizedStr,
|
|
15
|
-
)
|
|
16
|
-
from openrouter.utils import get_discriminator, validate_open_enum
|
|
17
|
-
from pydantic import Discriminator, Tag, model_serializer
|
|
18
|
-
from pydantic.functional_validators import PlainValidator
|
|
8
|
+
from openrouter.types import BaseModel
|
|
9
|
+
from openrouter.utils import get_discriminator
|
|
10
|
+
from pydantic import Discriminator, Tag
|
|
19
11
|
from typing import List, Literal, Optional, Union
|
|
20
12
|
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict
|
|
21
13
|
|
|
22
14
|
|
|
23
|
-
|
|
15
|
+
OpenResponsesEasyInputMessageType = Literal["message",]
|
|
24
16
|
|
|
25
17
|
|
|
26
18
|
OpenResponsesEasyInputMessageRoleDeveloper = Literal["developer",]
|
|
@@ -57,114 +49,49 @@ OpenResponsesEasyInputMessageRoleUnion = TypeAliasType(
|
|
|
57
49
|
)
|
|
58
50
|
|
|
59
51
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
OpenResponsesEasyInputMessageDetail = Union[
|
|
64
|
-
Literal[
|
|
65
|
-
"auto",
|
|
66
|
-
"high",
|
|
67
|
-
"low",
|
|
68
|
-
],
|
|
69
|
-
UnrecognizedStr,
|
|
70
|
-
]
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
class OpenResponsesEasyInputMessageContentInputImageTypedDict(TypedDict):
|
|
74
|
-
r"""Image input content item"""
|
|
75
|
-
|
|
76
|
-
type: OpenResponsesEasyInputMessageContentType
|
|
77
|
-
detail: OpenResponsesEasyInputMessageDetail
|
|
78
|
-
image_url: NotRequired[Nullable[str]]
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
class OpenResponsesEasyInputMessageContentInputImage(BaseModel):
|
|
82
|
-
r"""Image input content item"""
|
|
83
|
-
|
|
84
|
-
type: OpenResponsesEasyInputMessageContentType
|
|
85
|
-
|
|
86
|
-
detail: Annotated[
|
|
87
|
-
OpenResponsesEasyInputMessageDetail, PlainValidator(validate_open_enum(False))
|
|
88
|
-
]
|
|
89
|
-
|
|
90
|
-
image_url: OptionalNullable[str] = UNSET
|
|
91
|
-
|
|
92
|
-
@model_serializer(mode="wrap")
|
|
93
|
-
def serialize_model(self, handler):
|
|
94
|
-
optional_fields = ["image_url"]
|
|
95
|
-
nullable_fields = ["image_url"]
|
|
96
|
-
null_default_fields = []
|
|
97
|
-
|
|
98
|
-
serialized = handler(self)
|
|
99
|
-
|
|
100
|
-
m = {}
|
|
101
|
-
|
|
102
|
-
for n, f in type(self).model_fields.items():
|
|
103
|
-
k = f.alias or n
|
|
104
|
-
val = serialized.get(k)
|
|
105
|
-
serialized.pop(k, None)
|
|
106
|
-
|
|
107
|
-
optional_nullable = k in optional_fields and k in nullable_fields
|
|
108
|
-
is_set = (
|
|
109
|
-
self.__pydantic_fields_set__.intersection({n})
|
|
110
|
-
or k in null_default_fields
|
|
111
|
-
) # pylint: disable=no-member
|
|
112
|
-
|
|
113
|
-
if val is not None and val != UNSET_SENTINEL:
|
|
114
|
-
m[k] = val
|
|
115
|
-
elif val != UNSET_SENTINEL and (
|
|
116
|
-
not k in optional_fields or (optional_nullable and is_set)
|
|
117
|
-
):
|
|
118
|
-
m[k] = val
|
|
119
|
-
|
|
120
|
-
return m
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
OpenResponsesEasyInputMessageContentUnion1TypedDict = TypeAliasType(
|
|
124
|
-
"OpenResponsesEasyInputMessageContentUnion1TypedDict",
|
|
52
|
+
OpenResponsesEasyInputMessageContent1TypedDict = TypeAliasType(
|
|
53
|
+
"OpenResponsesEasyInputMessageContent1TypedDict",
|
|
125
54
|
Union[
|
|
126
55
|
ResponseInputTextTypedDict,
|
|
127
56
|
ResponseInputAudioTypedDict,
|
|
128
|
-
|
|
129
|
-
OpenResponsesEasyInputMessageContentInputImageTypedDict,
|
|
57
|
+
ResponseInputImageTypedDict,
|
|
130
58
|
ResponseInputFileTypedDict,
|
|
131
59
|
],
|
|
132
60
|
)
|
|
133
61
|
|
|
134
62
|
|
|
135
|
-
|
|
63
|
+
OpenResponsesEasyInputMessageContent1 = Annotated[
|
|
136
64
|
Union[
|
|
137
65
|
Annotated[ResponseInputText, Tag("input_text")],
|
|
138
|
-
Annotated[
|
|
66
|
+
Annotated[ResponseInputImage, Tag("input_image")],
|
|
139
67
|
Annotated[ResponseInputFile, Tag("input_file")],
|
|
140
68
|
Annotated[ResponseInputAudio, Tag("input_audio")],
|
|
141
|
-
Annotated[ResponseInputVideo, Tag("input_video")],
|
|
142
69
|
],
|
|
143
70
|
Discriminator(lambda m: get_discriminator(m, "type", "type")),
|
|
144
71
|
]
|
|
145
72
|
|
|
146
73
|
|
|
147
|
-
|
|
148
|
-
"
|
|
149
|
-
Union[List[
|
|
74
|
+
OpenResponsesEasyInputMessageContent2TypedDict = TypeAliasType(
|
|
75
|
+
"OpenResponsesEasyInputMessageContent2TypedDict",
|
|
76
|
+
Union[List[OpenResponsesEasyInputMessageContent1TypedDict], str],
|
|
150
77
|
)
|
|
151
78
|
|
|
152
79
|
|
|
153
|
-
|
|
154
|
-
"
|
|
155
|
-
Union[List[
|
|
80
|
+
OpenResponsesEasyInputMessageContent2 = TypeAliasType(
|
|
81
|
+
"OpenResponsesEasyInputMessageContent2",
|
|
82
|
+
Union[List[OpenResponsesEasyInputMessageContent1], str],
|
|
156
83
|
)
|
|
157
84
|
|
|
158
85
|
|
|
159
86
|
class OpenResponsesEasyInputMessageTypedDict(TypedDict):
|
|
160
87
|
role: OpenResponsesEasyInputMessageRoleUnionTypedDict
|
|
161
|
-
content:
|
|
162
|
-
type: NotRequired[
|
|
88
|
+
content: OpenResponsesEasyInputMessageContent2TypedDict
|
|
89
|
+
type: NotRequired[OpenResponsesEasyInputMessageType]
|
|
163
90
|
|
|
164
91
|
|
|
165
92
|
class OpenResponsesEasyInputMessage(BaseModel):
|
|
166
93
|
role: OpenResponsesEasyInputMessageRoleUnion
|
|
167
94
|
|
|
168
|
-
content:
|
|
95
|
+
content: OpenResponsesEasyInputMessageContent2
|
|
169
96
|
|
|
170
|
-
type: Optional[
|
|
97
|
+
type: Optional[OpenResponsesEasyInputMessageType] = None
|
|
@@ -60,9 +60,9 @@ OpenResponsesInput1TypedDict = TypeAliasType(
|
|
|
60
60
|
OpenResponsesFunctionCallOutputTypedDict,
|
|
61
61
|
ResponsesOutputMessageTypedDict,
|
|
62
62
|
OpenResponsesFunctionToolCallTypedDict,
|
|
63
|
+
ResponsesOutputItemReasoningTypedDict,
|
|
63
64
|
ResponsesOutputItemFunctionCallTypedDict,
|
|
64
65
|
OpenResponsesReasoningTypedDict,
|
|
65
|
-
ResponsesOutputItemReasoningTypedDict,
|
|
66
66
|
],
|
|
67
67
|
)
|
|
68
68
|
|
|
@@ -78,9 +78,9 @@ OpenResponsesInput1 = TypeAliasType(
|
|
|
78
78
|
OpenResponsesFunctionCallOutput,
|
|
79
79
|
ResponsesOutputMessage,
|
|
80
80
|
OpenResponsesFunctionToolCall,
|
|
81
|
+
ResponsesOutputItemReasoning,
|
|
81
82
|
ResponsesOutputItemFunctionCall,
|
|
82
83
|
OpenResponsesReasoning,
|
|
83
|
-
ResponsesOutputItemReasoning,
|
|
84
84
|
],
|
|
85
85
|
)
|
|
86
86
|
|