rusticai-api 0.0.1__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.
- rustic_ai/api_server/__init__.py +0 -0
- rustic_ai/api_server/api_dependency_manager.py +103 -0
- rustic_ai/api_server/catalog/__init__.py +4 -0
- rustic_ai/api_server/catalog/catalog_store.py +607 -0
- rustic_ai/api_server/catalog/models.py +338 -0
- rustic_ai/api_server/catalog/router.py +423 -0
- rustic_ai/api_server/guilds/__init__.py +4 -0
- rustic_ai/api_server/guilds/comms_manager.py +256 -0
- rustic_ai/api_server/guilds/router.py +426 -0
- rustic_ai/api_server/guilds/schema.py +5 -0
- rustic_ai/api_server/guilds/service.py +30 -0
- rustic_ai/api_server/guilds/socket.py +52 -0
- rustic_ai/api_server/guilds/system_comms_manager.py +238 -0
- rustic_ai/api_server/logging/__init__.py +4 -0
- rustic_ai/api_server/logging/config.py +35 -0
- rustic_ai/api_server/logging/format.py +24 -0
- rustic_ai/api_server/main.py +95 -0
- rustic_ai/api_server/main_debug.py +17 -0
- rusticai_api-0.0.1.dist-info/METADATA +87 -0
- rusticai_api-0.0.1.dist-info/RECORD +21 -0
- rusticai_api-0.0.1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import logging
|
|
3
|
+
import random
|
|
4
|
+
import time
|
|
5
|
+
from typing import Callable, Dict, Optional
|
|
6
|
+
|
|
7
|
+
import shortuuid
|
|
8
|
+
from fastapi import WebSocket, WebSocketDisconnect
|
|
9
|
+
from opentelemetry import trace
|
|
10
|
+
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
|
|
11
|
+
from sqlalchemy import Engine
|
|
12
|
+
|
|
13
|
+
from rustic_ai.core import (
|
|
14
|
+
AgentTag,
|
|
15
|
+
Client,
|
|
16
|
+
GuildSpec,
|
|
17
|
+
Message,
|
|
18
|
+
MessageTrackingClient,
|
|
19
|
+
MessagingInterface,
|
|
20
|
+
Priority,
|
|
21
|
+
)
|
|
22
|
+
from rustic_ai.core.agents.utils import UserProxyAgent
|
|
23
|
+
from rustic_ai.core.guild.agent_ext.mixins.telemetry import TelemetryConstants
|
|
24
|
+
from rustic_ai.core.guild.builders import GuildHelper
|
|
25
|
+
from rustic_ai.core.guild.metastore import GuildStore
|
|
26
|
+
from rustic_ai.core.utils import GemstoneGenerator
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class SystemCommunicationManager:
|
|
30
|
+
_gemstone: GemstoneGenerator = GemstoneGenerator(random.randint(10, 100))
|
|
31
|
+
_instance: Optional["SystemCommunicationManager"] = None
|
|
32
|
+
|
|
33
|
+
def __new__(cls):
|
|
34
|
+
if cls._instance is None:
|
|
35
|
+
cls._instance = super().__new__(cls)
|
|
36
|
+
return cls._instance
|
|
37
|
+
|
|
38
|
+
def __init__(self):
|
|
39
|
+
if not hasattr(self, "initialized"):
|
|
40
|
+
self.initialized = True
|
|
41
|
+
self.tracer = trace.get_tracer(TelemetryConstants.TRACER_NAME)
|
|
42
|
+
self.guild_specs: Dict[str, GuildSpec] = {}
|
|
43
|
+
self.messaging_interfaces: Dict[str, MessagingInterface] = {}
|
|
44
|
+
|
|
45
|
+
async def shutdown(self):
|
|
46
|
+
for _, messaging in self.messaging_interfaces.items():
|
|
47
|
+
messaging.shutdown()
|
|
48
|
+
|
|
49
|
+
async def get_or_fetch_guild_spec(self, guild_id: str, engine: Engine) -> Optional[GuildSpec]:
|
|
50
|
+
if guild_id not in self.guild_specs:
|
|
51
|
+
guild_store = GuildStore(engine)
|
|
52
|
+
guild_model = guild_store.get_guild(guild_id)
|
|
53
|
+
|
|
54
|
+
if guild_model:
|
|
55
|
+
self.guild_specs[guild_id] = guild_model.to_guild_spec()
|
|
56
|
+
else: # pragma: no cover
|
|
57
|
+
logging.debug(f"Guild with ID {guild_id} not found")
|
|
58
|
+
return None
|
|
59
|
+
|
|
60
|
+
return self.guild_specs[guild_id]
|
|
61
|
+
|
|
62
|
+
async def get_or_create_messaging_interface(self, guild_spec: GuildSpec) -> MessagingInterface:
|
|
63
|
+
guild_id = guild_spec.id
|
|
64
|
+
if guild_id not in self.messaging_interfaces:
|
|
65
|
+
guild_spec = guild_spec
|
|
66
|
+
messaging_config = GuildHelper.get_messaging_config(guild_spec)
|
|
67
|
+
self.messaging_interfaces[guild_id] = MessagingInterface(guild_id, messaging_config)
|
|
68
|
+
return self.messaging_interfaces[guild_id]
|
|
69
|
+
|
|
70
|
+
def build_message_handler(
|
|
71
|
+
self,
|
|
72
|
+
guild_id: str,
|
|
73
|
+
user_id: str,
|
|
74
|
+
websocket: WebSocket,
|
|
75
|
+
loop: asyncio.AbstractEventLoop,
|
|
76
|
+
) -> Callable[[Message], None]:
|
|
77
|
+
def on_message(message: Message) -> None:
|
|
78
|
+
logging.debug(f"Received message: {message}")
|
|
79
|
+
|
|
80
|
+
try:
|
|
81
|
+
coroutine = self.send_message(guild_id, user_id, message, websocket)
|
|
82
|
+
asyncio.run_coroutine_threadsafe(coroutine, loop)
|
|
83
|
+
except ValueError as e: # pragma: no cover
|
|
84
|
+
logging.error(f"Invalid message received: {e}")
|
|
85
|
+
except RuntimeError as e: # pragma: no cover
|
|
86
|
+
logging.error(f"Error sending message: {e}")
|
|
87
|
+
except Exception as e: # pragma: no cover
|
|
88
|
+
logging.error(f"Error sending message: {e}")
|
|
89
|
+
|
|
90
|
+
return on_message
|
|
91
|
+
|
|
92
|
+
async def create_guild_client(
|
|
93
|
+
self,
|
|
94
|
+
guild_id: str,
|
|
95
|
+
user_id: str,
|
|
96
|
+
messaging: MessagingInterface,
|
|
97
|
+
websocket: WebSocket,
|
|
98
|
+
loop: asyncio.AbstractEventLoop,
|
|
99
|
+
) -> Client:
|
|
100
|
+
uuid = shortuuid.uuid()
|
|
101
|
+
client = MessageTrackingClient(
|
|
102
|
+
uuid,
|
|
103
|
+
f"{guild_id}_{uuid}",
|
|
104
|
+
self.build_message_handler(guild_id, user_id, websocket, loop),
|
|
105
|
+
)
|
|
106
|
+
messaging.register_client(client)
|
|
107
|
+
return client
|
|
108
|
+
|
|
109
|
+
async def send_message(self, guild_id: str, user_id: str, message: Message, websocket: WebSocket):
|
|
110
|
+
logging.debug(f"Sending message to User[{user_id}] on WS[{websocket}]: \n{message.model_dump_json()}")
|
|
111
|
+
span_context = None
|
|
112
|
+
if message.traceparent:
|
|
113
|
+
carrier = {"traceparent": message.traceparent}
|
|
114
|
+
span_context = TraceContextTextMapPropagator().extract(carrier)
|
|
115
|
+
with self.tracer.start_as_current_span(
|
|
116
|
+
"websocket:send_sys_message",
|
|
117
|
+
attributes={
|
|
118
|
+
"user_id": user_id,
|
|
119
|
+
"guild_id": guild_id,
|
|
120
|
+
"message_id": f"id:{message.id}",
|
|
121
|
+
"message_format": message.format,
|
|
122
|
+
"message_topic": message.topic_published_to or "UNKNOWN",
|
|
123
|
+
"agent_id": message.sender.id or "UNKNOWN",
|
|
124
|
+
"agent_name": message.sender.name or "UNKNOWN",
|
|
125
|
+
"root_thread_id": f"id:{message.root_thread_id}",
|
|
126
|
+
},
|
|
127
|
+
context=span_context,
|
|
128
|
+
):
|
|
129
|
+
try:
|
|
130
|
+
await websocket.send_json(message.model_dump())
|
|
131
|
+
except Exception as e: # pragma: no cover
|
|
132
|
+
logging.error(f"Error sending message: {e}")
|
|
133
|
+
|
|
134
|
+
async def handle_websocket_connection(
|
|
135
|
+
self,
|
|
136
|
+
websocket: WebSocket,
|
|
137
|
+
guild_id: str,
|
|
138
|
+
user_id: str,
|
|
139
|
+
engine: Engine,
|
|
140
|
+
):
|
|
141
|
+
guild_spec = await self.get_or_fetch_guild_spec(guild_id, engine)
|
|
142
|
+
|
|
143
|
+
if not guild_spec: # pragma: no cover
|
|
144
|
+
logging.error(f"Guild with ID {guild_id} not found")
|
|
145
|
+
await websocket.close()
|
|
146
|
+
return
|
|
147
|
+
else:
|
|
148
|
+
await websocket.accept()
|
|
149
|
+
|
|
150
|
+
loop = asyncio.get_running_loop()
|
|
151
|
+
|
|
152
|
+
messaging: MessagingInterface = await self.get_or_create_messaging_interface(guild_spec)
|
|
153
|
+
guild_client: Client = await self.create_guild_client(guild_id, user_id, messaging, websocket, loop)
|
|
154
|
+
messaging.subscribe(
|
|
155
|
+
UserProxyAgent.get_user_system_notifications_topic(user_id),
|
|
156
|
+
guild_client,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
user_agent_tag = AgentTag(id=f"sys_comms_socket:{user_id}")
|
|
160
|
+
|
|
161
|
+
try:
|
|
162
|
+
while True:
|
|
163
|
+
try:
|
|
164
|
+
data = await websocket.receive_json()
|
|
165
|
+
except ValueError as e: # pragma: no cover
|
|
166
|
+
logging.error(f"Invalid JSON received: {e}")
|
|
167
|
+
continue
|
|
168
|
+
|
|
169
|
+
id = data.get("id", None)
|
|
170
|
+
|
|
171
|
+
if id and isinstance(id, str):
|
|
172
|
+
idg = self._gemstone.get_id_from_string(id)
|
|
173
|
+
elif id and isinstance(id, int):
|
|
174
|
+
idg = self._gemstone.get_id_from_int(id)
|
|
175
|
+
|
|
176
|
+
priority = Priority(data.get("priority", Priority.NORMAL.value))
|
|
177
|
+
if not idg or idg.timestamp - (time.time_ns() // 1000000) > 1000: # pragma: no cover
|
|
178
|
+
data["id"] = self._gemstone.get_id(priority).to_int()
|
|
179
|
+
else:
|
|
180
|
+
data["id"] = idg.to_int()
|
|
181
|
+
|
|
182
|
+
with self.tracer.start_as_current_span(
|
|
183
|
+
"websocket:receive_sys_message",
|
|
184
|
+
attributes={
|
|
185
|
+
"user_id": user_id,
|
|
186
|
+
"guild_id": guild_id,
|
|
187
|
+
"guild_name": guild_spec.name,
|
|
188
|
+
"message_id": f"id:{data['id']}",
|
|
189
|
+
"message_format": data.get("format", "UNKNOWN"),
|
|
190
|
+
},
|
|
191
|
+
) as span:
|
|
192
|
+
|
|
193
|
+
carrier: Dict[str, str] = {}
|
|
194
|
+
TraceContextTextMapPropagator().inject(carrier, context=trace.set_span_in_context(span))
|
|
195
|
+
|
|
196
|
+
logging.debug(f"Carrier: {carrier}")
|
|
197
|
+
|
|
198
|
+
data["sender"] = user_agent_tag.model_dump()
|
|
199
|
+
|
|
200
|
+
if "thread" not in data or not data["thread"]:
|
|
201
|
+
data["thread"] = []
|
|
202
|
+
|
|
203
|
+
traceparent = carrier.get("traceparent", TelemetryConstants.NO_TRACING)
|
|
204
|
+
|
|
205
|
+
data["thread"].append(data["id"])
|
|
206
|
+
data["traceparent"] = traceparent
|
|
207
|
+
|
|
208
|
+
try:
|
|
209
|
+
logging.debug(f"Received message: {data}")
|
|
210
|
+
message = Message(
|
|
211
|
+
idg,
|
|
212
|
+
topics=UserProxyAgent.get_user_system_requests_topic(user_id),
|
|
213
|
+
sender=user_agent_tag,
|
|
214
|
+
format=data["format"],
|
|
215
|
+
payload=data["payload"],
|
|
216
|
+
thread=[data["id"]],
|
|
217
|
+
traceparent=traceparent,
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
logging.debug(f"Publishing message: {message.model_dump_json()}")
|
|
221
|
+
|
|
222
|
+
if message:
|
|
223
|
+
guild_client.publish(message)
|
|
224
|
+
|
|
225
|
+
except ValueError as e: # pragma: no cover
|
|
226
|
+
logging.error(f"Invalid message received: {e}")
|
|
227
|
+
continue
|
|
228
|
+
|
|
229
|
+
except WebSocketDisconnect:
|
|
230
|
+
messaging.unsubscribe(
|
|
231
|
+
UserProxyAgent.get_user_system_notifications_topic(user_id),
|
|
232
|
+
guild_client,
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
@classmethod
|
|
236
|
+
def get_instance(cls) -> "SystemCommunicationManager":
|
|
237
|
+
scm = SystemCommunicationManager()
|
|
238
|
+
return scm
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
logging_level = os.environ.get("RUSTIC_LOGGING_LEVEL", "DEBUG")
|
|
4
|
+
|
|
5
|
+
LOGGING_CONFIG = {
|
|
6
|
+
"version": 1,
|
|
7
|
+
"disable_existing_loggers": True,
|
|
8
|
+
"formatters": {
|
|
9
|
+
"standard": {"format": "%(levelname)s:\t %(asctime)s - %(name)s - %(message)s (%(filename)s:%(lineno)d)"},
|
|
10
|
+
},
|
|
11
|
+
"handlers": {
|
|
12
|
+
"default": {
|
|
13
|
+
"formatter": "standard",
|
|
14
|
+
"class": "logging.StreamHandler",
|
|
15
|
+
"stream": "ext://sys.stdout", # Default is stderr
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
"loggers": {
|
|
19
|
+
"": { # root logger
|
|
20
|
+
"level": logging_level,
|
|
21
|
+
"handlers": ["default"],
|
|
22
|
+
"propagate": False,
|
|
23
|
+
},
|
|
24
|
+
"uvicorn.access": {
|
|
25
|
+
"level": logging_level,
|
|
26
|
+
"handlers": ["default"],
|
|
27
|
+
"propagate": False,
|
|
28
|
+
},
|
|
29
|
+
"uvicorn.error": {
|
|
30
|
+
"level": logging_level,
|
|
31
|
+
"handlers": ["default"],
|
|
32
|
+
"propagate": False,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class RusticLogFormatter(logging.Formatter):
|
|
5
|
+
|
|
6
|
+
grey = "\x1b[38;20m"
|
|
7
|
+
yellow = "\x1b[33;20m"
|
|
8
|
+
red = "\x1b[31;20m"
|
|
9
|
+
bold_red = "\x1b[31;1m"
|
|
10
|
+
reset = "\x1b[0m"
|
|
11
|
+
format_str = "%(levelname)s:\t %(asctime)s - %(name)s - %(message)s (%(filename)s:%(lineno)d)"
|
|
12
|
+
|
|
13
|
+
FORMATS = {
|
|
14
|
+
logging.DEBUG: grey + format_str + reset,
|
|
15
|
+
logging.INFO: grey + format_str + reset,
|
|
16
|
+
logging.WARNING: yellow + format_str + reset,
|
|
17
|
+
logging.ERROR: red + format_str + reset,
|
|
18
|
+
logging.CRITICAL: bold_red + format_str + reset,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
def format(self, record):
|
|
22
|
+
log_fmt = self.FORMATS.get(record.levelno)
|
|
23
|
+
formatter = logging.Formatter(log_fmt)
|
|
24
|
+
return formatter.format(record)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import logging
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
import uvicorn
|
|
5
|
+
from fastapi import FastAPI, HTTPException
|
|
6
|
+
from fastapi.exception_handlers import http_exception_handler
|
|
7
|
+
from fastapi.middleware.cors import CORSMiddleware
|
|
8
|
+
from starlette.exceptions import HTTPException as StarletteHTTPException
|
|
9
|
+
from starlette.requests import Request
|
|
10
|
+
|
|
11
|
+
import ray
|
|
12
|
+
from rustic_ai.api_server import catalog, guilds
|
|
13
|
+
from rustic_ai.api_server.guilds.socket import lifespan
|
|
14
|
+
from rustic_ai.api_server.logging import LOGGING_CONFIG, RusticLogFormatter
|
|
15
|
+
from rustic_ai.core.guild.metastore.database import Metastore
|
|
16
|
+
|
|
17
|
+
logging_level = os.environ.get("RUSTIC_LOGGING_LEVEL", "DEBUG")
|
|
18
|
+
formatter = RusticLogFormatter()
|
|
19
|
+
|
|
20
|
+
ch = logging.StreamHandler()
|
|
21
|
+
ch.setFormatter(formatter)
|
|
22
|
+
|
|
23
|
+
logging.basicConfig(
|
|
24
|
+
level=logging_level,
|
|
25
|
+
datefmt="%Y-%m-%d %H:%M:%S",
|
|
26
|
+
handlers=[ch],
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
INITIALIZE_RAY_CLUSTER = os.environ.get("RUSTIC_INIT_RAY_CLUSTER", "False")
|
|
30
|
+
if INITIALIZE_RAY_CLUSTER.lower() == "true":
|
|
31
|
+
ray.init(include_dashboard=True)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if not Metastore.is_initialized():
|
|
35
|
+
rustic_metastore = os.environ.get("RUSTIC_METASTORE", "sqlite:///rustic_app.db")
|
|
36
|
+
Metastore.initialize_engine(rustic_metastore)
|
|
37
|
+
|
|
38
|
+
app = FastAPI(title="Rustic AI API", lifespan=lifespan)
|
|
39
|
+
app.include_router(guilds.router, prefix="/api")
|
|
40
|
+
app.include_router(guilds.socket, prefix="/ws")
|
|
41
|
+
app.include_router(catalog.catalog_router, prefix="/catalog")
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
origins = [
|
|
45
|
+
os.environ.get("RUSTIC_CORS_ORIGIN", "http://localhost:3000"),
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
app.add_middleware(
|
|
49
|
+
CORSMiddleware,
|
|
50
|
+
allow_origins=origins,
|
|
51
|
+
allow_methods=["*"],
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
@app.get("/__health")
|
|
56
|
+
def health_check():
|
|
57
|
+
return {"message": "All is well"}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@app.exception_handler(StarletteHTTPException)
|
|
61
|
+
async def global_exception_handler(request: Request, exc: StarletteHTTPException):
|
|
62
|
+
"""
|
|
63
|
+
Global exception handler function that handles any exception raised in the FastAPI application.
|
|
64
|
+
Recommended approach is to register exception handler for Starlette's HTTPException and
|
|
65
|
+
reuse the default exception handlers from fastapi.exception_handlers.
|
|
66
|
+
References:
|
|
67
|
+
https://fastapi.tiangolo.com/tutorial/handling-errors/#fastapis-httpexception-vs-starlettes-httpexception
|
|
68
|
+
https://fastapi.tiangolo.com/tutorial/handling-errors/#reuse-fastapis-exception-handlers
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
request: The request object containing information about the incoming request.
|
|
72
|
+
exc: The exception object that was raised.
|
|
73
|
+
|
|
74
|
+
Raises:
|
|
75
|
+
HTTPException: With a status code of 500 and a message indicating an internal server error.
|
|
76
|
+
"""
|
|
77
|
+
if isinstance(exc, StarletteHTTPException):
|
|
78
|
+
if exc.status_code == 500:
|
|
79
|
+
logging.error(repr(exc))
|
|
80
|
+
raise HTTPException(status_code=exc.status_code, detail="Internal Server Error") # pragma: no cover
|
|
81
|
+
else:
|
|
82
|
+
return await http_exception_handler(request, exc)
|
|
83
|
+
else:
|
|
84
|
+
logging.error(repr(exc))
|
|
85
|
+
raise HTTPException(status_code=500, detail="Internal Server Error")
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
if __name__ == "__main__":
|
|
89
|
+
uvicorn.run(
|
|
90
|
+
app,
|
|
91
|
+
host="0.0.0.0",
|
|
92
|
+
port=8880,
|
|
93
|
+
log_level=logging_level.lower(),
|
|
94
|
+
log_config=LOGGING_CONFIG,
|
|
95
|
+
)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import ptvsd
|
|
2
|
+
import uvicorn
|
|
3
|
+
|
|
4
|
+
from rustic_ai.api_server.logging import LOGGING_CONFIG
|
|
5
|
+
|
|
6
|
+
from .main import app, logging_level
|
|
7
|
+
|
|
8
|
+
if __name__ == "__main__":
|
|
9
|
+
ptvsd.enable_attach(address=("0.0.0.0", 5678))
|
|
10
|
+
ptvsd.wait_for_attach()
|
|
11
|
+
uvicorn.run(
|
|
12
|
+
app,
|
|
13
|
+
host="0.0.0.0",
|
|
14
|
+
port=8880,
|
|
15
|
+
log_level=logging_level.lower(),
|
|
16
|
+
log_config=LOGGING_CONFIG,
|
|
17
|
+
)
|
|
@@ -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,21 @@
|
|
|
1
|
+
rustic_ai/api_server/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
rustic_ai/api_server/api_dependency_manager.py,sha256=0G6D1ufz8ghAh87St-ItVaOK-TVbp3hutMVR2RLZAEw,4013
|
|
3
|
+
rustic_ai/api_server/catalog/__init__.py,sha256=lUeHm889wHOuVGZnn0E2kFJZtIt4xECLjWEe-RByDhg,121
|
|
4
|
+
rustic_ai/api_server/catalog/catalog_store.py,sha256=XTukvjWZ6YTcHOEjwN5l1eYaXXjtCIILpZ_N77enmbo,28682
|
|
5
|
+
rustic_ai/api_server/catalog/models.py,sha256=ed9lHTdKc0f9Kp9dEakC9JUr-jFK2pNwdXM5cy9iVpE,11014
|
|
6
|
+
rustic_ai/api_server/catalog/router.py,sha256=ea6gqWqFGgCsfn_rykavXUVyGnfWRaGK6CKtitfMrcE,15038
|
|
7
|
+
rustic_ai/api_server/guilds/__init__.py,sha256=UGlBXhy9z8qoa-7RCZ8Ii52y4JL8l7_EM6jWIhdKyD8,86
|
|
8
|
+
rustic_ai/api_server/guilds/comms_manager.py,sha256=jTPgt6_Uw1r2aKrBTB7Fs7Ocf1-ptLPi0zPbfvg9D8A,10877
|
|
9
|
+
rustic_ai/api_server/guilds/router.py,sha256=XYDvmGmMT0rP82twevMIzxVbxA1DANAU1dYBd4iBS_8,15188
|
|
10
|
+
rustic_ai/api_server/guilds/schema.py,sha256=--VvzZ3Ur8iIkvzzg04FvabFD669sy4u6LEQ_qd5-yA,70
|
|
11
|
+
rustic_ai/api_server/guilds/service.py,sha256=ib6lqQ2DGX0ZDfmhQv981nZ9ooVsv0aSEXTVIlw5XRo,857
|
|
12
|
+
rustic_ai/api_server/guilds/socket.py,sha256=ImAfNa9yqXRIUSbylIX3M0VsXZXfu9CoZJ9g35BMopQ,1917
|
|
13
|
+
rustic_ai/api_server/guilds/system_comms_manager.py,sha256=m7wl_AxqNeZcg1Qw5Doq_4ehhM6THuNgFkW8zE-Ehok,9396
|
|
14
|
+
rustic_ai/api_server/logging/__init__.py,sha256=ooxkg9XLkd5JC2pPMXnTf2Arf-fSauV048V31h6ClLI,126
|
|
15
|
+
rustic_ai/api_server/logging/config.py,sha256=q0qw1OmZTKzgjYbRnTXZX7XwzZdiLKyVOu22jrXp53c,954
|
|
16
|
+
rustic_ai/api_server/logging/format.py,sha256=X-EGoFR8qlzk7d2Ag5dtapMi95RAgquVg8hvoRHqNrA,739
|
|
17
|
+
rustic_ai/api_server/main.py,sha256=rna-IFNjRYJC40r76f6-GmkD6RZ4RWzzdQVO6qlqmeA,3135
|
|
18
|
+
rustic_ai/api_server/main_debug.py,sha256=ZtnGkqs3ZML7rk2v-Sj_xCoBqGhiPuIHVlgMvkN-vFw,385
|
|
19
|
+
rusticai_api-0.0.1.dist-info/METADATA,sha256=UfKvczEb2W5Jh-6mzkxyuQXvFWyOt3C8D5V1qKANnL8,2953
|
|
20
|
+
rusticai_api-0.0.1.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
21
|
+
rusticai_api-0.0.1.dist-info/RECORD,,
|