swarmauri_provider_qwen 0.1.0.dev3__tar.gz

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.
@@ -0,0 +1,13 @@
1
+ Copyright 2024 Jacob Stewart
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,50 @@
1
+ Metadata-Version: 2.4
2
+ Name: swarmauri_provider_qwen
3
+ Version: 0.1.0.dev3
4
+ Summary: Aggregated Qwen provider resources for Swarmauri models.
5
+ License: Copyright 2024 Jacob Stewart
6
+
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
18
+ License-File: LICENSE
19
+ Keywords: swarmauri,provider,qwen,dashscope,realtime
20
+ Author: Jacob Stewart
21
+ Author-email: jacob@swarmauri.com
22
+ Requires-Python: >=3.10,<3.13
23
+ Classifier: Development Status :: 1 - Planning
24
+ Classifier: License :: OSI Approved :: Apache Software License
25
+ Classifier: Programming Language :: Python :: 3.10
26
+ Classifier: Programming Language :: Python :: 3.11
27
+ Classifier: Programming Language :: Python :: 3.12
28
+ Requires-Dist: swarmauri_base (>=0.11.0.dev5)
29
+ Requires-Dist: swarmauri_core (>=0.11.0.dev5)
30
+ Description-Content-Type: text/markdown
31
+
32
+ ![Swarmauri](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
33
+
34
+ [![PyPI](https://img.shields.io/pypi/v/swarmauri_provider_qwen.svg)](https://pypi.org/project/swarmauri_provider_qwen/) [![Python](https://img.shields.io/pypi/pyversions/swarmauri_provider_qwen.svg)](https://pypi.org/project/swarmauri_provider_qwen/) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE) [![Downloads](https://static.pepy.tech/badge/swarmauri_provider_qwen)](https://pepy.tech/project/swarmauri_provider_qwen) [![Hits](https://hits.sh/github.com/swarmauri/swarmauri-sdk.svg)](https://hits.sh/github.com/swarmauri/swarmauri-sdk/)
35
+
36
+ # swarmauri_provider_qwen
37
+
38
+ ## Features
39
+
40
+ - Qwen/DashScope authentication, endpoints, catalogs, errors, and schemas.
41
+ - Shared provider resource for Qwen model families.
42
+
43
+ ## Installation
44
+
45
+ `uv add swarmauri_provider_qwen` or `pip install swarmauri_provider_qwen`.
46
+
47
+ ## Usage
48
+
49
+ Inject `QwenProvider(api_key=...)` into a Qwen adapter.
50
+
@@ -0,0 +1,18 @@
1
+ ![Swarmauri](https://github.com/swarmauri/swarmauri-sdk/blob/3d4d1cfa949399d7019ae9d8f296afba773dfb7f/assets/swarmauri.brand.theme.svg)
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/swarmauri_provider_qwen.svg)](https://pypi.org/project/swarmauri_provider_qwen/) [![Python](https://img.shields.io/pypi/pyversions/swarmauri_provider_qwen.svg)](https://pypi.org/project/swarmauri_provider_qwen/) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE) [![Downloads](https://static.pepy.tech/badge/swarmauri_provider_qwen)](https://pepy.tech/project/swarmauri_provider_qwen) [![Hits](https://hits.sh/github.com/swarmauri/swarmauri-sdk.svg)](https://hits.sh/github.com/swarmauri/swarmauri-sdk/)
4
+
5
+ # swarmauri_provider_qwen
6
+
7
+ ## Features
8
+
9
+ - Qwen/DashScope authentication, endpoints, catalogs, errors, and schemas.
10
+ - Shared provider resource for Qwen model families.
11
+
12
+ ## Installation
13
+
14
+ `uv add swarmauri_provider_qwen` or `pip install swarmauri_provider_qwen`.
15
+
16
+ ## Usage
17
+
18
+ Inject `QwenProvider(api_key=...)` into a Qwen adapter.
@@ -0,0 +1,27 @@
1
+ [project]
2
+ name = "swarmauri_provider_qwen"
3
+ version = "0.1.0.dev3"
4
+ description = "Aggregated Qwen provider resources for Swarmauri models."
5
+ readme = "README.md"
6
+ requires-python = ">=3.10,<3.13"
7
+ authors = [{ name = "Jacob Stewart", email = "jacob@swarmauri.com" }]
8
+ license = { file = "LICENSE" }
9
+ dependencies = ["swarmauri_core>=0.11.0.dev5", "swarmauri_base>=0.11.0.dev5"]
10
+ classifiers = ["Development Status :: 1 - Planning", "License :: OSI Approved :: Apache Software License", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12"]
11
+ keywords = ["swarmauri", "provider", "qwen", "dashscope", "realtime"]
12
+ [tool.uv.sources]
13
+ swarmauri_core = { workspace = true }
14
+ swarmauri_base = { workspace = true }
15
+ [project.entry-points."swarmauri.model_providers"]
16
+ QwenProvider = "swarmauri_provider_qwen:QwenProvider"
17
+ [build-system]
18
+ requires = ["poetry-core>=1.8.0"]
19
+ build-backend = "poetry.core.masonry.api"
20
+ [dependency-groups]
21
+ dev = ["pytest>=8.0", "ruff>=0.9.9", "swarmauri_tests_component"]
22
+
23
+ [tool.ruff]
24
+ extend = "../../pyproject.toml"
25
+
26
+ [tool.ruff.lint]
27
+ ignore = ["N999", "RUF012"]
@@ -0,0 +1,21 @@
1
+ from collections.abc import Mapping
2
+ from typing import Literal
3
+
4
+ from pydantic import Field, SecretStr
5
+ from swarmauri_base.model_providers.ProviderAuthBase import ProviderAuthBase
6
+ from swarmauri_base.ComponentBase import ComponentBase
7
+
8
+
9
+ @ComponentBase.register_type(ProviderAuthBase, "QwenAuthConfig")
10
+ class QwenAuthConfig(ProviderAuthBase):
11
+ api_key: SecretStr | None = Field(default=None, exclude=True)
12
+ type: Literal["QwenAuthConfig"] = "QwenAuthConfig"
13
+
14
+ def apply(self, headers: Mapping[str, str]) -> dict[str, str]:
15
+ authorized = dict(headers)
16
+ if self.api_key is None:
17
+ raise ValueError("QwenProvider requires an api_key")
18
+ authorized["Authorization"] = (
19
+ f"Bearer {self.api_key.get_secret_value()}"
20
+ )
21
+ return authorized
@@ -0,0 +1,25 @@
1
+ from typing import Literal
2
+
3
+ from swarmauri_base.model_providers.ProviderEndpointBase import (
4
+ ProviderEndpointBase,
5
+ )
6
+ from swarmauri_base.ComponentBase import ComponentBase
7
+
8
+
9
+ @ComponentBase.register_type(ProviderEndpointBase, "QwenEndpoints")
10
+ class QwenEndpoints(ProviderEndpointBase):
11
+ base_url: str = "https://dashscope-intl.aliyuncs.com/api/v1"
12
+ websocket_url: str = "wss://dashscope-intl.aliyuncs.com/api-ws/v1/realtime"
13
+ type: Literal["QwenEndpoints"] = "QwenEndpoints"
14
+
15
+ def resolve(self, capability: str) -> str:
16
+ endpoints = {
17
+ "api": self.base_url,
18
+ "realtime.connect": self.websocket_url,
19
+ }
20
+ try:
21
+ return endpoints[capability]
22
+ except KeyError as error:
23
+ raise ValueError(
24
+ f"Qwen does not support capability {capability!r}"
25
+ ) from error
@@ -0,0 +1,14 @@
1
+ from typing import Any, Literal
2
+
3
+ from swarmauri_base.model_providers.ProviderErrorMapperBase import (
4
+ ProviderErrorMapperBase,
5
+ )
6
+ from swarmauri_base.ComponentBase import ComponentBase
7
+
8
+
9
+ @ComponentBase.register_type(ProviderErrorMapperBase, "QwenErrorMapper")
10
+ class QwenErrorMapper(ProviderErrorMapperBase):
11
+ type: Literal["QwenErrorMapper"] = "QwenErrorMapper"
12
+
13
+ def map_error(self, error: BaseException | Any) -> BaseException:
14
+ return RuntimeError(f"Qwen provider error: {error}")
@@ -0,0 +1,15 @@
1
+ from typing import Literal
2
+
3
+ from swarmauri_base.model_providers.ModelCatalogBase import ModelCatalogBase
4
+ from swarmauri_base.ComponentBase import ComponentBase
5
+
6
+
7
+ @ComponentBase.register_type(ModelCatalogBase, "QwenModelCatalog")
8
+ class QwenModelCatalog(ModelCatalogBase):
9
+ models: dict = {
10
+ "qwen-omni-turbo-realtime": {
11
+ "name": "qwen-omni-turbo-realtime",
12
+ "features": ["realtime", "audio", "tools"],
13
+ }
14
+ }
15
+ type: Literal["QwenModelCatalog"] = "QwenModelCatalog"
@@ -0,0 +1,30 @@
1
+ from typing import Literal
2
+
3
+ from pydantic import Field, model_validator
4
+ from swarmauri_base.ComponentBase import ComponentBase
5
+ from swarmauri_base.model_providers.ModelProviderBase import ModelProviderBase
6
+
7
+ from .QwenAuthConfig import QwenAuthConfig
8
+ from .QwenEndpoints import QwenEndpoints
9
+ from .QwenErrorMapper import QwenErrorMapper
10
+ from .QwenModelCatalog import QwenModelCatalog
11
+
12
+
13
+ @ComponentBase.register_type(ModelProviderBase, "QwenProvider")
14
+ class QwenProvider(ModelProviderBase):
15
+ provider_name: Literal["qwen"] = "qwen"
16
+ endpoints: QwenEndpoints = Field(default_factory=QwenEndpoints)
17
+ auth: QwenAuthConfig = Field(default_factory=QwenAuthConfig, exclude=True)
18
+ catalog: QwenModelCatalog = Field(default_factory=QwenModelCatalog)
19
+ error_mapper: QwenErrorMapper = Field(default_factory=QwenErrorMapper)
20
+ type: Literal["QwenProvider"] = "QwenProvider"
21
+
22
+ @model_validator(mode="after")
23
+ def configure(self) -> "QwenProvider":
24
+ self.base_url = self.base_url or self.endpoints.resolve("api")
25
+ self.endpoints.base_url = self.base_url
26
+ if self.api_key is not None:
27
+ self.auth.api_key = self.api_key
28
+ elif self.auth.api_key is not None:
29
+ self.api_key = self.auth.api_key
30
+ return self
@@ -0,0 +1,10 @@
1
+ from typing import Any
2
+
3
+
4
+ class QwenToolSchemaConverter:
5
+ def convert(self, tool: Any) -> dict[str, Any]:
6
+ return {
7
+ "type": "function",
8
+ "name": tool.name,
9
+ "parameters": {"type": "object", "properties": {}},
10
+ }
@@ -0,0 +1,15 @@
1
+ from .QwenAuthConfig import QwenAuthConfig
2
+ from .QwenEndpoints import QwenEndpoints
3
+ from .QwenErrorMapper import QwenErrorMapper
4
+ from .QwenModelCatalog import QwenModelCatalog
5
+ from .QwenProvider import QwenProvider
6
+ from .QwenToolSchemaConverter import QwenToolSchemaConverter
7
+
8
+ __all__ = [
9
+ "QwenAuthConfig",
10
+ "QwenEndpoints",
11
+ "QwenErrorMapper",
12
+ "QwenModelCatalog",
13
+ "QwenProvider",
14
+ "QwenToolSchemaConverter",
15
+ ]