diff --git a/README.md b/README.md index e459f92ab..6d01ce1c6 100644 --- a/README.md +++ b/README.md @@ -272,7 +272,7 @@ Websocket接口地址: wss://2662r3426b.vicp.fun/xiaozhi/v1/ | 使用方式 | 支持平台 | 免费平台 | |:---:|:---:|:---:| -| OpenAI 接口调用 | 阿里百炼、智谱ChatGLMVLLM | 智谱ChatGLMVLLM | +| OpenAI 接口调用 | 阿里百炼、智谱ChatGLMVLLM、科大讯飞 | 智谱ChatGLMVLLM | 实际上,任何支持 OpenAI 接口调用的 VLLM 均可接入使用。 @@ -322,6 +322,7 @@ Websocket接口地址: wss://2662r3426b.vicp.fun/xiaozhi/v1/ | Memory | [powermem](./docs/powermem-integration.md) | 本地总结 | 取决于LLM和DB | OceanBase开源,支持智能检索 | | Memory | mem_local_short | 本地总结 | 免费 | | | Memory | nomem | 无记忆模式 | 免费 | | +| Memory | mem_report_only | 仅上报 | 免费 | 只上报聊天记录,不做记忆总结 | --- diff --git a/docs/readme/README_de.md b/docs/readme/README_de.md index a65a1acbe..f854a04ff 100644 --- a/docs/readme/README_de.md +++ b/docs/readme/README_de.md @@ -270,7 +270,7 @@ Tatsächlich kann jedes LLM, das OpenAI-Schnittstellenaufrufe unterstützt, inte | Verwendungsmethode | Unterstützte Plattformen | Kostenlose Plattformen | |:---:|:---:|:---:| -| OpenAI-Schnittstellenaufrufe | Alibaba Bailian, Zhipu ChatGLMVLLM | Zhipu ChatGLMVLLM | +| OpenAI-Schnittstellenaufrufe | Alibaba Bailian, Zhipu ChatGLMVLLM, iFLYTEK | Zhipu ChatGLMVLLM | Tatsächlich kann jedes VLLM, das OpenAI-Schnittstellenaufrufe unterstützt, integriert und verwendet werden. @@ -320,6 +320,7 @@ Die Stimmabdruckerkennung erfordert einen separat bereitgestellten [voiceprint-a | Memory | [powermem](../powermem-integration.md) | Lokale Zusammenfassung | Abhängig von LLM und DB | OceanBase Open Source, unterstützt intelligente Abfrage | | Memory | mem_local_short | Lokale Zusammenfassung | Kostenlos | | | Memory | nomem | Kein Gedächtnismodus | Kostenlos | | +| Memory | mem_report_only | Nur Meldung | Kostenlos | Meldet nur Chat-Verläufe, keine Gedächtniszusammenfassung | --- diff --git a/docs/readme/README_en.md b/docs/readme/README_en.md index 3e4d2a1a1..dd2d84082 100644 --- a/docs/readme/README_en.md +++ b/docs/readme/README_en.md @@ -270,7 +270,7 @@ In fact, any LLM that supports OpenAI interface calls can be integrated and used | Usage Method | Supported Platforms | Free Platforms | |:---:|:---:|:---:| -| OpenAI interface calls | Alibaba Bailian, Zhipu ChatGLMVLLM | Zhipu ChatGLMVLLM | +| OpenAI interface calls | Alibaba Bailian, Zhipu ChatGLMVLLM, iFLYTEK | Zhipu ChatGLMVLLM | In fact, any VLLM that supports OpenAI interface calls can be integrated and used. @@ -320,6 +320,7 @@ Voiceprint recognition requires a separately deployed [voiceprint-api](https://g | Memory | [powermem](../powermem-integration.md) | Local summarization | Depends on LLM and DB | OceanBase open source, supports intelligent retrieval | | Memory | mem_local_short | Local summarization | Free | | | Memory | nomem | No memory mode | Free | | +| Memory | mem_report_only | Report only | Free | Only reports chat records, no memory summarization | --- diff --git a/docs/readme/README_es.md b/docs/readme/README_es.md index 3fd99a30a..1cded9cbf 100644 --- a/docs/readme/README_es.md +++ b/docs/readme/README_es.md @@ -270,7 +270,7 @@ En la práctica, se puede integrar cualquier LLM que admita llamadas por la inte | Forma de uso | Plataformas compatibles | Plataformas gratuitas | |:---:|:---:|:---:| -| Llamadas por la interfaz OpenAI | Alibaba Bailian, Zhipu ChatGLMVLLM | Zhipu ChatGLMVLLM | +| Llamadas por la interfaz OpenAI | Alibaba Bailian, Zhipu ChatGLMVLLM, iFLYTEK | Zhipu ChatGLMVLLM | En la práctica, se puede integrar cualquier VLLM que admita llamadas por la interfaz OpenAI. @@ -320,6 +320,7 @@ El reconocimiento de huella de voz requiere desplegar por separado el servicio [ | Memory | [powermem](../powermem-integration.md) | Resumen local | Depende del LLM y de la base de datos | OceanBase de código abierto; admite búsqueda inteligente | | Memory | mem_local_short | Resumen local | Gratuito | | | Memory | nomem | Modo sin memoria | Gratuito | | +| Memory | mem_report_only | Solo informe | Gratuito | Solo informa el historial de chat, sin resumen de memoria | --- diff --git a/docs/readme/README_pt_BR.md b/docs/readme/README_pt_BR.md index ce18fe7a9..6d423497d 100644 --- a/docs/readme/README_pt_BR.md +++ b/docs/readme/README_pt_BR.md @@ -270,7 +270,7 @@ Na verdade, qualquer LLM que suporte chamadas via interface OpenAI pode ser inte | Método de Uso | Plataformas Suportadas | Plataformas Gratuitas | |:---:|:---:|:---:| -| Chamadas via interface OpenAI | Alibaba Bailian, Zhipu ChatGLMVLLM | Zhipu ChatGLMVLLM | +| Chamadas via interface OpenAI | Alibaba Bailian, Zhipu ChatGLMVLLM, iFLYTEK | Zhipu ChatGLMVLLM | Na verdade, qualquer VLLM que suporte chamadas via interface OpenAI pode ser integrado e utilizado. @@ -320,6 +320,7 @@ O reconhecimento de impressão vocal exige um serviço [voiceprint-api](https:// | Memória | [powermem](../powermem-integration.md) | Resumo local | Depende do LLM e BD | OceanBase de código aberto, suporta busca inteligente | | Memória | mem_local_short | Resumo local | Gratuito | | | Memória | nomem | Modo sem memória | Gratuito | | +| Memória | mem_report_only | Apenas relatório | Gratuito | Apenas reporta o histórico de chat, sem resumo de memória | --- diff --git a/docs/readme/README_vi.md b/docs/readme/README_vi.md index 9941c4cc0..d872a8ef9 100644 --- a/docs/readme/README_vi.md +++ b/docs/readme/README_vi.md @@ -271,7 +271,7 @@ Trên thực tế, bất kỳ LLM nào hỗ trợ gọi giao diện OpenAI đề | Phương pháp sử dụng | Nền tảng hỗ trợ | Nền tảng miễn phí | |:---:|:---:|:---:| -| Gọi giao diện OpenAI | Alibaba Bailian, Zhipu ChatGLMVLLM | Zhipu ChatGLMVLLM | +| Gọi giao diện OpenAI | Alibaba Bailian, Zhipu ChatGLMVLLM, iFLYTEK | Zhipu ChatGLMVLLM | Trên thực tế, bất kỳ VLLM nào hỗ trợ gọi giao diện OpenAI đều có thể truy cập sử dụng. @@ -321,6 +321,7 @@ Nhận dạng vân giọng cần dịch vụ [voiceprint-api](https://github.com | Memory | [powermem](../powermem-integration.md) | Tóm tắt cục bộ | Phụ thuộc vào LLM và DB | OceanBase mã nguồn mở, hỗ trợ tìm kiếm thông minh | | Memory | mem_local_short | Tóm tắt cục bộ | Miễn phí | | | Memory | nomem | Chế độ không có bộ nhớ | Miễn phí | | +| Memory | mem_report_only | Chỉ báo cáo | Miễn phí | Chỉ báo cáo lịch sử trò chuyện, không tóm tắt bộ nhớ | --- diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index 66a97e81a..e2cd0dd88 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -348,6 +348,10 @@ Memory: nomem: # 不想使用记忆功能,可以使用nomem type: nomem + mem_report_only: + # 只把聊天记录上报到智控台,不做记忆总结,也不保存记忆 + # 适合只想留存对话记录、又不需要记忆功能的场景 + type: mem_report_only mem_local_short: # 本地记忆功能,通过selected_module的llm总结,数据保存在本地服务器,不会上传到外部服务器 type: mem_local_short diff --git a/main/xiaozhi-server/tests/config/test_provider_registry.py b/main/xiaozhi-server/tests/config/test_provider_registry.py new file mode 100644 index 000000000..ad58e9e50 --- /dev/null +++ b/main/xiaozhi-server/tests/config/test_provider_registry.py @@ -0,0 +1,124 @@ +"""出厂配置与 provider 实现之间的一致性护栏。 + +config.yaml 是出厂默认配置,每个 provider 段(Memory/LLM/TTS/...)下的每个键 +都对应一个可选的 provider 实现。两边一旦脱节,就会出现两种坏情况: + +1. 配置里有、实现里没有 —— 用户选了会在 create_instance 阶段报 + "不支持的服务类型"。 +2. 实现里有、配置里没有 —— 用户想选它,却要么找不到入口,要么在连接初始化 + 阶段直接 KeyError(core/connection.py 里是 + ``self.config["Memory"][selected_module["Memory"]]["type"]``)。 + +Memory 段历史上踩过第 2 种:``mem_report_only`` 的实现在 +core/providers/memory/mem_report_only/ 里,core/connection.py 也显式处理了它, +但 config.yaml 的 Memory 段没有对应配置块 —— 只要在 selected_module 里选了它, +连接初始化就会 KeyError,服务起不来。 + +这里把上面两条不变量钉死。 +""" +from __future__ import annotations + +import os + +import pytest + +from config.config_loader import get_project_dir, read_config + +# 各模块的 provider 发现方式: +# "dir" —— 目录式:core/providers///.py +# "file" —— 文件式:core/providers//.py +MODULES = [ + ("Intent", "intent", "dir"), + ("Memory", "memory", "dir"), + ("LLM", "llm", "dir"), + ("ASR", "asr", "file"), + ("TTS", "tts", "file"), + ("VAD", "vad", "file"), + ("VLLM", "vllm", "file"), +] + +# 目录式模块里,一个实现目录通常只服务一个 provider(目录名 == 配置键 == +# type)。LLM 是例外:core/providers/llm/openai/ 被 ChatGLMLLM、DoubaoLLM +# 等多个配置键共用,所以「实现 -> 配置」的反向检查只对一一对应的模块做。 +ONE_TO_ONE_MODULES = ("Memory",) + + +@pytest.fixture(scope="module") +def default_config(): + """出厂的 config.yaml(未经 data/.config.yaml 覆盖)。""" + return read_config(get_project_dir() + "config.yaml") + + +def _impl_path(mod: str, style: str, type_name: str) -> str: + """provider 实现的绝对路径。""" + root = get_project_dir() + if style == "dir": + return os.path.join(root, "core", "providers", mod, type_name, f"{type_name}.py") + return os.path.join(root, "core", "providers", mod, f"{type_name}.py") + + +def test_selected_module_provider_is_configured(default_config): + """selected_module 里选中的 provider 必须在对应配置段里存在。 + + core/connection.py 初始化各模块时都是直接下标取配置 + (self.config["Memory"][selected_module["Memory"]]["type"]), + 配置段里缺这个键就是启动期 KeyError。 + """ + selected = default_config.get("selected_module") or {} + for module in ("VAD", "ASR", "LLM", "VLLM", "TTS", "Memory", "Intent"): + name = selected.get(module) + assert name, f"selected_module.{module} 没有设置" + block = (default_config.get(module) or {}).get(name) + assert block is not None, ( + f"selected_module.{module} = {name}," + f"但 config.yaml 里没有 {module}.{name} 配置块" + ) + + +@pytest.mark.parametrize( + "section,mod,style", MODULES, ids=[section for section, _, _ in MODULES] +) +def test_every_configured_provider_has_implementation(default_config, section, mod, style): + """配置里的每个 provider,type 字段都必须指向真实存在的实现。 + + 覆盖「配置有、实现没有」:用户选了会在 create_instance 阶段报 + "不支持的服务类型"。 + """ + for name, block in (default_config.get(section) or {}).items(): + if not isinstance(block, dict): + continue + type_name = block.get("type", name) + path = _impl_path(mod, style, type_name) + assert os.path.exists(path), ( + f"{section}.{name} 的 type={type_name} 找不到实现文件 {path}" + ) + + +@pytest.mark.parametrize("section", ONE_TO_ONE_MODULES) +def test_every_implemented_provider_is_configured(default_config, section): + """实现里有的 provider,配置里必须也有一份。 + + 覆盖「实现有、配置没有」:这类 provider 用户根本没法从出厂配置里选到, + 一旦有人手动选了就会在连接初始化阶段 KeyError。 + + mem_report_only 就是这么漏掉的。 + """ + mod = section.lower() + providers_dir = os.path.join(get_project_dir(), "core", "providers", mod) + impls = sorted( + name + for name in os.listdir(providers_dir) + if os.path.isfile(os.path.join(providers_dir, name, f"{name}.py")) + ) + assert impls, f"core/providers/{mod} 下没找到任何 provider 实现" + + for name in impls: + block = (default_config.get(section) or {}).get(name) + assert block is not None, ( + f"core/providers/{mod}/{name} 有实现," + f"但 config.yaml 的 {section} 段没有 {name} 配置块" + ) + assert block.get("type", name) == name, ( + f"config.yaml 的 {section}.{name}.type 应该是 {name}," + f"实际是 {block.get('type')}" + )