42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""RPC 端点: ip_sound_column.ping
|
|||
|
|
|
||
|
|
模型由 gen_models 生成(编辑 config/workers/ip_sound_column/ping.toml 后重新生成)。
|
||
|
|
"""
|
||
|
|
import httpx
|
||
|
|
|
||
|
|
from chongming_worker.decorators import rpc_method
|
||
|
|
|
||
|
|
from ..models.pydantic import TtsPostRequest, TtsPostResponse
|
||
|
|
from ..global_var import require
|
||
|
|
|
||
|
|
|
||
|
|
@rpc_method(
|
||
|
|
subject="ip_sound_column.tts",
|
||
|
|
method="POST",
|
||
|
|
summary="tts 操作",
|
||
|
|
response_model=TtsPostResponse,
|
||
|
|
)
|
||
|
|
async def tts(request: TtsPostRequest) -> TtsPostResponse:
|
||
|
|
"""业务逻辑实现。"""
|
||
|
|
|
||
|
|
ip_addr: str = require("ip")
|
||
|
|
if ip_addr == "unknown":
|
||
|
|
raise RuntimeError("ip_sound_column: 未初始化 ip 地址,请检查配置")
|
||
|
|
|
||
|
|
tts_url = f"http://{ip_addr}/v1/api"
|
||
|
|
try:
|
||
|
|
async with httpx.AsyncClient() as client:
|
||
|
|
resp = await client.post(
|
||
|
|
tts_url,
|
||
|
|
json=request.model_dump(),
|
||
|
|
headers={"Content-Type": "application/json"},
|
||
|
|
)
|
||
|
|
if resp.is_success:
|
||
|
|
return TtsPostResponse(**resp.json())
|
||
|
|
else:
|
||
|
|
raise RuntimeError(
|
||
|
|
f"ip_sound_column: tts 请求失败,状态码 {resp.status_code},响应内容: {resp.text}"
|
||
|
|
)
|
||
|
|
except httpx.RequestError as e:
|
||
|
|
raise RuntimeError(f"ip_sound_column: tts 请求异常: {str(e)}") from e
|