From 68c9cc3e42d9063543b49b92d7943b7dbc782372 Mon Sep 17 00:00:00 2001 From: kirto Date: Thu, 2 Apr 2026 16:09:22 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20=E5=AE=8C=E6=88=90deepseek?= =?UTF-8?q?=E3=80=81=E8=B1=86=E5=8C=85=E3=80=81kimi=E3=80=81=E6=B7=B7?= =?UTF-8?q?=E5=85=83=EF=BC=88=E8=85=BE=E8=AE=AF=E5=85=83=E5=AE=9D=EF=BC=89?= =?UTF-8?q?=E7=9A=84=E5=AF=B9=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 + README.md | 47 ++++++++-- README_ZH.md | 47 ++++++++-- TODO.md | 10 +-- TODO_ZH.md | 9 +- components/embed_claw/ec_config_internal.h | 99 +++++++++++++++++++++- 6 files changed, 183 insertions(+), 32 deletions(-) diff --git a/.gitignore b/.gitignore index 517e760..147bece 100644 --- a/.gitignore +++ b/.gitignore @@ -64,3 +64,6 @@ STEP.md # config ec_config.h + +# codex +.codex diff --git a/README.md b/README.md index bd068bc..2f85b6c 100644 --- a/README.md +++ b/README.md @@ -203,23 +203,50 @@ Build-time configuration is layered: - [`components/embed_claw/ec_config_internal.h`](components/embed_claw/ec_config_internal.h) provides repo defaults and empty secret placeholders. - Create local [`main/ec_config.h`](main/ec_config.h) for project-specific overrides. Define only the macros you want to override. The build injects this header into `embed_claw`, so sensitive values do not need to live in the shared component tree. -Create `main/ec_config.h` if needed, then set at least: +Create `main/ec_config.h` if needed. The default preset is `Qwen`: ```c +#define EC_USE_QWEN 1 +#define EC_USE_DEEPSEEK 0 +#define EC_USE_DOUBAO 0 +#define EC_USE_KIMI 0 +#define EC_USE_HUNYUAN 0 #define EC_SECRET_SEARCH_KEY "YOUR_TAVILY_API_KEY" #define EC_LLM_API_KEY "YOUR_DASHSCOPE_API_KEY" -#define EC_LLM_MODEL "qwen-plus" #define EC_SECRET_FEISHU_APP_ID "YOUR_FEISHU_APP_ID" #define EC_SECRET_FEISHU_APP_SECRET "YOUR_FEISHU_APP_SECRET" ``` -Default LLM URL (DashScope OpenAI-compatible): +Under the default preset, the effective LLM settings are: ```c -#define EC_LLM_API_URL "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions" +#define EC_LLM_PROVIDER_NAME "openai" +#define EC_LLM_API_URL "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions" +#define EC_LLM_MODEL "qwen-plus" ``` -If you skip Tavily or Feishu for now, you only need the Qwen-related keys. +Built-in OpenAI-compatible LLM presets now include: + +- `Qwen`: DashScope + `qwen-plus` +- `DeepSeek`: `https://api.deepseek.com/v1/chat/completions` + `deepseek-chat` +- `Doubao`: `https://operator.las.cn-beijing.volces.com/api/v1/chat/completions` + `doubao-seed-1-6-251015` +- `KiMi`: `https://api.moonshot.cn/v1/chat/completions` + `kimi-k2.5` +- `Hunyuan`: `https://api.hunyuan.cloud.tencent.com/v1/chat/completions` + `hunyuan-turbos-latest` + +If you want to switch to DeepSeek, use: + +```c +#define EC_USE_QWEN 0 +#define EC_USE_DEEPSEEK 1 +#define EC_LLM_API_KEY "YOUR_DEEPSEEK_API_KEY" +``` + +Notes: + +- Explicit `EC_LLM_PROVIDER_NAME / EC_LLM_API_URL / EC_LLM_MODEL` overrides take precedence over preset-derived defaults. +- Only one `EC_USE_*` LLM preset can be `1` at a time. +- The Doubao preset defaults to the Volcengine Beijing OpenAI-compatible endpoint; override `EC_LLM_API_URL` or `EC_DOUBAO_LLM_API_URL` if your region or endpoint differs. +- If you skip Tavily or Feishu for now, you only need the keys for the active LLM preset. Optional channel toggles: @@ -597,9 +624,11 @@ esp_err_t ec_channel_demo(void) Currently used: +- `EC_USE_QWEN=1` +- Other built-in OpenAI-compatible presets: `EC_USE_DEEPSEEK / EC_USE_DOUBAO / EC_USE_KIMI / EC_USE_HUNYUAN` - `EC_LLM_PROVIDER_NAME` (default: `openai`) -- DashScope OpenAI-compatible API -- **qwen-plus** +- Qwen preset defaults to DashScope OpenAI-compatible + **qwen-plus** +- The other presets reuse the same OpenAI-compatible provider To add another provider: @@ -610,7 +639,7 @@ To add another provider: 5. Add one branch in `ec_llm_init_default()` (`components/embed_claw/llm/ec_llm.c`) to map provider name to getter 6. Set `EC_LLM_PROVIDER_NAME` in `main/ec_config.h` (and set matching URL/model) -The current runtime path is OpenAI-compatible providers (OpenAI, DeepSeek, Moonshot, Qwen, etc.). Other provider families are not wired yet. +The current runtime path is OpenAI-compatible providers (OpenAI, DeepSeek, Moonshot/KiMi, Qwen, Doubao, Hunyuan, etc.). Other provider families are not wired yet. ## Possible next steps @@ -624,7 +653,7 @@ For open-source distribution, repo defaults keep secret fields empty. Put real k Before running, set: -- DashScope / Qwen API key +- API key for the active LLM preset - `EC_LLM_PROVIDER_NAME` (default is `openai`) - Tavily API key - Feishu App ID and App Secret diff --git a/README_ZH.md b/README_ZH.md index 8f57af2..8b83d21 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -202,23 +202,50 @@ EmbedClaw 使用 SPIFFS 保存人格、用户信息、会话与记忆: - [`components/embed_claw/ec_config_internal.h`](components/embed_claw/ec_config_internal.h) 提供仓库内默认值和空白密钥占位。 - 如需放项目自己的参数或敏感信息,请新建本地 [`main/ec_config.h`](main/ec_config.h),只定义你要覆盖的宏。构建系统会把这个头自动注入 `embed_claw`,因此不必把密钥写回共享组件目录。 -如不存在可先创建 `main/ec_config.h`,你至少需要填写: +如不存在可先创建 `main/ec_config.h`。默认预设是 `Qwen`: ```c +#define EC_USE_QWEN 1 +#define EC_USE_DEEPSEEK 0 +#define EC_USE_DOUBAO 0 +#define EC_USE_KIMI 0 +#define EC_USE_HUNYUAN 0 #define EC_SECRET_SEARCH_KEY "YOUR_TAVILY_API_KEY" #define EC_LLM_API_KEY "YOUR_DASHSCOPE_API_KEY" -#define EC_LLM_MODEL "qwen-plus" #define EC_SECRET_FEISHU_APP_ID "YOUR_FEISHU_APP_ID" #define EC_SECRET_FEISHU_APP_SECRET "YOUR_FEISHU_APP_SECRET" ``` -默认的 LLM 地址已经指向 DashScope OpenAI-Compatible 接口: +在默认预设下,LLM 会自动落到: ```c -#define EC_LLM_API_URL "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions" +#define EC_LLM_PROVIDER_NAME "openai" +#define EC_LLM_API_URL "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions" +#define EC_LLM_MODEL "qwen-plus" ``` -如果你暂时不用 Tavily 或飞书,可以只配置 Qwen 所需参数。 +当前内置的 OpenAI-Compatible LLM 预设有: + +- `Qwen`:DashScope + `qwen-plus` +- `DeepSeek`:`https://api.deepseek.com/v1/chat/completions` + `deepseek-chat` +- `Doubao`:`https://operator.las.cn-beijing.volces.com/api/v1/chat/completions` + `doubao-seed-1-6-251015` +- `KiMi`:`https://api.moonshot.cn/v1/chat/completions` + `kimi-k2.5` +- `Hunyuan`:`https://api.hunyuan.cloud.tencent.com/v1/chat/completions` + `hunyuan-turbos-latest` + +如果你想切到 DeepSeek,可在本地配置里改成: + +```c +#define EC_USE_QWEN 0 +#define EC_USE_DEEPSEEK 1 +#define EC_LLM_API_KEY "YOUR_DEEPSEEK_API_KEY" +``` + +说明: + +- 显式定义的 `EC_LLM_PROVIDER_NAME / EC_LLM_API_URL / EC_LLM_MODEL` 优先级高于预设宏。 +- 同一时刻只能有一个 `EC_USE_*` LLM 预设为 `1`。 +- Doubao 预设默认使用火山引擎北京区 OpenAI-Compatible endpoint;如果你的地域或接入点不同,请显式覆盖 `EC_LLM_API_URL` 或 `EC_DOUBAO_LLM_API_URL`。 +- 如果你暂时不用 Tavily 或飞书,可以只配置当前 LLM 预设所需参数。 可选的 channel 开关示例: @@ -628,9 +655,11 @@ esp_err_t ec_channel_demo(void) 当前默认实际启用的是: +- `EC_USE_QWEN=1` +- 其它内置 OpenAI-Compatible 预设:`EC_USE_DEEPSEEK / EC_USE_DOUBAO / EC_USE_KIMI / EC_USE_HUNYUAN` - `EC_LLM_PROVIDER_NAME`(默认:`openai`) -- DashScope OpenAI-Compatible 接口 -- `qwen-plus` +- Qwen 预设默认落到 DashScope OpenAI-Compatible + `qwen-plus` +- 其它预设同样复用这套 OpenAI-Compatible provider 但抽象层已经拆出来了,扩展新 Provider 的路径很清晰: @@ -644,7 +673,7 @@ esp_err_t ec_channel_demo(void) 补充说明: - 但现阶段真正跑通的是 OpenAI-Compatible 路径 -- 所以如果你要接 OpenAI、DeepSeek、Moonshot、通义千问兼容接口,成本会最低 +- 所以如果你要接 OpenAI、DeepSeek、Moonshot/KiMi、通义千问、豆包或混元的兼容接口,成本会最低 ## 适合继续演进的方向 @@ -658,7 +687,7 @@ esp_err_t ec_channel_demo(void) 在正式运行前,请先填写: -- DashScope / Qwen API Key +- 当前预设对应的 LLM API Key - `EC_LLM_PROVIDER_NAME`(默认是 `openai`) - Tavily API Key - Feishu App ID / Secret diff --git a/TODO.md b/TODO.md index 374eb68..70313b9 100644 --- a/TODO.md +++ b/TODO.md @@ -3,11 +3,10 @@ ## LLM integration - [x] Qwen -- [ ] XiaoZhi -- [ ] DeepSeek -- [ ] Doubao (ByteDance) -- [ ] KiMi (Moonshot) -- [ ] Hunyuan (Tencent) +- [x] DeepSeek (OpenAI-compatible preset) +- [x] Doubao (ByteDance, OpenAI-compatible preset) +- [x] KiMi (Moonshot, OpenAI-compatible preset) +- [x] Hunyuan (Tencent, OpenAI-compatible preset) ## Tools integration @@ -35,4 +34,3 @@ - [ ] Support more filesystems (beyond SPIFFS) - [ ] SD card support - [ ] Support ESP32C3 - diff --git a/TODO_ZH.md b/TODO_ZH.md index edf5edb..d2a829a 100644 --- a/TODO_ZH.md +++ b/TODO_ZH.md @@ -3,11 +3,10 @@ ## LLM对接 - [x] 对接qwen -- [ ] 对接小智 -- [ ] 对接deepseek -- [ ] 对接豆包 -- [ ] 对接KiMi -- [ ] 对接混元 +- [x] 对接deepseek(OpenAI-Compatible 预设) +- [x] 对接豆包(OpenAI-Compatible 预设) +- [x] 对接KiMi(OpenAI-Compatible 预设) +- [x] 对接混元(OpenAI-Compatible 预设) ## Tools对接 diff --git a/components/embed_claw/ec_config_internal.h b/components/embed_claw/ec_config_internal.h index 3a367c2..d1daeb3 100644 --- a/components/embed_claw/ec_config_internal.h +++ b/components/embed_claw/ec_config_internal.h @@ -72,12 +72,95 @@ extern "C" { /* * [embed_claw/llm] * 如何配置: - * - 覆盖 provider 名称、API 地址、密钥、模型和响应缓冲参数。 + * - 可通过预设宏快速切换 Qwen / DeepSeek / Doubao / KiMi / Hunyuan, + * 也可直接覆盖 provider 名称、 + * API 地址、密钥、模型和响应缓冲参数。 * 作用: * - 影响 LLM provider 选择、接入目标、推理容量、内存占用和工具调用解析上限。 + * 优先级: + * - 显式定义的 EC_LLM_PROVIDER_NAME / EC_LLM_API_URL / EC_LLM_MODEL + * 优先于预设宏推导值。 */ +#ifndef EC_USE_DEEPSEEK +#define EC_USE_DEEPSEEK 0 +#endif + +#ifndef EC_USE_DOUBAO +#define EC_USE_DOUBAO 0 +#endif + +#ifndef EC_USE_KIMI +#define EC_USE_KIMI 0 +#endif + +#ifndef EC_USE_HUNYUAN +#define EC_USE_HUNYUAN 0 +#endif + +#ifndef EC_USE_QWEN +#if EC_USE_DEEPSEEK || EC_USE_DOUBAO || EC_USE_KIMI || EC_USE_HUNYUAN +#define EC_USE_QWEN 0 +#else +#define EC_USE_QWEN 1 +#endif +#endif + +#if (EC_USE_QWEN + EC_USE_DEEPSEEK + EC_USE_DOUBAO + EC_USE_KIMI + EC_USE_HUNYUAN) > 1 +#error "Only one EC_USE_* LLM preset can be 1 at a time" +#endif + +#ifndef EC_QWEN_LLM_API_URL +#define EC_QWEN_LLM_API_URL "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions" +#endif + +#ifndef EC_QWEN_LLM_MODEL +#define EC_QWEN_LLM_MODEL "qwen-plus" +#endif + +#ifndef EC_DEEPSEEK_LLM_API_URL +#define EC_DEEPSEEK_LLM_API_URL "https://api.deepseek.com/v1/chat/completions" +#endif + +#ifndef EC_DEEPSEEK_LLM_MODEL +#define EC_DEEPSEEK_LLM_MODEL "deepseek-chat" +#endif + +#ifndef EC_DOUBAO_LLM_API_URL +#define EC_DOUBAO_LLM_API_URL "https://ark.cn-beijing.volces.com/api/v3/chat/completions" +#endif + +#ifndef EC_DOUBAO_LLM_MODEL +#define EC_DOUBAO_LLM_MODEL "doubao-seed-2-0-pro-260215" +#endif + +#ifndef EC_KIMI_LLM_API_URL +#define EC_KIMI_LLM_API_URL "https://api.moonshot.cn/v1/chat/completions" +#endif + +#ifndef EC_KIMI_LLM_MODEL +#define EC_KIMI_LLM_MODEL "kimi-k2.5" +#endif + +#ifndef EC_HUNYUAN_LLM_API_URL +#define EC_HUNYUAN_LLM_API_URL "https://api.hunyuan.cloud.tencent.com/v1/chat/completions" +#endif + +#ifndef EC_HUNYUAN_LLM_MODEL +#define EC_HUNYUAN_LLM_MODEL "hunyuan-turbos-latest" +#endif + #ifndef EC_LLM_API_URL -#define EC_LLM_API_URL "https://dashscope-intl.aliyuncs.com/compatible-mode/v1/chat/completions" +#if EC_USE_DEEPSEEK +#define EC_LLM_API_URL EC_DEEPSEEK_LLM_API_URL +#elif EC_USE_DOUBAO +#define EC_LLM_API_URL EC_DOUBAO_LLM_API_URL +#elif EC_USE_KIMI +#define EC_LLM_API_URL EC_KIMI_LLM_API_URL +#elif EC_USE_HUNYUAN +#define EC_LLM_API_URL EC_HUNYUAN_LLM_API_URL +#else +#define EC_LLM_API_URL EC_QWEN_LLM_API_URL +#endif #endif #ifndef EC_LLM_API_KEY @@ -85,7 +168,17 @@ extern "C" { #endif #ifndef EC_LLM_MODEL -#define EC_LLM_MODEL "qwen-plus" +#if EC_USE_DEEPSEEK +#define EC_LLM_MODEL EC_DEEPSEEK_LLM_MODEL +#elif EC_USE_DOUBAO +#define EC_LLM_MODEL EC_DOUBAO_LLM_MODEL +#elif EC_USE_KIMI +#define EC_LLM_MODEL EC_KIMI_LLM_MODEL +#elif EC_USE_HUNYUAN +#define EC_LLM_MODEL EC_HUNYUAN_LLM_MODEL +#else +#define EC_LLM_MODEL EC_QWEN_LLM_MODEL +#endif #endif #ifndef EC_LLM_PROVIDER_NAME