73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
import asyncio
|
|
import ray
|
|
|
|
from pretor.utils.banner import print_banner
|
|
from pretor.core.database.postgres import PostgresDatabase
|
|
from pretor.core.global_state_machine.global_state_machine import GlobalStateMachine
|
|
from pretor.core.individual.supervisory_node.supervisory_node import SupervisoryNode
|
|
from pretor.core.individual.consciousness_node.consciousness_node import ConsciousnessNode
|
|
from pretor.core.individual.control_node.control_node import ControlNode
|
|
from pretor.core.workflow.workflow_runner import WorkflowRunningEngine
|
|
from pretor.core.api import PretorGateway
|
|
from ray import serve
|
|
import os
|
|
|
|
|
|
|
|
async def start_system():
|
|
env_vars = {
|
|
"POSTGRES_USER": os.getenv("POSTGRES_USER", "postgres"),
|
|
"POSTGRES_PASSWORD": os.getenv("POSTGRES_PASSWORD", ""),
|
|
"POSTGRES_HOST": os.getenv("POSTGRES_HOST", "db"),
|
|
"POSTGRES_PORT": os.getenv("POSTGRES_PORT", "5432"),
|
|
"POSTGRES_DB": os.getenv("POSTGRES_DB", "postgres"),
|
|
"SECRET_KEY": os.getenv("SECRET_KEY", "secret"),
|
|
}
|
|
|
|
ray.init(ignore_reinit_error=True,
|
|
namespace="pretor",
|
|
dashboard_host="0.0.0.0",
|
|
dashboard_port=8265,
|
|
runtime_env={"env_vars": env_vars})
|
|
|
|
|
|
# 2. 启动数据库组件
|
|
postgres_database = PostgresDatabase.options(name='postgres_database').remote()
|
|
await postgres_database.init_db.remote()
|
|
|
|
# 3. 启动全局状态机
|
|
GlobalStateMachine.options(name='global_state_machine').remote(postgres_database)
|
|
|
|
# 4. 启动核心节点
|
|
supervisory_node = SupervisoryNode.options(name='supervisory_node').remote()
|
|
consciousness_node = ConsciousnessNode.options(name='consciousness_node').remote()
|
|
control_node = ControlNode.options(name='control_node').remote()
|
|
|
|
# 5. 启动工作流运行引擎
|
|
workflow_engine = WorkflowRunningEngine.options(name='workflow_running_engine').remote(
|
|
consciousness_node=consciousness_node,
|
|
control_node=control_node,
|
|
supervisory_node=supervisory_node
|
|
)
|
|
# 异步拉起 runner 协程群
|
|
workflow_engine.run.remote()
|
|
|
|
# 6. 启动 FastAPI 网关 (使用 Ray Serve)
|
|
serve.start(http_options={"host": "0.0.0.0", "port": 8000})
|
|
serve.run(PretorGateway.bind())
|
|
|
|
# 挂起主线程以保持系统运行
|
|
while True:
|
|
await asyncio.sleep(3600)
|
|
|
|
|
|
def main():
|
|
print_banner()
|
|
try:
|
|
asyncio.run(start_system())
|
|
except KeyboardInterrupt:
|
|
print("系统已退出。")
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |