rtc-voice-chat/backend/routes/scenes.py

75 lines
2.2 KiB
Python

"""
POST /getScenes — 场景列表
"""
from fastapi import APIRouter
from fastapi.responses import JSONResponse
from services.scene_service import Scenes, prepare_scene_runtime
router = APIRouter()
@router.post("/getScenes")
async def get_scenes():
try:
scenes_list = []
for scene_name, data in Scenes.items():
scene_config, rtc_config, voice_chat = prepare_scene_runtime(
scene_name, data
)
scene_config["id"] = scene_name
scene_config["botName"] = voice_chat.get("AgentConfig", {}).get("UserId")
scene_config["isInterruptMode"] = (
voice_chat.get("Config", {}).get("InterruptMode") == 0
)
scene_config["isVision"] = (
voice_chat.get("Config", {})
.get("LLMConfig", {})
.get("VisionConfig", {})
.get("Enable")
)
scene_config["isScreenMode"] = (
voice_chat.get("Config", {})
.get("LLMConfig", {})
.get("VisionConfig", {})
.get("SnapshotConfig", {})
.get("StreamType")
== 1
)
scene_config["isAvatarScene"] = (
voice_chat.get("Config", {}).get("AvatarConfig", {}).get("Enabled")
)
scene_config["avatarBgUrl"] = (
voice_chat.get("Config", {})
.get("AvatarConfig", {})
.get("BackgroundUrl")
)
rtc_out = {k: v for k, v in rtc_config.items() if k != "AppKey"}
scenes_list.append(
{
"scene": scene_config,
"rtc": rtc_out,
}
)
return JSONResponse(
{
"ResponseMetadata": {"Action": "getScenes"},
"Result": {"scenes": scenes_list},
}
)
except ValueError as e:
return JSONResponse(
{
"ResponseMetadata": {
"Action": "getScenes",
"Error": {"Code": -1, "Message": str(e)},
}
}
)