dataease / dataease/SQLBot

[BUG]大模型调用失败

Abierto
#945 2 comentarios 0 reacciones 2 asignados Ver en GitHub

@xuwei-fit2cloud ya está trabajando en esto.

Desde el 5/3/2026.

bug
Lenguaje dominante
JavaScript
Estrellas
6.8k
Forks
882
Merge medio
4 h 37 min
PR fusionados (30 d)
32

Descripción

[BUG] 自定义 OpenAI 兼容接口在 SQLBot 中校验成功,但实际调用返回 401(JWT格式的api-key,形如eyJxxxxx.xxxxxx.xxxx)
Image Image
SQLBot Version

v1.6.0
Docker 镜像:registry.cn-qingdao.aliyuncs.com/dataease/sqlbot:v1.6.0

Run Mode

Docker 运行


问题描述

在 SQLBot 中配置 自定义 OpenAI 兼容接口 时:

  • 保存模型配置时的“测试连接 / 校验”阶段调用成功
  • 但在 实际聊天 / SQL 生成阶段调用失败

返回错误:

openai.AuthenticationError: Error code: 401
{'code': 401, 'msg': '流程->API Key解析失败'}

但是使用 相同 API 地址 + 相同 API Key,通过 curl 或其他客户端调用接口是完全正常的。

因此怀疑 SQLBot 在 运行阶段构造请求或读取配置时存在问题


API 接口示例

接口地址(已脱敏):

http://xxx.xxx.xxx.xxx:xxxxx/prod-api/api_ability/xxx/inference-xxx/inferenceurl/xxxrewrite/v1

实际请求接口:

POST /v1/chat/completions

示例 curl 调用(可正常返回):

curl -X POST http://xxx.xxx.xxx.xxx/.../v1/chat/completions \
  -H "Authorization: Bearer xxx" \
  -H "Content-Type: application/json" \
  -d '{
        "model":"xxx",
        "messages":[{"role":"user","content":"hi"}]
      }'

返回 200 正常。


SQLBot 模型配置

Protocol:

OpenAI

API Domain:

http://xxx.xxx.xxx.xxx/.../v1

Model Name:

xxx

API Key:

xxx

错误日志

SQLBot 后端日志:

HTTP Request: POST http://xxx.xxx.xxx.xxx/.../v1/chat/completions "HTTP/1.1 401 Unauthorized"

openai.AuthenticationError: Error code: 401
{'code': 401, 'msg': '流程->API Key解析失败'}

调用栈:

File "/opt/sqlbot/app/apps/chat/task/llm.py", line xxxx
for chunk in sql_res

File ".../langchain_openai/chat_models/base.py", line xxxx
response = self.client.create(**payload)

行为差异

保存模型时调用:

/system/aimodel/status

接口调用 成功

实际聊天调用:

/api/v1/chat/question

接口返回 401


可能相关代码

SQLBot 中相关代码位置:

apps/ai_model/model_factory.py
apps/chat/task/llm.py

可能原因猜测:

1. LLMFactory.create_llm 使用了缓存

代码中:

@lru_cache(maxsize=32)
def create_llm(...)

可能导致:

  • API Key 或配置更新后
  • 运行阶段仍然使用旧实例

2. API Key 读取或格式问题

可能存在:

  • key 前后存在空格
  • key 被保存为 Bearer xxx
  • key 中存在换行符

3. get_default_config 解密逻辑

代码中:

if not db_model.api_domain.startswith("http"):
    db_model.api_domain = await sqlbot_decrypt(...)

解密逻辑依赖 startswith("http") 判断,可能导致:

  • 部分情况下 key / domain 未正确解密

期望行为

如果 模型配置校验成功,则实际聊天调用也应成功。


补充说明

该接口为 OpenAI ChatCompletion API 兼容实现,在以下客户端均测试正常:

  • curl
  • Python openai SDK
  • PowerShell Invoke-RestMethod

因此问题可能在 SQLBot 内部请求构造或配置缓存逻辑


问题

SQLBot 是否支持 完全自定义的 OpenAI 兼容 API endpoint

如果需要额外配置(例如 header 或 key 格式),是否有相关说明?

希望能得到一些建议或解决方案。

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.