2026-04-14 10:08:41 +08:00

77 lines
3.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
配置管理 - 集中管理所有配置项
"""
from pydantic_settings import BaseSettings
from pydantic import Field
from typing import Optional
from pathlib import Path
class Settings(BaseSettings):
"""应用配置 - 所有配置项通过环境变量或 .env 文件设置"""
# ==================== WebSocket 服务器 ====================
WS_HOST: str = "0.0.0.0"
WS_PORT: int = 8765
WS_PATH: str = "/v1/voice/session"
# ==================== 鉴权 ====================
BEARER_TOKEN: str = "drone-voice-cloud-token-2024"
# ==================== 阿里云百炼 LLM ====================
DASHSCOPE_API_KEY: str = "sk-8ac47bb8a1f7497a922c52d905dd11dc"
# 与 LLM 共用 API Key实时语音识别 Fun-ASR 走 WebSocket inference
DASHSCOPE_WEBSOCKET_URL: str = (
"wss://dashscope.aliyuncs.com/api-ws/v1/inference"
)
DASHSCOPE_ASR_MODEL: str = "fun-asr-realtime"
ASR_AUDIO_SAMPLE_RATE: int = 16000
ASR_SEMANTIC_PUNCTUATION_ENABLED: bool = True
LLM_PROVIDER: str = "dashscope" # 服务提供者: dashscope | local (后续扩展)
LLM_MODEL: str = "qwen-plus" # qwen-turbo | qwen-plus | qwen-max
LLM_MAX_TOKENS: int = 512
LLM_TEMPERATURE: float = 0.3
LLM_TIMEOUT: int = 30 # 秒
LLM_CONTEXT_TURNS: int = 4 # 保留的历史对话轮数
# Function calling天气 / 联网摘要等DashScope tools + 本地执行)
LLM_TOOLS_ENABLED: bool = True
LLM_AGENT_MAX_STEPS: int = 8 # 每用户轮最多模型↔工具往返次数(含最终回答)
LLM_TOOL_RESULT_MAX_CHARS: int = 8000 # 单次 tool 消息写入上下文上限
# ==================== TTS 配置 ====================
TTS_PROVIDER: str = "piper" # piper | azure | local (后续扩展)
TTS_MODEL_DIR: str = "models" # Piper 模型目录
TTS_VOICE_NAME: str = "zh_CN-huayan-medium" # Piper 语音名称
TTS_SAMPLE_RATE: int = 24000 # 协议规定 24kHz
TTS_MAX_CHARS: int = 800 # TTS 最大字符数(超长截断)
# 闲聊流式 TTS更早切出首段降低首字节延迟见 intent_service.take_next_speech_segment
TTS_STREAM_SOFT_FLUSH_LEN: int = 28
TTS_STREAM_EARLY_WEAK_CUT: bool = True
TTS_STREAM_EARLY_WEAK_MIN_SEGMENT: int = 6
TTS_STREAM_EARLY_WEAK_SCAN_CAP: int = 48
# ==================== 超时配置 (毫秒) ====================
DIALOG_RESULT_TIMEOUT_MS: int = 30000 # LLM 推理超时
TTS_FIRST_BYTE_TIMEOUT_MS: int = 10000 # TTS 首字节超时
# ==================== 飞控二次确认dialog_result v1 之 confirm====================
FLIGHT_CONFIRM_REQUIRED: bool = True
FLIGHT_CONFIRM_TIMEOUT_SEC: float = 10.0
# ==================== 限流 ====================
MAX_CONCURRENT_SESSIONS: int = 4 # 最大并发 session 数
# ==================== 日志 ====================
LOG_LEVEL: str = "INFO"
LOG_TO_FILE: bool = False
LOG_FILE: str = "logs/server.log"
class Config:
env_file = ".env"
env_file_encoding = "utf-8"
case_sensitive = True
# 全局配置实例
settings = Settings()