api channel and tools
This commit is contained in:
parent
9222c59f03
commit
3816a9627e
4 changed files with 684 additions and 582 deletions
21
app.py
21
app.py
|
|
@ -5,7 +5,7 @@ from pathlib import Path
|
|||
from typing import Any, Awaitable, Callable
|
||||
|
||||
from fastapi import FastAPI, WebSocket, WebSocketDisconnect
|
||||
from fastapi.responses import FileResponse, JSONResponse
|
||||
from fastapi.responses import FileResponse, HTMLResponse, JSONResponse
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from supertonic_gateway import SuperTonicGateway
|
||||
|
|
@ -28,8 +28,9 @@ async def health() -> JSONResponse:
|
|||
|
||||
|
||||
@app.get("/")
|
||||
async def index() -> FileResponse:
|
||||
return FileResponse(INDEX_PATH)
|
||||
async def index() -> HTMLResponse:
|
||||
html = INDEX_PATH.read_text(encoding="utf-8")
|
||||
return HTMLResponse(content=html)
|
||||
|
||||
|
||||
@app.websocket("/ws/chat")
|
||||
|
|
@ -65,18 +66,24 @@ async def websocket_chat(websocket: WebSocket) -> None:
|
|||
elif msg_type == "rtc-ice-candidate":
|
||||
await voice_session.handle_ice_candidate(message)
|
||||
elif msg_type == "voice-ptt":
|
||||
voice_session.set_push_to_talk_pressed(
|
||||
bool(message.get("pressed", False))
|
||||
)
|
||||
voice_session.set_push_to_talk_pressed(bool(message.get("pressed", False)))
|
||||
elif msg_type == "user-message":
|
||||
await gateway.send_user_message(str(message.get("text", "")))
|
||||
elif msg_type == "ui-response":
|
||||
await gateway.send_ui_response(
|
||||
str(message.get("request_id", "")),
|
||||
str(message.get("value", "")),
|
||||
)
|
||||
elif msg_type == "command":
|
||||
await gateway.send_command(str(message.get("command", "")))
|
||||
else:
|
||||
await safe_send_json(
|
||||
{
|
||||
"role": "system",
|
||||
"text": (
|
||||
"Unknown message type. Use spawn, stop, rtc-offer, "
|
||||
"rtc-ice-candidate, voice-ptt, or user-message."
|
||||
"rtc-ice-candidate, voice-ptt, user-message, "
|
||||
"ui-response, or command."
|
||||
),
|
||||
"timestamp": "",
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue