feat: 添加一键启动脚本并更新项目配置

- 添加 start_all.sh 一键启动脚本,支持启动llama-server和FastAPI服务
- 修改启动脚本使用venv虚拟环境替代conda环境
- 更新README.md,添加一键启动脚本使用说明
- 更新py_tree_generator.py,添加final_prompt返回字段
- 禁用Qwen3模型的思考功能
- 添加RAG检索结果的终端打印
- 移除ROS2相关代码(ros2_client.py已删除)
This commit is contained in:
2025-12-02 21:42:26 +08:00
parent ab6e09423b
commit a6c2027caa
9 changed files with 625 additions and 822 deletions

View File

@@ -3,13 +3,13 @@ import os
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
from fastapi.staticfiles import StaticFiles
import logging
import threading
import rclpy
# import threading # ROS2相关已注释
# import rclpy # ROS2相关已注释
from .models import GeneratePlanRequest, ExecuteMissionRequest
from .websocket_manager import websocket_manager
from .py_tree_generator import py_tree_generator
from .ros2_client import MissionActionClient
# from .ros2_client import MissionActionClient # ROS2相关已注释
# --- Application Setup ---
app = FastAPI(
@@ -23,14 +23,15 @@ static_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'gene
app.mount("/static", StaticFiles(directory=static_dir), name="static")
# --- ROS2 Node and Client Initialization ---
rclpy.init()
ros2_client = MissionActionClient()
# ROS2相关代码已注释项目已与ROS2解耦
# rclpy.init()
# ros2_client = MissionActionClient()
def run_ros2_node():
"""Spins the ROS2 node in a dedicated thread."""
logging.info("Starting to spin ROS2 node...")
rclpy.spin(ros2_client)
logging.info("ROS2 node has stopped spinning.")
# def run_ros2_node():
# """Spins the ROS2 node in a dedicated thread."""
# logging.info("Starting to spin ROS2 node...")
# rclpy.spin(ros2_client)
# logging.info("ROS2 node has stopped spinning.")
# --- API Endpoints ---
@@ -49,9 +50,12 @@ async def generate_plan_endpoint(request: GeneratePlanRequest):
async def execute_mission_endpoint(request: ExecuteMissionRequest):
"""
Receives a `py_tree.json` and sends it to the drone for execution.
ROS2相关功能已注释项目已与ROS2解耦。
"""
ros2_client.send_goal(request.py_tree)
return {"status": "execution_started"}
# ROS2相关代码已注释
# ros2_client.send_goal(request.py_tree)
logging.warning("execute_mission endpoint called but ROS2 is disabled. Mission execution is not available.")
return {"status": "execution_disabled", "message": "ROS2 integration is disabled. Mission execution is not available."}
@app.websocket("/ws/status")
async def websocket_endpoint(websocket: WebSocket):
@@ -73,21 +77,23 @@ async def websocket_endpoint(websocket: WebSocket):
async def startup_event():
"""
On startup, get the current asyncio event loop and pass it to the websocket manager.
Also, start the ROS2 node in a background thread.
ROS2相关功能已注释项目已与ROS2解耦。
"""
# Configure WebSocket Manager
loop = asyncio.get_running_loop()
websocket_manager.set_loop(loop)
logging.info("WebSocket event loop configured.")
# ROS2相关代码已注释
# Start ROS2 node in a background thread
ros2_thread = threading.Thread(target=run_ros2_node, daemon=True)
ros2_thread.start()
logging.info("ROS2 node thread started.")
# ros2_thread = threading.Thread(target=run_ros2_node, daemon=True)
# ros2_thread.start()
# logging.info("ROS2 node thread started.")
@app.on_event("shutdown")
async def shutdown_event():
logging.info("Backend service shutting down.")
ros2_client.destroy_node()
rclpy.shutdown()
logging.info("ROS2 node shut down successfully.")
# ROS2相关代码已注释
# ros2_client.destroy_node()
# rclpy.shutdown()
# logging.info("ROS2 node shut down successfully.")