modify: aibox_sophon_adapter plugins

This commit is contained in:
2026-07-27 14:28:07 +08:00
parent 2b7b8ee08c
commit 79eb7fe5cc
23 changed files with 1380 additions and 61 deletions
+4
View File
@@ -1,4 +1,6 @@
from .add import add, add_post
from .add_mqtt import add_mqtt
from .heartbeat import heartbeat
from .subtract import subtract
from .multiply import multiply
from .divide import divide
@@ -8,6 +10,8 @@ from .count import count_get
__all__ = [
"add",
"add_post",
"add_mqtt",
"heartbeat",
"subtract",
"multiply",
"divide",
+24
View File
@@ -0,0 +1,24 @@
"""
MQTT 端点处理器 — 通过 MQTT 主题 chongming/example/add 调用
与 GET/POST 的 add 共用同一个 subject (example.add),
通过 _method="MQTT" 区分。
"""
import time
from chongming_worker import rpc_method
from ..models.pydantic import AddMqttRequest
@rpc_method(
subject="example.add",
method="MQTT",
summary="Add two numbers via MQTT",
)
async def add_mqtt(request: AddMqttRequest) -> dict:
"""MQTT 加法 — 通过 MQTT 主题 chongming/example/add 调用,返回 dict"""
return {
"result": request.a + request.b,
"operation": "add_mqtt",
"timestamp": time.time(),
}
+20
View File
@@ -0,0 +1,20 @@
"""
心跳 MQTT 端点 — 仅上报,无需响应
通过 MQTT 主题 chongming/example/heartbeat 发送心跳,
Worker 返回 None,MQTT Bridge 不发布响应。
"""
import time
from chongming_worker import rpc_method
@rpc_method(
subject="example.heartbeat",
method="MQTT",
summary="Heartbeat ping via MQTT (no response)",
)
async def heartbeat(worker_id: str = "") -> None:
"""心跳上报 — 无返回值,MQTT Bridge 跳过响应发布"""
print(f"[Heartbeat] worker={worker_id} time={time.time()}")
return None # 显式返回 None,MQTT Bridge 不发布响应