rusticai-api 0.0.1__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,87 @@
1
+ Metadata-Version: 2.1
2
+ Name: rusticai-api
3
+ Version: 0.0.1
4
+ Summary: API Server for Rustic AI
5
+ Home-page: https://www.rustic.ai/
6
+ License: Apache-2.0
7
+ Author: Dragonscale Industries Inc.
8
+ Author-email: dev@dragonscale.ai
9
+ Requires-Python: >=3.12,<4.0
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Requires-Dist: fastapi (>=0.115.8,<0.116.0)
15
+ Requires-Dist: griffe (>=1.7.2,<2.0.0)
16
+ Requires-Dist: opentelemetry-distro (>=0.52b1,<0.53)
17
+ Requires-Dist: psycopg (>=3.2.6,<4.0.0)
18
+ Requires-Dist: ptvsd (>=4.3.2,<5.0.0)
19
+ Requires-Dist: python-multipart (>=0.0.20,<0.0.21)
20
+ Requires-Dist: rusticai-core (>=0.0.3,<0.1.0)
21
+ Requires-Dist: rusticai-ray (>=0.0.2,<0.1.0)
22
+ Requires-Dist: starlette (>=0.45.3,<0.46.0)
23
+ Requires-Dist: uvicorn (>=0.34.0,<0.35.0)
24
+ Requires-Dist: websockets (>=15.0.1,<16.0.0)
25
+ Project-URL: Repository, https://github.com/rustic-ai/python-framework
26
+ Project-URL: Rustic AI Core, https://pypi.org/project/rusticai-core/
27
+ Description-Content-Type: text/markdown
28
+
29
+ # Rustic AI API
30
+ This module provides the backend server for the Rustic AI framework. It provides the interface for creating and interacting with guilds.
31
+ The interaction with a guild is supported through a Websocket interface, allowing for real-time communication and updates.
32
+
33
+ ## Installing
34
+
35
+ ```shell
36
+ pip install rusticai-api
37
+ ```
38
+ **Note:** It depends on [rusticai-core](https://pypi.org/project/rusticai-core/) and [rusticai-ray](https://pypi.org/project/rusticai-ray/).
39
+
40
+ ## Running from source
41
+
42
+ 1. Install required dependencies:
43
+ ```shell
44
+ poetry install --with dev
45
+ poetry shell
46
+ ```
47
+
48
+ 2. Start the server:
49
+ ```shell
50
+ # If using an external SQL database, expose RUSTIC_METASTORE to the corresponding url
51
+ # For example, if postgres is run using docker, export RUSTIC_METASTORE=postgresql+psycopg://user:pwd@localhost:5432
52
+ ./scripts/dev_server.sh
53
+ ```
54
+
55
+ Server will be available at `http://localhost:8880` by default. The API documentation can be accessed at `http://localhost:8880/docs`.
56
+
57
+ ## Running from source with Telemetry
58
+
59
+ 1. Install required dependencies:
60
+ ```shell
61
+ poetry install --with dev
62
+ poetry shell
63
+ ```
64
+
65
+ 2. Start Zipkin server - requires [Docker](https://www.docker.com/get-started/)
66
+ ```shell
67
+ sudo chmod 777 scripts/zipkin/data-tmp/
68
+ ./scripts/zipkin/zipkin_up.sh
69
+ ```
70
+
71
+ 3. Set the otel env variables -
72
+ ```shell
73
+ export OTEL_SERVICE_NAME=GuildCommunicationService
74
+ export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://localhost:4318/v1/traces"
75
+ export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
76
+ ```
77
+ Refer [docs](https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#endpoint-configuration)
78
+ for details.
79
+
80
+ 3. Start the server -
81
+ ```shell
82
+ ./scripts/dev_server_with_otel.sh
83
+ ```
84
+ Traces will be visible in Zipkin UI at http://localhost:9411/zipkin/
85
+
86
+ Note: To stop the Zipkin server, use `./scripts/zipkin/zipkin_down.sh`
87
+
@@ -0,0 +1,58 @@
1
+ # Rustic AI API
2
+ This module provides the backend server for the Rustic AI framework. It provides the interface for creating and interacting with guilds.
3
+ The interaction with a guild is supported through a Websocket interface, allowing for real-time communication and updates.
4
+
5
+ ## Installing
6
+
7
+ ```shell
8
+ pip install rusticai-api
9
+ ```
10
+ **Note:** It depends on [rusticai-core](https://pypi.org/project/rusticai-core/) and [rusticai-ray](https://pypi.org/project/rusticai-ray/).
11
+
12
+ ## Running from source
13
+
14
+ 1. Install required dependencies:
15
+ ```shell
16
+ poetry install --with dev
17
+ poetry shell
18
+ ```
19
+
20
+ 2. Start the server:
21
+ ```shell
22
+ # If using an external SQL database, expose RUSTIC_METASTORE to the corresponding url
23
+ # For example, if postgres is run using docker, export RUSTIC_METASTORE=postgresql+psycopg://user:pwd@localhost:5432
24
+ ./scripts/dev_server.sh
25
+ ```
26
+
27
+ Server will be available at `http://localhost:8880` by default. The API documentation can be accessed at `http://localhost:8880/docs`.
28
+
29
+ ## Running from source with Telemetry
30
+
31
+ 1. Install required dependencies:
32
+ ```shell
33
+ poetry install --with dev
34
+ poetry shell
35
+ ```
36
+
37
+ 2. Start Zipkin server - requires [Docker](https://www.docker.com/get-started/)
38
+ ```shell
39
+ sudo chmod 777 scripts/zipkin/data-tmp/
40
+ ./scripts/zipkin/zipkin_up.sh
41
+ ```
42
+
43
+ 3. Set the otel env variables -
44
+ ```shell
45
+ export OTEL_SERVICE_NAME=GuildCommunicationService
46
+ export OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://localhost:4318/v1/traces"
47
+ export OTEL_EXPORTER_OTLP_PROTOCOL="http/protobuf"
48
+ ```
49
+ Refer [docs](https://opentelemetry.io/docs/languages/sdk-configuration/otlp-exporter/#endpoint-configuration)
50
+ for details.
51
+
52
+ 3. Start the server -
53
+ ```shell
54
+ ./scripts/dev_server_with_otel.sh
55
+ ```
56
+ Traces will be visible in Zipkin UI at http://localhost:9411/zipkin/
57
+
58
+ Note: To stop the Zipkin server, use `./scripts/zipkin/zipkin_down.sh`
@@ -0,0 +1,78 @@
1
+ [build-system]
2
+ requires = ["poetry-core"]
3
+ build-backend = "poetry.core.masonry.api"
4
+
5
+ [tool.poetry]
6
+ name = "rusticai-api"
7
+ version = "0.0.1"
8
+ description = "API Server for Rustic AI"
9
+ authors = ["Dragonscale Industries Inc. <dev@dragonscale.ai>"]
10
+ license = "Apache-2.0"
11
+ readme = "README.md"
12
+ homepage = "https://www.rustic.ai/"
13
+ repository = "https://github.com/rustic-ai/python-framework"
14
+ packages = [{ include = "rustic_ai", from = "src" }]
15
+
16
+ [tool.poetry.urls]
17
+ "Rustic AI Core" = "https://pypi.org/project/rusticai-core/"
18
+
19
+ [tool.poetry.dependencies]
20
+ python = "^3.12"
21
+ rusticai-core = { version = "0.0.3"}
22
+ rusticai-ray = { version = "0.0.2"}
23
+ fastapi = "^0.115.8"
24
+ starlette = "^0.45.3"
25
+ uvicorn = "^0.34.0"
26
+ ptvsd = "^4.3.2"
27
+ python-multipart = "^0.0.20"
28
+ opentelemetry-distro = "^0.52b1"
29
+ websockets = "^15.0.1"
30
+ griffe = "^1.7.2"
31
+ psycopg = "^3.2.6"
32
+
33
+ [tool.poetry-monorepo.deps]
34
+
35
+ [tool.poetry.group.dev.dependencies]
36
+ pytest = "^8.3.4"
37
+ black = { version = "^24.2.0", extras = ["jupyter"] }
38
+ flake8 = "^7.1.2"
39
+ tox = "^4.24.1"
40
+ isort = "^6.0.0"
41
+ mypy = "^1.15.0"
42
+ pytest-asyncio = "^0.25.3"
43
+ httpx = "^0.28.1"
44
+
45
+ [tool.black]
46
+ line-length = 120
47
+ target-version = ['py312']
48
+ include = '\.pyi?$'
49
+ exclude = '''
50
+ /(
51
+ \.git
52
+ | \.mypy_cache
53
+ | \.tox
54
+ | \.venv
55
+ | _build
56
+ | buck-out
57
+ | build
58
+ | dist
59
+ )/
60
+ '''
61
+
62
+ [tool.mypy]
63
+ python_version = "3.12"
64
+ ignore_missing_imports = true
65
+ check_untyped_defs = true
66
+ plugins = "pydantic.mypy"
67
+ explicit_package_bases = true
68
+
69
+
70
+ [tool.isort]
71
+ profile = "black"
72
+ known_third_party = ["pydantic"]
73
+ known_first_party = ["rustic_ai.core", "rustic_ai.ray", "rustic_ai.api_server"]
74
+
75
+
76
+ [tool.pytest.ini_options]
77
+ asyncio_mode = "auto"
78
+ asyncio_default_fixture_loop_scope="function"
@@ -0,0 +1,103 @@
1
+ from typing import Dict, Optional
2
+
3
+ from fastapi import HTTPException
4
+ from sqlalchemy import Engine
5
+
6
+ from rustic_ai.core.guild.agent_ext.depends.dependency_resolver import (
7
+ DependencyResolver,
8
+ )
9
+ from rustic_ai.core.guild.builders import GuildHelper
10
+ from rustic_ai.core.guild.dsl import DependencySpec
11
+ from rustic_ai.core.guild.metastore.guild_store import GuildStore
12
+ from rustic_ai.core.utils.basic_class_utils import get_class_from_name
13
+
14
+
15
+ class ApiDependencyManager:
16
+ """Singleton class to access dependencies for a guild from the API server."""
17
+
18
+ __instance: Optional["ApiDependencyManager"] = None
19
+
20
+ def __new__(cls):
21
+ if cls.__instance is None:
22
+ cls.__instance = super(ApiDependencyManager, cls).__new__(cls)
23
+ return cls.__instance
24
+
25
+ def __init__(self):
26
+ if not hasattr(self, "initialized"):
27
+ self.dependency_map_cache: Dict[str, Dict[str, DependencySpec]] = {}
28
+ self.dependency_resolver_cache: Dict[str, Dict[str, DependencyResolver]] = {}
29
+ self.initialized = True
30
+
31
+ def get_dependency(self, dependency_name: str, engine: Engine, guild_id: str, agent_id: Optional[str] = None):
32
+ """
33
+ Gets the dependency resolver for the given dependency name.
34
+
35
+ Args:
36
+ dependency_name (str): The name of the dependency.
37
+ engine (Engine): The database engine.
38
+ guild_id (str): The guild id.
39
+ agent_id (str): The agent id.
40
+
41
+ Returns:
42
+ Any: The dependency.
43
+ """
44
+
45
+ if (
46
+ guild_id not in self.dependency_resolver_cache
47
+ or dependency_name not in self.dependency_resolver_cache[guild_id]
48
+ ):
49
+ if guild_id not in self.dependency_map_cache:
50
+
51
+ guild_store = GuildStore(engine)
52
+ guild_model = guild_store.get_guild(guild_id)
53
+
54
+ if not guild_model:
55
+ raise HTTPException(status_code=404, detail="Guild not found")
56
+
57
+ guild_spec = guild_model.to_guild_spec()
58
+
59
+ self.dependency_map_cache[guild_id] = GuildHelper.get_guild_dependency_map(guild_spec)
60
+
61
+ if dependency_name not in self.dependency_map_cache[guild_id]: # pragma: no cover
62
+ raise HTTPException(
63
+ status_code=404, detail=f"Dependency for {dependency_name} not configured for guild {guild_id}"
64
+ )
65
+
66
+ if guild_id not in self.dependency_resolver_cache:
67
+ self.dependency_resolver_cache[guild_id] = {}
68
+
69
+ self.dependency_resolver_cache[guild_id][dependency_name] = self._load_dependency_resolver(
70
+ guild_id, dependency_name
71
+ )
72
+
73
+ resolver = self.dependency_resolver_cache[guild_id][dependency_name]
74
+ dependency = resolver.get_or_resolve(guild_id, agent_id)
75
+
76
+ return dependency
77
+
78
+ def _load_dependency_resolver(self, guild_id: str, name: str) -> DependencyResolver:
79
+ """
80
+ Loads the dependency resolver for the given name.
81
+
82
+ Args:
83
+ guild_id (str): The guild id.
84
+ name (str): The name of the dependency resolver.
85
+
86
+ Returns:
87
+ DependencyResolver: The dependency resolver for the agent.
88
+ """
89
+ dependencies = self.dependency_map_cache[guild_id]
90
+ if name in dependencies:
91
+ resolver_spec = dependencies[name]
92
+ resolver_class = get_class_from_name(resolver_spec.class_name)
93
+ if issubclass(resolver_class, DependencyResolver):
94
+ return resolver_class(**resolver_spec.properties)
95
+ else: # pragma: no cover
96
+ raise ValueError(f"Dependency resolver {resolver_spec} is not a valid dependency resolver.")
97
+ else: # pragma: no cover
98
+ raise ValueError(f"Dependency {name} not found in agent dependencies.")
99
+
100
+ @classmethod
101
+ def get_instance(cls) -> "ApiDependencyManager":
102
+ api_dependency_manager = ApiDependencyManager()
103
+ return api_dependency_manager
@@ -0,0 +1,4 @@
1
+ from .catalog_store import CatalogStore
2
+ from .router import catalog_router
3
+
4
+ __all__ = ["catalog_router", "CatalogStore"]