Skip to content

配置 API

通过 HTTP 接口读取和修改 hebb.json 配置。

所有配置端点都挂载在 /api/v1/admin/config 下。

获取配置

GET /api/v1/admin/config

返回所有配置项。敏感字段(llm_api_keypg_urlembedding_api_key)自动脱敏显示。

bash
curl http://localhost:8321/api/v1/admin/config

响应(节选):

json
{
  "storage_type": "sqlite",
  "home": null,
  "embedding_enabled": true,
  "embedding_provider": "local",
  "embedding_model": "all-MiniLM-L6-v2",
  "embedding_dim": 384,
  "hf_endpoint": null,
  "llm_model": null,
  "llm_base_url": null,
  "llm_api_key": "sk-x****ykey",
  "host": "0.0.0.0",
  "port": 8321,
  "consolidation_time": "18:00",
  "forget_interval_seconds": 1800,
  "base_ttl_hours": 168.0,
  "decay_factor": 0.693,
  "weight_recency": 1.0,
  "weight_importance": 1.0,
  "weight_relevance": 1.0
}

更新配置

PUT /api/v1/admin/config

每次更新一个配置字段,修改会直接写入 hebb.json

字段类型必填说明
keystring配置字段名
valuestring字符串形式的新值,服务端按字段类型自动转换
bash
curl -X PUT http://localhost:8321/api/v1/admin/config \
  -H "Content-Type: application/json" \
  -d '{"key": "llm_model", "value": "openai/gpt-4o"}'

响应:

json
{
  "key": "llm_model",
  "value": "openai/gpt-4o",
  "restart_required": false
}

restart_requiredtrue 时需要重启服务才能生效。需要重启的字段包括:storage_typepg_urlpg_pool_minpg_pool_maxembedding_enabledembedding_providerembedding_modelembedding_dimembedding_api_keyembedding_base_urlconsolidation_timehostporthome

查看敏感值

GET /api/v1/admin/config/reveal/{key}

仅支持 llm_api_keypg_urlembedding_api_key

bash
curl http://localhost:8321/api/v1/admin/config/reveal/llm_api_key

响应:

json
{
  "key": "llm_api_key",
  "value": "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

测试 LLM 连接

向指定模型发起一次最小化的请求,验证 model/base_url/api_key 是否可用。如果 api_key 中包含 ****(脱敏占位),服务端会自动从 hebb.json 中读取真实密钥。

POST /api/v1/admin/config/test-llm
字段类型必填说明
modelstringLiteLLM 模型标识,如 openai/gpt-4o-mini
base_urlstring自定义 API 端点
api_keystringAPI Key(可填脱敏占位以使用已保存的密钥)
bash
curl -X POST http://localhost:8321/api/v1/admin/config/test-llm \
  -H "Content-Type: application/json" \
  -d '{"model": "openai/gpt-4o-mini", "api_key": "sk-your-key"}'

成功响应:

json
{
  "success": true,
  "response": "ok",
  "model": "gpt-4o-mini"
}

失败响应:

json
{
  "success": false,
  "error": "AuthenticationError: Invalid API key"
}

测试 Embedding 连接

验证本地 embedding 模型能否加载,或云端 embedding API 能否响应。

POST /api/v1/admin/config/test-embedding
字段类型必填说明
providerstringlocalapi
modelstring模型名称(HuggingFace ID 或 LiteLLM 模型 ID)
base_urlstringapi 类型必填
api_keystringAPI Key 或脱敏占位

成功响应:

json
{
  "success": true,
  "dimension": 384,
  "message": "Model loaded, dimension=384, sample vector length=384"
}

Embedding 状态

返回当前 embedding 配置以及本地模型是否已缓存。

GET /api/v1/admin/config/embedding-status

响应(local,已缓存):

json
{
  "enabled": true,
  "provider": "local",
  "model": "all-MiniLM-L6-v2",
  "status": "cached",
  "cached": true
}

status 取值:cachednot_downloadeddisabledapi

字段元数据

返回所有配置字段的类型、描述和默认值,便于动态构建表单。

GET /api/v1/admin/config/fields

响应(节选):

json
[
  {
    "key": "storage_type",
    "type": "string",
    "description": "'sqlite' or 'postgresql'",
    "default": "sqlite"
  },
  {
    "key": "port",
    "type": "number",
    "description": "",
    "default": 8321
  }
]

Released under the MIT License.