🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -3,6 +3,7 @@ import psutil
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
def get_system_info():
|
def get_system_info():
|
||||||
"""获取操作系统信息"""
|
"""获取操作系统信息"""
|
||||||
return {
|
return {
|
||||||
@@ -13,19 +14,23 @@ def get_system_info():
|
|||||||
"processor": platform.processor(),
|
"processor": platform.processor(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_python_version():
|
def get_python_version():
|
||||||
"""获取 Python 版本信息"""
|
"""获取 Python 版本信息"""
|
||||||
return sys.version
|
return sys.version
|
||||||
|
|
||||||
|
|
||||||
def get_cpu_usage():
|
def get_cpu_usage():
|
||||||
"""获取系统总CPU使用率"""
|
"""获取系统总CPU使用率"""
|
||||||
return psutil.cpu_percent(interval=1)
|
return psutil.cpu_percent(interval=1)
|
||||||
|
|
||||||
|
|
||||||
def get_process_cpu_usage():
|
def get_process_cpu_usage():
|
||||||
"""获取当前进程CPU使用率"""
|
"""获取当前进程CPU使用率"""
|
||||||
process = psutil.Process(os.getpid())
|
process = psutil.Process(os.getpid())
|
||||||
return process.cpu_percent(interval=1)
|
return process.cpu_percent(interval=1)
|
||||||
|
|
||||||
|
|
||||||
def get_memory_usage():
|
def get_memory_usage():
|
||||||
"""获取系统内存使用情况 (单位 MB)"""
|
"""获取系统内存使用情况 (单位 MB)"""
|
||||||
mem = psutil.virtual_memory()
|
mem = psutil.virtual_memory()
|
||||||
@@ -38,6 +43,7 @@ def get_memory_usage():
|
|||||||
"free_mb": bytes_to_mb(mem.free),
|
"free_mb": bytes_to_mb(mem.free),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_process_memory_usage():
|
def get_process_memory_usage():
|
||||||
"""获取当前进程内存使用情况 (单位 MB)"""
|
"""获取当前进程内存使用情况 (单位 MB)"""
|
||||||
process = psutil.Process(os.getpid())
|
process = psutil.Process(os.getpid())
|
||||||
@@ -46,9 +52,10 @@ def get_process_memory_usage():
|
|||||||
return {
|
return {
|
||||||
"rss_mb": bytes_to_mb(mem_info.rss), # Resident Set Size: 实际使用物理内存
|
"rss_mb": bytes_to_mb(mem_info.rss), # Resident Set Size: 实际使用物理内存
|
||||||
"vms_mb": bytes_to_mb(mem_info.vms), # Virtual Memory Size: 虚拟内存大小
|
"vms_mb": bytes_to_mb(mem_info.vms), # Virtual Memory Size: 虚拟内存大小
|
||||||
"percent": process.memory_percent() # 进程内存使用百分比
|
"percent": process.memory_percent(), # 进程内存使用百分比
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_disk_usage(path="/"):
|
def get_disk_usage(path="/"):
|
||||||
"""获取指定路径磁盘使用情况 (单位 GB)"""
|
"""获取指定路径磁盘使用情况 (单位 GB)"""
|
||||||
disk = psutil.disk_usage(path)
|
disk = psutil.disk_usage(path)
|
||||||
@@ -60,6 +67,7 @@ def get_disk_usage(path="/"):
|
|||||||
"percent": disk.percent,
|
"percent": disk.percent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_all_basic_info():
|
def get_all_basic_info():
|
||||||
"""获取所有基本信息并封装返回"""
|
"""获取所有基本信息并封装返回"""
|
||||||
# 对于进程CPU使用率,需要先初始化
|
# 对于进程CPU使用率,需要先初始化
|
||||||
@@ -77,6 +85,7 @@ def get_all_basic_info():
|
|||||||
"disk_usage_root": get_disk_usage("/"),
|
"disk_usage_root": get_disk_usage("/"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_all_basic_info_string() -> str:
|
def get_all_basic_info_string() -> str:
|
||||||
"""获取所有基本信息并以带解释的字符串形式返回"""
|
"""获取所有基本信息并以带解释的字符串形式返回"""
|
||||||
info = get_all_basic_info()
|
info = get_all_basic_info()
|
||||||
@@ -87,43 +96,44 @@ def get_all_basic_info_string() -> str:
|
|||||||
disk_usage = info["disk_usage_root"]
|
disk_usage = info["disk_usage_root"]
|
||||||
|
|
||||||
# 对进程内存使用百分比进行格式化,保留两位小数
|
# 对进程内存使用百分比进行格式化,保留两位小数
|
||||||
proc_mem_percent = round(proc_mem_usage['percent'], 2)
|
proc_mem_percent = round(proc_mem_usage["percent"], 2)
|
||||||
|
|
||||||
output_string = f"""[系统信息]
|
output_string = f"""[系统信息]
|
||||||
- 操作系统: {sys_info['system']} (例如: Windows, Linux)
|
- 操作系统: {sys_info["system"]} (例如: Windows, Linux)
|
||||||
- 发行版本: {sys_info['release']} (例如: 11, Ubuntu 20.04)
|
- 发行版本: {sys_info["release"]} (例如: 11, Ubuntu 20.04)
|
||||||
- 详细版本: {sys_info['version']}
|
- 详细版本: {sys_info["version"]}
|
||||||
- 硬件架构: {sys_info['machine']} (例如: AMD64)
|
- 硬件架构: {sys_info["machine"]} (例如: AMD64)
|
||||||
- 处理器信息: {sys_info['processor']}
|
- 处理器信息: {sys_info["processor"]}
|
||||||
|
|
||||||
[Python 环境]
|
[Python 环境]
|
||||||
- Python 版本: {info['python_version']}
|
- Python 版本: {info["python_version"]}
|
||||||
|
|
||||||
[CPU 状态]
|
[CPU 状态]
|
||||||
- 系统总 CPU 使用率: {info['cpu_usage_percent']}%
|
- 系统总 CPU 使用率: {info["cpu_usage_percent"]}%
|
||||||
- 当前进程 CPU 使用率: {info['process_cpu_usage_percent']}%
|
- 当前进程 CPU 使用率: {info["process_cpu_usage_percent"]}%
|
||||||
|
|
||||||
[系统内存使用情况]
|
[系统内存使用情况]
|
||||||
- 总物理内存: {mem_usage['total_mb']} MB
|
- 总物理内存: {mem_usage["total_mb"]} MB
|
||||||
- 可用物理内存: {mem_usage['available_mb']} MB
|
- 可用物理内存: {mem_usage["available_mb"]} MB
|
||||||
- 物理内存使用率: {mem_usage['percent']}%
|
- 物理内存使用率: {mem_usage["percent"]}%
|
||||||
- 已用物理内存: {mem_usage['used_mb']} MB
|
- 已用物理内存: {mem_usage["used_mb"]} MB
|
||||||
- 空闲物理内存: {mem_usage['free_mb']} MB
|
- 空闲物理内存: {mem_usage["free_mb"]} MB
|
||||||
|
|
||||||
[当前进程内存使用情况]
|
[当前进程内存使用情况]
|
||||||
- 实际使用物理内存 (RSS): {proc_mem_usage['rss_mb']} MB
|
- 实际使用物理内存 (RSS): {proc_mem_usage["rss_mb"]} MB
|
||||||
- 占用虚拟内存 (VMS): {proc_mem_usage['vms_mb']} MB
|
- 占用虚拟内存 (VMS): {proc_mem_usage["vms_mb"]} MB
|
||||||
- 进程内存使用率: {proc_mem_percent}%
|
- 进程内存使用率: {proc_mem_percent}%
|
||||||
|
|
||||||
[磁盘使用情况 (根目录)]
|
[磁盘使用情况 (根目录)]
|
||||||
- 总空间: {disk_usage['total_gb']} GB
|
- 总空间: {disk_usage["total_gb"]} GB
|
||||||
- 已用空间: {disk_usage['used_gb']} GB
|
- 已用空间: {disk_usage["used_gb"]} GB
|
||||||
- 可用空间: {disk_usage['free_gb']} GB
|
- 可用空间: {disk_usage["free_gb"]} GB
|
||||||
- 磁盘使用率: {disk_usage['percent']}%
|
- 磁盘使用率: {disk_usage["percent"]}%
|
||||||
"""
|
"""
|
||||||
return output_string
|
return output_string
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
print(f"System Info: {get_system_info()}")
|
print(f"System Info: {get_system_info()}")
|
||||||
print(f"Python Version: {get_python_version()}")
|
print(f"Python Version: {get_python_version()}")
|
||||||
print(f"CPU Usage: {get_cpu_usage()}%")
|
print(f"CPU Usage: {get_cpu_usage()}%")
|
||||||
@@ -134,17 +144,24 @@ if __name__ == '__main__':
|
|||||||
print(f"Process CPU Usage: {current_process.cpu_percent(interval=1)}%") # 实际获取
|
print(f"Process CPU Usage: {current_process.cpu_percent(interval=1)}%") # 实际获取
|
||||||
|
|
||||||
memory_usage_info = get_memory_usage()
|
memory_usage_info = get_memory_usage()
|
||||||
print(f"Memory Usage: Total={memory_usage_info['total_mb']}MB, Used={memory_usage_info['used_mb']}MB, Percent={memory_usage_info['percent']}%")
|
print(
|
||||||
|
f"Memory Usage: Total={memory_usage_info['total_mb']}MB, Used={memory_usage_info['used_mb']}MB, Percent={memory_usage_info['percent']}%"
|
||||||
|
)
|
||||||
|
|
||||||
process_memory_info = get_process_memory_usage()
|
process_memory_info = get_process_memory_usage()
|
||||||
print(f"Process Memory Usage: RSS={process_memory_info['rss_mb']}MB, VMS={process_memory_info['vms_mb']}MB, Percent={process_memory_info['percent']}%")
|
print(
|
||||||
|
f"Process Memory Usage: RSS={process_memory_info['rss_mb']}MB, VMS={process_memory_info['vms_mb']}MB, Percent={process_memory_info['percent']}%"
|
||||||
|
)
|
||||||
|
|
||||||
disk_usage_info = get_disk_usage('/')
|
disk_usage_info = get_disk_usage("/")
|
||||||
print(f"Disk Usage (Root): Total={disk_usage_info['total_gb']}GB, Used={disk_usage_info['used_gb']}GB, Percent={disk_usage_info['percent']}%")
|
print(
|
||||||
|
f"Disk Usage (Root): Total={disk_usage_info['total_gb']}GB, Used={disk_usage_info['used_gb']}GB, Percent={disk_usage_info['percent']}%"
|
||||||
|
)
|
||||||
|
|
||||||
print("\n--- All Basic Info (JSON) ---")
|
print("\n--- All Basic Info (JSON) ---")
|
||||||
all_info = get_all_basic_info()
|
all_info = get_all_basic_info()
|
||||||
import json
|
import json
|
||||||
|
|
||||||
print(json.dumps(all_info, indent=4, ensure_ascii=False))
|
print(json.dumps(all_info, indent=4, ensure_ascii=False))
|
||||||
|
|
||||||
print("\n--- All Basic Info (String with Explanations) ---")
|
print("\n--- All Basic Info (String with Explanations) ---")
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
from typing import List, Optional, Dict, Any
|
from typing import List, Optional, Dict, Any
|
||||||
import strawberry
|
import strawberry
|
||||||
|
|
||||||
# from packaging.version import Version
|
# from packaging.version import Version
|
||||||
import os
|
import os
|
||||||
|
|
||||||
@@ -158,10 +159,25 @@ class APIBotConfig:
|
|||||||
"""
|
"""
|
||||||
# 检查主层级
|
# 检查主层级
|
||||||
required_sections = [
|
required_sections = [
|
||||||
"inner", "bot", "groups", "personality", "identity", "schedule",
|
"inner",
|
||||||
"platforms", "chat", "normal_chat", "focus_chat", "emoji", "memory",
|
"bot",
|
||||||
"mood", "keywords_reaction", "chinese_typo", "response_splitter",
|
"groups",
|
||||||
"remote", "experimental", "model"
|
"personality",
|
||||||
|
"identity",
|
||||||
|
"schedule",
|
||||||
|
"platforms",
|
||||||
|
"chat",
|
||||||
|
"normal_chat",
|
||||||
|
"focus_chat",
|
||||||
|
"emoji",
|
||||||
|
"memory",
|
||||||
|
"mood",
|
||||||
|
"keywords_reaction",
|
||||||
|
"chinese_typo",
|
||||||
|
"response_splitter",
|
||||||
|
"remote",
|
||||||
|
"experimental",
|
||||||
|
"model",
|
||||||
]
|
]
|
||||||
for section in required_sections:
|
for section in required_sections:
|
||||||
if section not in config:
|
if section not in config:
|
||||||
@@ -193,9 +209,15 @@ class APIBotConfig:
|
|||||||
|
|
||||||
# 检查模型配置
|
# 检查模型配置
|
||||||
model_keys = [
|
model_keys = [
|
||||||
"llm_reasoning", "llm_normal", "llm_topic_judge", "llm_summary",
|
"llm_reasoning",
|
||||||
"vlm", "llm_heartflow", "llm_observation", "llm_sub_heartflow",
|
"llm_normal",
|
||||||
"embedding"
|
"llm_topic_judge",
|
||||||
|
"llm_summary",
|
||||||
|
"vlm",
|
||||||
|
"llm_heartflow",
|
||||||
|
"llm_observation",
|
||||||
|
"llm_sub_heartflow",
|
||||||
|
"embedding",
|
||||||
]
|
]
|
||||||
if "model" not in config:
|
if "model" not in config:
|
||||||
raise KeyError("缺少 [model] 配置段")
|
raise KeyError("缺少 [model] 配置段")
|
||||||
@@ -246,8 +268,15 @@ class APIEnvConfig:
|
|||||||
:raises: KeyError, TypeError
|
:raises: KeyError, TypeError
|
||||||
"""
|
"""
|
||||||
required_fields = [
|
required_fields = [
|
||||||
"HOST", "PORT", "PLUGINS", "MONGODB_HOST", "MONGODB_PORT", "DATABASE_NAME",
|
"HOST",
|
||||||
"CHAT_ANY_WHERE_BASE_URL", "SILICONFLOW_BASE_URL", "DEEP_SEEK_BASE_URL"
|
"PORT",
|
||||||
|
"PLUGINS",
|
||||||
|
"MONGODB_HOST",
|
||||||
|
"MONGODB_PORT",
|
||||||
|
"DATABASE_NAME",
|
||||||
|
"CHAT_ANY_WHERE_BASE_URL",
|
||||||
|
"SILICONFLOW_BASE_URL",
|
||||||
|
"DEEP_SEEK_BASE_URL",
|
||||||
]
|
]
|
||||||
for field in required_fields:
|
for field in required_fields:
|
||||||
if field not in config:
|
if field not in config:
|
||||||
@@ -274,15 +303,23 @@ class APIEnvConfig:
|
|||||||
|
|
||||||
# 可选字段类型检查
|
# 可选字段类型检查
|
||||||
optional_str_fields = [
|
optional_str_fields = [
|
||||||
"DEEP_SEEK_KEY", "CHAT_ANY_WHERE_KEY", "SILICONFLOW_KEY",
|
"DEEP_SEEK_KEY",
|
||||||
"CONSOLE_LOG_LEVEL", "FILE_LOG_LEVEL",
|
"CHAT_ANY_WHERE_KEY",
|
||||||
"DEFAULT_CONSOLE_LOG_LEVEL", "DEFAULT_FILE_LOG_LEVEL"
|
"SILICONFLOW_KEY",
|
||||||
|
"CONSOLE_LOG_LEVEL",
|
||||||
|
"FILE_LOG_LEVEL",
|
||||||
|
"DEFAULT_CONSOLE_LOG_LEVEL",
|
||||||
|
"DEFAULT_FILE_LOG_LEVEL",
|
||||||
]
|
]
|
||||||
for field in optional_str_fields:
|
for field in optional_str_fields:
|
||||||
if field in config and config[field] is not None and not isinstance(config[field], str):
|
if field in config and config[field] is not None and not isinstance(config[field], str):
|
||||||
raise TypeError(f"{field} 必须为字符串或None")
|
raise TypeError(f"{field} 必须为字符串或None")
|
||||||
|
|
||||||
if "SIMPLE_OUTPUT" in config and config["SIMPLE_OUTPUT"] is not None and not isinstance(config["SIMPLE_OUTPUT"], bool):
|
if (
|
||||||
|
"SIMPLE_OUTPUT" in config
|
||||||
|
and config["SIMPLE_OUTPUT"] is not None
|
||||||
|
and not isinstance(config["SIMPLE_OUTPUT"], bool)
|
||||||
|
):
|
||||||
raise TypeError("SIMPLE_OUTPUT 必须为布尔值或None")
|
raise TypeError("SIMPLE_OUTPUT 必须为布尔值或None")
|
||||||
|
|
||||||
# 检查通过
|
# 检查通过
|
||||||
|
|||||||
Reference in New Issue
Block a user