mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-26 17:13:54 +08:00
update:单模块部署xiaozhi-server,支持mcp调用摄像头识图
This commit is contained in:
@@ -882,3 +882,51 @@ def filter_sensitive_info(config: dict) -> dict:
|
||||
return filtered
|
||||
|
||||
return _filter_dict(copy.deepcopy(config))
|
||||
|
||||
|
||||
def get_vision_url(config: dict) -> str:
|
||||
"""获取 vision URL
|
||||
|
||||
Args:
|
||||
config: 配置字典
|
||||
|
||||
Returns:
|
||||
str: vision URL
|
||||
"""
|
||||
server_config = config["server"]
|
||||
vision_explain = server_config.get("vision_explain", "")
|
||||
if "你的" in vision_explain:
|
||||
local_ip = get_local_ip()
|
||||
port = int(server_config.get("http_port", 8003))
|
||||
vision_explain = f"http://{local_ip}:{port}/mcp/vision/explain"
|
||||
return vision_explain
|
||||
|
||||
|
||||
def is_valid_image_file(file_data: bytes) -> bool:
|
||||
"""
|
||||
检查文件数据是否为有效的图片格式
|
||||
|
||||
Args:
|
||||
file_data: 文件的二进制数据
|
||||
|
||||
Returns:
|
||||
bool: 如果是有效的图片格式返回True,否则返回False
|
||||
"""
|
||||
# 常见图片格式的魔数(文件头)
|
||||
image_signatures = {
|
||||
b"\xff\xd8\xff": "JPEG",
|
||||
b"\x89PNG\r\n\x1a\n": "PNG",
|
||||
b"GIF87a": "GIF",
|
||||
b"GIF89a": "GIF",
|
||||
b"BM": "BMP",
|
||||
b"II*\x00": "TIFF",
|
||||
b"MM\x00*": "TIFF",
|
||||
b"RIFF": "WEBP",
|
||||
}
|
||||
|
||||
# 检查文件头是否匹配任何已知的图片格式
|
||||
for signature in image_signatures:
|
||||
if file_data.startswith(signature):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
import sys
|
||||
|
||||
# 添加项目根目录到Python路径
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
project_root = os.path.abspath(os.path.join(current_dir, "..", ".."))
|
||||
sys.path.insert(0, project_root)
|
||||
|
||||
from config.logger import setup_logging
|
||||
import importlib
|
||||
|
||||
logger = setup_logging()
|
||||
|
||||
|
||||
def create_instance(class_name, *args, **kwargs):
|
||||
# 创建LLM实例
|
||||
if os.path.exists(os.path.join("core", "providers", "vllm", f"{class_name}.py")):
|
||||
lib_name = f"core.providers.vllm.{class_name}"
|
||||
if lib_name not in sys.modules:
|
||||
sys.modules[lib_name] = importlib.import_module(f"{lib_name}")
|
||||
return sys.modules[lib_name].VLLMProvider(*args, **kwargs)
|
||||
|
||||
raise ValueError(f"不支持的VLLM类型: {class_name},请检查该配置的type是否设置正确")
|
||||
Reference in New Issue
Block a user