mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-27 04:49:47 +01:00
- Defaults and config aligned with English-first product surface - Adds/removes ASR/TTS paths; drops China-only provider implementations and bundled SenseVoice assets - Westernizes prompts, plugin/tool copy, connection and handler behavior on upstream fixes - Powermem max_tokens and OpenAI no-thinking guard preserved on downstream path
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
import datetime
|
|
from typing import Dict, Tuple
|
|
|
|
# Global dictionary to store daily output character count for each device
|
|
_device_daily_output: Dict[Tuple[str, datetime.date], int] = {}
|
|
# Record the last check date
|
|
_last_check_date: datetime.date = None
|
|
|
|
|
|
def reset_device_output():
|
|
"""
|
|
Reset daily output character count for all devices
|
|
Call this function at 0:00 every day
|
|
"""
|
|
_device_daily_output.clear()
|
|
|
|
|
|
def get_device_output(device_id: str) -> int:
|
|
"""
|
|
Get device's daily output character count
|
|
"""
|
|
current_date = datetime.datetime.now().date()
|
|
return _device_daily_output.get((device_id, current_date), 0)
|
|
|
|
|
|
def add_device_output(device_id: str, char_count: int):
|
|
"""
|
|
Add to device's output character count
|
|
"""
|
|
current_date = datetime.datetime.now().date()
|
|
global _last_check_date
|
|
|
|
# If first call or date changed, clear counter
|
|
if _last_check_date is None or _last_check_date != current_date:
|
|
_device_daily_output.clear()
|
|
_last_check_date = current_date
|
|
|
|
current_count = _device_daily_output.get((device_id, current_date), 0)
|
|
_device_daily_output[(device_id, current_date)] = current_count + char_count
|
|
|
|
|
|
def check_device_output_limit(device_id: str, max_output_size: int) -> bool:
|
|
"""
|
|
Check if device exceeds output limit
|
|
:return: True if exceeds limit, False if not exceeded
|
|
"""
|
|
if not device_id:
|
|
return False
|
|
current_output = get_device_output(device_id)
|
|
return current_output >= max_output_size
|