swarmauri_provider_amazon_nova 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_amazon_nova
3
+ Version: 0.1.0.dev3
4
+ Summary: Aggregated Amazon Nova 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,amazon nova,bedrock,nova sonic
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_amazon_nova.svg)](https://pypi.org/project/swarmauri_provider_amazon_nova/) [![Python](https://img.shields.io/pypi/pyversions/swarmauri_provider_amazon_nova.svg)](https://pypi.org/project/swarmauri_provider_amazon_nova/) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE) [![Downloads](https://static.pepy.tech/badge/swarmauri_provider_amazon_nova)](https://pepy.tech/project/swarmauri_provider_amazon_nova) [![Hits](https://hits.sh/github.com/swarmauri/swarmauri-sdk.svg)](https://hits.sh/github.com/swarmauri/swarmauri-sdk/)
35
+
36
+ # swarmauri_provider_amazon_nova
37
+
38
+ ## Features
39
+
40
+ - AWS identity, region, Bedrock endpoint, catalog, error, and schema resources.
41
+ - Shared provider resource for Amazon Nova model families.
42
+
43
+ ## Installation
44
+
45
+ `uv add swarmauri_provider_amazon_nova` or `pip install swarmauri_provider_amazon_nova`.
46
+
47
+ ## Usage
48
+
49
+ Inject `AmazonNovaProvider(region=...)` into a Nova model 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_amazon_nova.svg)](https://pypi.org/project/swarmauri_provider_amazon_nova/) [![Python](https://img.shields.io/pypi/pyversions/swarmauri_provider_amazon_nova.svg)](https://pypi.org/project/swarmauri_provider_amazon_nova/) [![License](https://img.shields.io/badge/license-Apache--2.0-blue)](LICENSE) [![Downloads](https://static.pepy.tech/badge/swarmauri_provider_amazon_nova)](https://pepy.tech/project/swarmauri_provider_amazon_nova) [![Hits](https://hits.sh/github.com/swarmauri/swarmauri-sdk.svg)](https://hits.sh/github.com/swarmauri/swarmauri-sdk/)
4
+
5
+ # swarmauri_provider_amazon_nova
6
+
7
+ ## Features
8
+
9
+ - AWS identity, region, Bedrock endpoint, catalog, error, and schema resources.
10
+ - Shared provider resource for Amazon Nova model families.
11
+
12
+ ## Installation
13
+
14
+ `uv add swarmauri_provider_amazon_nova` or `pip install swarmauri_provider_amazon_nova`.
15
+
16
+ ## Usage
17
+
18
+ Inject `AmazonNovaProvider(region=...)` into a Nova model adapter.
@@ -0,0 +1,27 @@
1
+ [project]
2
+ name = "swarmauri_provider_amazon_nova"
3
+ version = "0.1.0.dev3"
4
+ description = "Aggregated Amazon Nova 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", "amazon nova", "bedrock", "nova sonic"]
12
+ [tool.uv.sources]
13
+ swarmauri_core = { workspace = true }
14
+ swarmauri_base = { workspace = true }
15
+ [project.entry-points."swarmauri.model_providers"]
16
+ AmazonNovaProvider = "swarmauri_provider_amazon_nova:AmazonNovaProvider"
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,39 @@
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, "AmazonNovaAuthConfig")
10
+ class AmazonNovaAuthConfig(ProviderAuthBase):
11
+ access_key_id: SecretStr | None = Field(default=None, exclude=True)
12
+ secret_access_key: SecretStr | None = Field(default=None, exclude=True)
13
+ session_token: SecretStr | None = Field(default=None, exclude=True)
14
+ profile: str | None = None
15
+ type: Literal["AmazonNovaAuthConfig"] = "AmazonNovaAuthConfig"
16
+
17
+ def apply(self, headers: Mapping[str, str]) -> dict[str, str]:
18
+ """Preserve headers; the AWS transport applies request-aware SigV4."""
19
+ return dict(headers)
20
+
21
+ def sdk_credentials(self) -> dict[str, str]:
22
+ if (self.access_key_id is None) != (self.secret_access_key is None):
23
+ raise ValueError(
24
+ "AWS access_key_id and secret_access_key must be "
25
+ "provided together"
26
+ )
27
+ if self.access_key_id is None:
28
+ return {}
29
+ credentials = {
30
+ "aws_access_key_id": self.access_key_id.get_secret_value(),
31
+ "aws_secret_access_key": (
32
+ self.secret_access_key.get_secret_value()
33
+ ),
34
+ }
35
+ if self.session_token is not None:
36
+ credentials["aws_session_token"] = (
37
+ self.session_token.get_secret_value()
38
+ )
39
+ return credentials
@@ -0,0 +1,27 @@
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, "AmazonNovaEndpoints")
10
+ class AmazonNovaEndpoints(ProviderEndpointBase):
11
+ region: str = "us-east-1"
12
+ service: str = "bedrock-runtime"
13
+ type: Literal["AmazonNovaEndpoints"] = "AmazonNovaEndpoints"
14
+
15
+ def runtime_url(self) -> str:
16
+ return f"https://bedrock-runtime.{self.region}.amazonaws.com"
17
+
18
+ def resolve(self, capability: str) -> str:
19
+ if capability not in {
20
+ "bedrock.runtime",
21
+ "live.connect",
22
+ "model.invoke",
23
+ }:
24
+ raise ValueError(
25
+ f"Amazon Nova does not support capability {capability!r}"
26
+ )
27
+ return self.runtime_url()
@@ -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, "AmazonNovaErrorMapper")
10
+ class AmazonNovaErrorMapper(ProviderErrorMapperBase):
11
+ type: Literal["AmazonNovaErrorMapper"] = "AmazonNovaErrorMapper"
12
+
13
+ def map_error(self, error: BaseException | Any) -> BaseException:
14
+ return RuntimeError(f"Amazon Nova 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, "AmazonNovaModelCatalog")
8
+ class AmazonNovaModelCatalog(ModelCatalogBase):
9
+ models: dict = {
10
+ "amazon.nova-sonic-v1:0": {
11
+ "name": "amazon.nova-sonic-v1:0",
12
+ "features": ["realtime", "audio", "tools", "http2"],
13
+ }
14
+ }
15
+ type: Literal["AmazonNovaModelCatalog"] = "AmazonNovaModelCatalog"
@@ -0,0 +1,86 @@
1
+ from typing import Literal
2
+ from urllib.parse import quote
3
+
4
+ from pydantic import Field, SecretStr, model_validator
5
+ from swarmauri_base.ComponentBase import ComponentBase
6
+ from swarmauri_base.model_providers.ModelProviderBase import ModelProviderBase
7
+ from swarmauri_base.model_providers.ProviderConnectionConfig import (
8
+ ProviderConnectionConfig,
9
+ )
10
+
11
+ from .AmazonNovaAuthConfig import AmazonNovaAuthConfig
12
+ from .AmazonNovaEndpoints import AmazonNovaEndpoints
13
+ from .AmazonNovaErrorMapper import AmazonNovaErrorMapper
14
+ from .AmazonNovaModelCatalog import AmazonNovaModelCatalog
15
+
16
+
17
+ @ComponentBase.register_type(ModelProviderBase, "AmazonNovaProvider")
18
+ class AmazonNovaProvider(ModelProviderBase):
19
+ provider_name: Literal["amazon_nova"] = "amazon_nova"
20
+ access_key_id: SecretStr | None = Field(default=None, exclude=True)
21
+ secret_access_key: SecretStr | None = Field(default=None, exclude=True)
22
+ session_token: SecretStr | None = Field(default=None, exclude=True)
23
+ profile: str | None = None
24
+ auth: AmazonNovaAuthConfig = Field(
25
+ default_factory=AmazonNovaAuthConfig, exclude=True
26
+ )
27
+ endpoints: AmazonNovaEndpoints = Field(default_factory=AmazonNovaEndpoints)
28
+ catalog: AmazonNovaModelCatalog = Field(
29
+ default_factory=AmazonNovaModelCatalog
30
+ )
31
+ error_mapper: AmazonNovaErrorMapper = Field(
32
+ default_factory=AmazonNovaErrorMapper
33
+ )
34
+ type: Literal["AmazonNovaProvider"] = "AmazonNovaProvider"
35
+
36
+ @model_validator(mode="after")
37
+ def configure(self) -> "AmazonNovaProvider":
38
+ self.region = self.region or self.endpoints.region
39
+ self.endpoints.region = self.region
40
+ self.base_url = self.base_url or self.endpoints.resolve(
41
+ "bedrock.runtime"
42
+ )
43
+ if self.access_key_id is not None:
44
+ self.auth.access_key_id = self.access_key_id
45
+ elif self.auth.access_key_id is not None:
46
+ self.access_key_id = self.auth.access_key_id
47
+ if self.secret_access_key is not None:
48
+ self.auth.secret_access_key = self.secret_access_key
49
+ elif self.auth.secret_access_key is not None:
50
+ self.secret_access_key = self.auth.secret_access_key
51
+ if self.session_token is not None:
52
+ self.auth.session_token = self.session_token
53
+ elif self.auth.session_token is not None:
54
+ self.session_token = self.auth.session_token
55
+ if self.profile is not None:
56
+ self.auth.profile = self.profile
57
+ elif self.auth.profile is not None:
58
+ self.profile = self.auth.profile
59
+ return self
60
+
61
+ def connection_config(
62
+ self, capability: str, model: str | None = None
63
+ ) -> ProviderConnectionConfig:
64
+ endpoint = self.endpoints.resolve(capability)
65
+ options: dict[str, object] = {"region": self.region}
66
+ if self.profile is not None:
67
+ options["profile"] = self.profile
68
+ if model is not None:
69
+ options["model_id"] = model
70
+ endpoint = (
71
+ f"{endpoint.rstrip('/')}/model/{quote(model, safe='')}"
72
+ "/invoke-with-bidirectional-stream"
73
+ )
74
+ return ProviderConnectionConfig(
75
+ endpoint=endpoint,
76
+ transport_options=options,
77
+ auth_context=self.auth,
78
+ )
79
+
80
+ def prepare_connection(
81
+ self, capability: str, model: str | None = None
82
+ ) -> ProviderConnectionConfig:
83
+ config = super().prepare_connection(capability, model)
84
+ options = dict(config.transport_options)
85
+ options.update(self.auth.sdk_credentials())
86
+ return config.model_copy(update={"transport_options": options})
@@ -0,0 +1,12 @@
1
+ from typing import Any
2
+
3
+
4
+ class AmazonNovaToolSchemaConverter:
5
+ def convert(self, tool: Any) -> dict[str, Any]:
6
+ return {
7
+ "toolSpec": {
8
+ "name": tool.name,
9
+ "description": getattr(tool, "description", ""),
10
+ "inputSchema": {"json": {"type": "object", "properties": {}}},
11
+ }
12
+ }
@@ -0,0 +1,15 @@
1
+ from .AmazonNovaAuthConfig import AmazonNovaAuthConfig
2
+ from .AmazonNovaEndpoints import AmazonNovaEndpoints
3
+ from .AmazonNovaErrorMapper import AmazonNovaErrorMapper
4
+ from .AmazonNovaModelCatalog import AmazonNovaModelCatalog
5
+ from .AmazonNovaProvider import AmazonNovaProvider
6
+ from .AmazonNovaToolSchemaConverter import AmazonNovaToolSchemaConverter
7
+
8
+ __all__ = [
9
+ "AmazonNovaAuthConfig",
10
+ "AmazonNovaEndpoints",
11
+ "AmazonNovaErrorMapper",
12
+ "AmazonNovaModelCatalog",
13
+ "AmazonNovaProvider",
14
+ "AmazonNovaToolSchemaConverter",
15
+ ]