58 lines
1.8 KiB
Python
58 lines
1.8 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
|
|
|
|
|
|
async def start_system():
|
|
# 1. 初始化 Ray
|
|
ray.init(ignore_reinit_error=True)
|
|
|
|
# 2. 启动数据库组件
|
|
postgres_database = PostgresDatabase.remote()
|
|
await postgres_database.init_db.remote()
|
|
|
|
# 3. 启动全局状态机
|
|
global_state_machine = GlobalStateMachine.remote(postgres_database)
|
|
|
|
# 4. 启动核心节点
|
|
supervisory_node = SupervisoryNode.remote()
|
|
consciousness_node = ConsciousnessNode.remote()
|
|
control_node = ControlNode.remote()
|
|
|
|
# 5. 启动工作流运行引擎
|
|
workflow_engine = WorkflowRunningEngine.remote(
|
|
consciousness_node=consciousness_node,
|
|
control_node=control_node,
|
|
supervisory_node=supervisory_node
|
|
)
|
|
# 异步拉起 runner 协程群
|
|
workflow_engine.run.remote()
|
|
|
|
# 6. 启动 FastAPI 网关
|
|
pretor_gateway = PretorGateway.remote(
|
|
postgres_database=postgres_database,
|
|
global_state_machine=global_state_machine,
|
|
supervisory_node=supervisory_node,
|
|
consciousness_node = consciousness_node,
|
|
control_node = control_node
|
|
)
|
|
|
|
# 挂起在网关服务上,暴露 8000 端口
|
|
await pretor_gateway.server_run.remote(host="0.0.0.0", port=8000)
|
|
|
|
|
|
def main():
|
|
print_banner()
|
|
asyncio.run(start_system())
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |