fix: bind HTTP API to localhost by default and expose --host
This commit is contained in:
@@ -301,7 +301,7 @@ def metrics_dashboard():
|
||||
}), 500
|
||||
|
||||
|
||||
def start_http_server(host='0.0.0.0', port=6060, debug=False):
|
||||
def start_http_server(host='127.0.0.1', port=6060, debug=False):
|
||||
"""启动 HTTP 服务器"""
|
||||
global task_manager, task_scheduler
|
||||
|
||||
@@ -330,4 +330,4 @@ if __name__ == '__main__':
|
||||
format='[%(asctime)s] %(levelname)s: %(message)s'
|
||||
)
|
||||
|
||||
start_http_server(port=6060, debug=True)
|
||||
start_http_server(host='127.0.0.1', port=6060, debug=True)
|
||||
|
||||
30
run.py
30
run.py
@@ -30,10 +30,11 @@ logging.basicConfig(
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_HTTP_PORT = 6060
|
||||
DEFAULT_HTTP_HOST = "127.0.0.1"
|
||||
|
||||
|
||||
def _print_api_info(port: int):
|
||||
logger.info(f"HTTP API 服务器已启动:http://0.0.0.0:{port}")
|
||||
def _print_api_info(host: str, port: int):
|
||||
logger.info(f"HTTP API 服务器已启动:http://{host}:{port}")
|
||||
logger.info("")
|
||||
logger.info("天网任务接口:")
|
||||
logger.info(" POST /api/task/receive - 接收任务")
|
||||
@@ -60,7 +61,7 @@ def run_websocket(enable_agent: bool):
|
||||
logger.info("已停止")
|
||||
|
||||
|
||||
def run_tianwang(enable_agent: bool, port: int):
|
||||
def run_tianwang(enable_agent: bool, host: str, port: int):
|
||||
"""完整版: HTTP API + WebSocket + AI Agent"""
|
||||
import asyncio
|
||||
from api.http_server import start_http_server
|
||||
@@ -70,8 +71,8 @@ def run_tianwang(enable_agent: bool, port: int):
|
||||
logger.info("AI 客服系统 - 天网协作版(完整)")
|
||||
logger.info("=" * 60)
|
||||
|
||||
start_http_server(host='0.0.0.0', port=port)
|
||||
_print_api_info(port)
|
||||
start_http_server(host=host, port=port)
|
||||
_print_api_info(host, port)
|
||||
logger.info("=" * 60)
|
||||
|
||||
logger.info("正在连接轻简 API...")
|
||||
@@ -98,7 +99,7 @@ def run_tianwang(enable_agent: bool, port: int):
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def run_api_only(port: int):
|
||||
def run_api_only(host: str, port: int):
|
||||
"""仅 HTTP API(不含 WebSocket / AI Agent)"""
|
||||
import time
|
||||
from api.http_server import start_http_server
|
||||
@@ -107,8 +108,8 @@ def run_api_only(port: int):
|
||||
logger.info("AI 客服系统 - 天网协作版(仅 API)")
|
||||
logger.info("=" * 60)
|
||||
|
||||
start_http_server(host='0.0.0.0', port=port)
|
||||
_print_api_info(port)
|
||||
start_http_server(host=host, port=port)
|
||||
_print_api_info(host, port)
|
||||
logger.info("=" * 60)
|
||||
logger.info("系统已就绪,等待天网任务...")
|
||||
|
||||
@@ -143,7 +144,7 @@ def run_multi_process(num_workers: int, enable_agent: bool):
|
||||
logger.info("已停止")
|
||||
coordinator.stop()
|
||||
|
||||
def run_tianwang_multi(num_workers: int, enable_agent: bool, port: int):
|
||||
def run_tianwang_multi(num_workers: int, enable_agent: bool, host: str, port: int):
|
||||
"""天网 + 多进程:HTTP API + 多进程 WebSocket 客户端"""
|
||||
from api.http_server import start_http_server
|
||||
from scripts.multi_process_launcher import Coordinator
|
||||
@@ -152,8 +153,8 @@ def run_tianwang_multi(num_workers: int, enable_agent: bool, port: int):
|
||||
logger.info("AI 客服系统 - 天网协作版(HTTP API) + 多进程模式")
|
||||
logger.info("=" * 60)
|
||||
|
||||
start_http_server(host='0.0.0.0', port=port)
|
||||
_print_api_info(port)
|
||||
start_http_server(host=host, port=port)
|
||||
_print_api_info(host, port)
|
||||
logger.info("=" * 60)
|
||||
|
||||
logger.info(f"工作进程数:{num_workers}")
|
||||
@@ -197,6 +198,7 @@ def main():
|
||||
mode.add_argument('--multi', action='store_true', help='多进程模式')
|
||||
|
||||
parser.add_argument('--no-agent', action='store_true', help='不启用 AI Agent')
|
||||
parser.add_argument('--host', type=str, default=DEFAULT_HTTP_HOST, help=f'HTTP API 监听地址(默认 {DEFAULT_HTTP_HOST})')
|
||||
parser.add_argument('--port', '-p', type=int, default=DEFAULT_HTTP_PORT, help=f'HTTP API 端口(默认 {DEFAULT_HTTP_PORT})')
|
||||
parser.add_argument('--workers', '-w', type=int, default=None, help='工作进程数(仅多进程模式,默认 CPU 核心数)')
|
||||
|
||||
@@ -204,11 +206,11 @@ def main():
|
||||
enable_agent = not args.no_agent
|
||||
|
||||
if args.api_only:
|
||||
run_api_only(port=args.port)
|
||||
run_api_only(host=args.host, port=args.port)
|
||||
elif args.tianwang:
|
||||
run_tianwang(enable_agent=enable_agent, port=args.port)
|
||||
run_tianwang(enable_agent=enable_agent, host=args.host, port=args.port)
|
||||
elif args.tianwang_multi:
|
||||
run_tianwang_multi(num_workers=args.workers, enable_agent=enable_agent, port=args.port)
|
||||
run_tianwang_multi(num_workers=args.workers, enable_agent=enable_agent, host=args.host, port=args.port)
|
||||
elif args.multi:
|
||||
run_multi_process(num_workers=args.workers, enable_agent=enable_agent)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user