python-open-router 0.2.0__py3-none-any.whl → 0.3.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.
- python_open_router/__init__.py +10 -0
- python_open_router/models.py +88 -0
- python_open_router/open_router.py +7 -0
- {python_open_router-0.2.0.dist-info → python_open_router-0.3.0.dist-info}/METADATA +2 -4
- python_open_router-0.3.0.dist-info/RECORD +9 -0
- {python_open_router-0.2.0.dist-info → python_open_router-0.3.0.dist-info}/WHEEL +1 -1
- python_open_router-0.2.0.dist-info/RECORD +0 -9
- {python_open_router-0.2.0.dist-info → python_open_router-0.3.0.dist-info}/LICENSE.md +0 -0
python_open_router/__init__.py
CHANGED
|
@@ -12,6 +12,11 @@ from python_open_router.models import (
|
|
|
12
12
|
KeyData,
|
|
13
13
|
KeyDataWrapper,
|
|
14
14
|
KeysDataWrapper,
|
|
15
|
+
Modality,
|
|
16
|
+
Model,
|
|
17
|
+
ModelArchitecture,
|
|
18
|
+
ModelsDataWrapper,
|
|
19
|
+
SupportedParameter,
|
|
15
20
|
)
|
|
16
21
|
from python_open_router.open_router import OpenRouterClient
|
|
17
22
|
|
|
@@ -22,8 +27,13 @@ __all__ = [
|
|
|
22
27
|
"KeyData",
|
|
23
28
|
"KeyDataWrapper",
|
|
24
29
|
"KeysDataWrapper",
|
|
30
|
+
"Modality",
|
|
31
|
+
"Model",
|
|
32
|
+
"ModelArchitecture",
|
|
33
|
+
"ModelsDataWrapper",
|
|
25
34
|
"OpenRouterAuthenticationError",
|
|
26
35
|
"OpenRouterClient",
|
|
27
36
|
"OpenRouterConnectionError",
|
|
28
37
|
"OpenRouterError",
|
|
38
|
+
"SupportedParameter",
|
|
29
39
|
]
|
python_open_router/models.py
CHANGED
|
@@ -3,9 +3,14 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
|
+
from enum import StrEnum
|
|
7
|
+
import logging
|
|
8
|
+
from typing import Any
|
|
6
9
|
|
|
7
10
|
from mashumaro.mixins.orjson import DataClassORJSONMixin
|
|
8
11
|
|
|
12
|
+
_LOGGER = logging.getLogger(__package__)
|
|
13
|
+
|
|
9
14
|
|
|
10
15
|
@dataclass
|
|
11
16
|
class KeyDataWrapper(DataClassORJSONMixin):
|
|
@@ -56,3 +61,86 @@ class CreatedKey(Key):
|
|
|
56
61
|
"""Created key."""
|
|
57
62
|
|
|
58
63
|
key: str
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@dataclass
|
|
67
|
+
class ModelsDataWrapper(DataClassORJSONMixin):
|
|
68
|
+
"""Wrapper for OpenRouter model data."""
|
|
69
|
+
|
|
70
|
+
data: list[Model]
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class SupportedParameter(StrEnum):
|
|
74
|
+
"""Supported parameters for models."""
|
|
75
|
+
|
|
76
|
+
TEMPERATURE = "temperature"
|
|
77
|
+
TOP_P = "top_p"
|
|
78
|
+
MAX_TOKENS = "max_tokens"
|
|
79
|
+
REASONING = "reasoning"
|
|
80
|
+
INCLUDE_REASONING = "include_reasoning"
|
|
81
|
+
STOP = "stop"
|
|
82
|
+
TOK_K = "top_k"
|
|
83
|
+
SEED = "seed"
|
|
84
|
+
RESPONSE_FORMAT = "response_format"
|
|
85
|
+
TOOLS = "tools"
|
|
86
|
+
TOOL_CHOICE = "tool_choice"
|
|
87
|
+
FREQUENCY_PENALTY = "frequency_penalty"
|
|
88
|
+
PRESENCE_PENALTY = "presence_penalty"
|
|
89
|
+
MIN_P = "min_p"
|
|
90
|
+
REPETITION_PENALTY = "repetition_penalty"
|
|
91
|
+
LOGPROBS = "logprobs"
|
|
92
|
+
LOGIT_BIAS = "logit_bias"
|
|
93
|
+
TOP_LOGPROBS = "top_logprobs"
|
|
94
|
+
STRUCTURED_OUTPUTS = "structured_outputs"
|
|
95
|
+
WEB_SEARCH_OPTIONS = "web_search_options"
|
|
96
|
+
TOP_A = "top_a"
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class Modality(StrEnum):
|
|
100
|
+
"""Supported modalities for models."""
|
|
101
|
+
|
|
102
|
+
TEXT = "text"
|
|
103
|
+
IMAGE = "image"
|
|
104
|
+
FILE = "file"
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@dataclass(kw_only=True)
|
|
108
|
+
class ModelArchitecture(DataClassORJSONMixin):
|
|
109
|
+
"""Model data."""
|
|
110
|
+
|
|
111
|
+
input_modalities: list[Modality]
|
|
112
|
+
output_modalities: list[Modality]
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@dataclass(kw_only=True)
|
|
116
|
+
class Model(DataClassORJSONMixin):
|
|
117
|
+
"""Model data."""
|
|
118
|
+
|
|
119
|
+
id: str
|
|
120
|
+
canonical_slug: str
|
|
121
|
+
hugging_face_id: str | None
|
|
122
|
+
name: str
|
|
123
|
+
description: str
|
|
124
|
+
context_length: int
|
|
125
|
+
architecture: ModelArchitecture
|
|
126
|
+
supported_parameters: list[SupportedParameter]
|
|
127
|
+
|
|
128
|
+
@classmethod
|
|
129
|
+
def __pre_deserialize__(cls, d: dict[str, Any]) -> dict[str, Any]:
|
|
130
|
+
"""Pre deserialize hook."""
|
|
131
|
+
parameters = d.get("supported_parameters", [])
|
|
132
|
+
for parameter in parameters:
|
|
133
|
+
if parameter not in SupportedParameter:
|
|
134
|
+
_LOGGER.warning(
|
|
135
|
+
"Unsupported parameter: %s. Please report at https://github.com/joostlek/python-open-router/issues.",
|
|
136
|
+
parameter,
|
|
137
|
+
)
|
|
138
|
+
parameters.remove(parameter)
|
|
139
|
+
return d
|
|
140
|
+
|
|
141
|
+
@classmethod
|
|
142
|
+
def __post_deserialize__(cls, obj: Model) -> Model:
|
|
143
|
+
"""Post deserialize hook."""
|
|
144
|
+
if obj.hugging_face_id == "":
|
|
145
|
+
obj.hugging_face_id = None
|
|
146
|
+
return obj
|
|
@@ -19,6 +19,8 @@ from python_open_router.models import (
|
|
|
19
19
|
KeyData,
|
|
20
20
|
KeyDataWrapper,
|
|
21
21
|
KeysDataWrapper,
|
|
22
|
+
Model,
|
|
23
|
+
ModelsDataWrapper,
|
|
22
24
|
)
|
|
23
25
|
|
|
24
26
|
if TYPE_CHECKING:
|
|
@@ -109,6 +111,11 @@ class OpenRouterClient:
|
|
|
109
111
|
response = await self._request(METH_POST, "keys", data=data)
|
|
110
112
|
return CreateKeyDataWrapper.from_json(response).data
|
|
111
113
|
|
|
114
|
+
async def get_models(self) -> list[Model]:
|
|
115
|
+
"""Get all available models."""
|
|
116
|
+
response = await self._request(METH_GET, "models")
|
|
117
|
+
return ModelsDataWrapper.from_json(response).data
|
|
118
|
+
|
|
112
119
|
async def close(self) -> None:
|
|
113
120
|
"""Close open client session."""
|
|
114
121
|
if self.session and self._close_session:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: python_open_router
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Asynchronous Python client for Open Router.
|
|
5
5
|
License: MIT
|
|
6
6
|
Keywords: OpenRouter,api,async,client
|
|
@@ -8,15 +8,13 @@ Author: Joost Lekkerkerker
|
|
|
8
8
|
Author-email: joostlek@outlook.com
|
|
9
9
|
Maintainer: Joost Lekkerkerker
|
|
10
10
|
Maintainer-email: joostlek@outlook.com
|
|
11
|
-
Requires-Python: >=3.
|
|
11
|
+
Requires-Python: >=3.13,<4.0
|
|
12
12
|
Classifier: Development Status :: 5 - Production/Stable
|
|
13
13
|
Classifier: Framework :: AsyncIO
|
|
14
14
|
Classifier: Intended Audience :: Developers
|
|
15
15
|
Classifier: License :: OSI Approved :: MIT License
|
|
16
16
|
Classifier: Natural Language :: English
|
|
17
17
|
Classifier: Programming Language :: Python :: 3
|
|
18
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
20
18
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
19
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
20
|
Requires-Dist: aiohttp (>=3.0.0)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
python_open_router/__init__.py,sha256=UQt6SpcnmQkS2wiyjwA_Ggvvzu7Ucx8BOCyZLZ_F2uA,840
|
|
2
|
+
python_open_router/exceptions.py,sha256=68nskqNdXNMIK4iA1XOE1E5P5rbhAf27DDACkk-ZVwU,312
|
|
3
|
+
python_open_router/models.py,sha256=ax1sfcdnvby1zqnlFyQ9v21eDFDKfk8uTUmvguNeNwU,3309
|
|
4
|
+
python_open_router/open_router.py,sha256=zq7aleWZfNFqbBb69Qp3_3jed95cwxtgGMlYFhDzYKw,4148
|
|
5
|
+
python_open_router/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
python_open_router-0.3.0.dist-info/LICENSE.md,sha256=Xbw7n2Ic30r4j8_MDNND4ss_sdoj9IGeIkEWc2Hsfs8,1077
|
|
7
|
+
python_open_router-0.3.0.dist-info/METADATA,sha256=H8In-JGkpn_P5GHOLI3MpodKkEB9R7s4wzzq9F6TuDE,5928
|
|
8
|
+
python_open_router-0.3.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
9
|
+
python_open_router-0.3.0.dist-info/RECORD,,
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
python_open_router/__init__.py,sha256=dmD0nHFaJzzKYD7Q4Ltm9p46uBhAOLpPTnWVyH_KHH8,640
|
|
2
|
-
python_open_router/exceptions.py,sha256=68nskqNdXNMIK4iA1XOE1E5P5rbhAf27DDACkk-ZVwU,312
|
|
3
|
-
python_open_router/models.py,sha256=qIKy3bqx-RnwlbwV4kgTPuDkbII4xPq2PE3gA8mShwo,999
|
|
4
|
-
python_open_router/open_router.py,sha256=WOJtZ40l3dv8_GGWRV1caN--KAgv0g0KfNdl-KzGGLM,3909
|
|
5
|
-
python_open_router/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
python_open_router-0.2.0.dist-info/LICENSE.md,sha256=Xbw7n2Ic30r4j8_MDNND4ss_sdoj9IGeIkEWc2Hsfs8,1077
|
|
7
|
-
python_open_router-0.2.0.dist-info/METADATA,sha256=iYrSXHhOj1w-vHE51V3JZoIdNcjrfkedqw-wuILzYVg,6030
|
|
8
|
-
python_open_router-0.2.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
|
|
9
|
-
python_open_router-0.2.0.dist-info/RECORD,,
|
|
File without changes
|