feat: 增加国内大模型厂商支持(硅基流动、火山方舟)
Some checks failed
Build / idf-build (push) Has been cancelled

- 创建通用提供商架构(llm_provider.h/c)
- 支持四个提供商:Anthropic、OpenAI、SiliconFlow、Volcengine
- 添加提供商特定的API密钥和Base URL配置
- 扩展CLI命令:set_siliconflow_key/url、set_volcengine_key/url
- 更新mimi_secrets.h.example配置模板
- 更新README.md文档说明
- 每个提供商支持独立的NVS存储配置
This commit is contained in:
2026-03-31 19:37:15 +08:00
parent 46e46b0a13
commit 49d3a131b7
8 changed files with 618 additions and 20 deletions

View File

@@ -171,6 +171,80 @@ static int cmd_set_model_provider(int argc, char **argv)
return 0;
}
/* --- set_siliconflow_key command --- */
static struct {
struct arg_str *key;
struct arg_end *end;
} siliconflow_key_args;
static int cmd_set_siliconflow_key(int argc, char **argv)
{
int nerrors = arg_parse(argc, argv, (void **)&siliconflow_key_args);
if (nerrors != 0) {
arg_print_errors(stderr, siliconflow_key_args.end, argv[0]);
return 1;
}
llm_set_api_key(siliconflow_key_args.key->sval[0]);
llm_provider_set_api_key("siliconflow", siliconflow_key_args.key->sval[0]);
printf("SiliconFlow API key saved.\n");
return 0;
}
/* --- set_siliconflow_url command --- */
static struct {
struct arg_str *url;
struct arg_end *end;
} siliconflow_url_args;
static int cmd_set_siliconflow_url(int argc, char **argv)
{
int nerrors = arg_parse(argc, argv, (void **)&siliconflow_url_args);
if (nerrors != 0) {
arg_print_errors(stderr, siliconflow_url_args.end, argv[0]);
return 1;
}
llm_set_base_url("siliconflow", siliconflow_url_args.url->sval[0]);
printf("SiliconFlow Base URL saved.\n");
return 0;
}
/* --- set_volcengine_key command --- */
static struct {
struct arg_str *key;
struct arg_end *end;
} volcengine_key_args;
static int cmd_set_volcengine_key(int argc, char **argv)
{
int nerrors = arg_parse(argc, argv, (void **)&volcengine_key_args);
if (nerrors != 0) {
arg_print_errors(stderr, volcengine_key_args.end, argv[0]);
return 1;
}
llm_set_api_key(volcengine_key_args.key->sval[0]);
llm_provider_set_api_key("volcengine", volcengine_key_args.key->sval[0]);
printf("Volcengine API key saved.\n");
return 0;
}
/* --- set_volcengine_url command --- */
static struct {
struct arg_str *url;
struct arg_end *end;
} volcengine_url_args;
static int cmd_set_volcengine_url(int argc, char **argv)
{
int nerrors = arg_parse(argc, argv, (void **)&volcengine_url_args);
if (nerrors != 0) {
arg_print_errors(stderr, volcengine_url_args.end, argv[0]);
return 1;
}
llm_set_base_url("volcengine", volcengine_url_args.url->sval[0]);
printf("Volcengine Base URL saved.\n");
return 0;
}
/* --- memory_read command --- */
static int cmd_memory_read(int argc, char **argv)
{
@@ -563,6 +637,18 @@ static int cmd_config_show(int argc, char **argv)
print_config("API Key", MIMI_NVS_LLM, MIMI_NVS_KEY_API_KEY, MIMI_SECRET_API_KEY, true);
print_config("Model", MIMI_NVS_LLM, MIMI_NVS_KEY_MODEL, MIMI_SECRET_MODEL, false);
print_config("Provider", MIMI_NVS_LLM, MIMI_NVS_KEY_PROVIDER, MIMI_SECRET_MODEL_PROVIDER, false);
/* Provider-specific configurations */
printf(" --- Provider-specific configs ---\n");
print_config("Anthropic Key", MIMI_NVS_LLM, MIMI_NVS_KEY_ANTHROPIC_API_KEY, "", true);
print_config("Anthropic URL", MIMI_NVS_LLM, MIMI_NVS_KEY_ANTHROPIC_BASE_URL, "", false);
print_config("OpenAI Key", MIMI_NVS_LLM, MIMI_NVS_KEY_OPENAI_API_KEY, "", true);
print_config("OpenAI URL", MIMI_NVS_LLM, MIMI_NVS_KEY_OPENAI_BASE_URL, "", false);
print_config("SiliconFlow Key", MIMI_NVS_LLM, MIMI_NVS_KEY_SILICONFLOW_API_KEY, "", true);
print_config("SiliconFlow URL", MIMI_NVS_LLM, MIMI_NVS_KEY_SILICONFLOW_BASE_URL, "", false);
print_config("Volcengine Key", MIMI_NVS_LLM, MIMI_NVS_KEY_VOLCENGINE_API_KEY, "", true);
print_config("Volcengine URL", MIMI_NVS_LLM, MIMI_NVS_KEY_VOLCENGINE_BASE_URL, "", false);
print_config("Proxy Host", MIMI_NVS_PROXY, MIMI_NVS_KEY_PROXY_HOST, MIMI_SECRET_PROXY_HOST, false);
print_config_u16("Proxy Port", MIMI_NVS_PROXY, MIMI_NVS_KEY_PROXY_PORT, MIMI_SECRET_PROXY_PORT);
print_config("Search Key", MIMI_NVS_SEARCH, MIMI_NVS_KEY_API_KEY, MIMI_SECRET_SEARCH_KEY, true);
@@ -887,7 +973,7 @@ esp_err_t serial_cli_init(void)
esp_console_cmd_register(&model_cmd);
/* set_model_provider */
provider_args.provider = arg_str1(NULL, NULL, "<provider>", "Model provider (anthropic|openai)");
provider_args.provider = arg_str1(NULL, NULL, "<provider>", "Model provider (anthropic|openai|siliconflow|volcengine)");
provider_args.end = arg_end(1);
esp_console_cmd_t provider_cmd = {
.command = "set_model_provider",
@@ -897,6 +983,50 @@ esp_err_t serial_cli_init(void)
};
esp_console_cmd_register(&provider_cmd);
/* set_siliconflow_key */
siliconflow_key_args.key = arg_str1(NULL, NULL, "<key>", "SiliconFlow API key");
siliconflow_key_args.end = arg_end(1);
esp_console_cmd_t siliconflow_key_cmd = {
.command = "set_siliconflow_key",
.help = "Set SiliconFlow API key",
.func = &cmd_set_siliconflow_key,
.argtable = &siliconflow_key_args,
};
esp_console_cmd_register(&siliconflow_key_cmd);
/* set_siliconflow_url */
siliconflow_url_args.url = arg_str1(NULL, NULL, "<url>", "SiliconFlow Base URL");
siliconflow_url_args.end = arg_end(1);
esp_console_cmd_t siliconflow_url_cmd = {
.command = "set_siliconflow_url",
.help = "Set SiliconFlow Base URL",
.func = &cmd_set_siliconflow_url,
.argtable = &siliconflow_url_args,
};
esp_console_cmd_register(&siliconflow_url_cmd);
/* set_volcengine_key */
volcengine_key_args.key = arg_str1(NULL, NULL, "<key>", "Volcengine API key");
volcengine_key_args.end = arg_end(1);
esp_console_cmd_t volcengine_key_cmd = {
.command = "set_volcengine_key",
.help = "Set Volcengine API key",
.func = &cmd_set_volcengine_key,
.argtable = &volcengine_key_args,
};
esp_console_cmd_register(&volcengine_key_cmd);
/* set_volcengine_url */
volcengine_url_args.url = arg_str1(NULL, NULL, "<url>", "Volcengine Base URL");
volcengine_url_args.end = arg_end(1);
esp_console_cmd_t volcengine_url_cmd = {
.command = "set_volcengine_url",
.help = "Set Volcengine Base URL",
.func = &cmd_set_volcengine_url,
.argtable = &volcengine_url_args,
};
esp_console_cmd_register(&volcengine_url_cmd);
/* skill_list */
esp_console_cmd_t skill_list_cmd = {
.command = "skill_list",