AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

openai_embedding模型在AstrBot4.21和4.22版本下无法通过测试并出现报错

Open Branwen07 opened this issue 8 months ago • 9 comments

What happened / 发生了什么

Image

比如text-embedding-3-large模型,连接测试通过,但出现'str' object has no attribute 'data'报错,无法构建知识库。

Reproduce / 如何复现?

更新astrbot4.21和4.22版本 导入openai旗下的embedding嵌入模型

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

4.21/4.22、docker

OS

Linux

Logs / 报错日志

'str' object has no attribute 'data'

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • [ ] Yes!

Code of Conduct

Branwen07 avatar Mar 24 '26 07:03 Branwen07

Hi @Branwen07! I'm Dosu and I’m helping the AstrBot team.

这个问题的根本原因是 PR #6669 移除了 OpenAI Embedding API Base URL 的自动 /v1 补全逻辑。当 embedding_api_base 配置缺少 /v1 路径时,请求会发送到错误的端点,导致 API 返回错误响应,进而触发 'str' object has no attribute 'data' 错误。

临时解决方案:在 embedding_api_base 中手动添加 /v1:

  • 例如:https://api.openai.com/v1(而不是 https://api.openai.com)

修复进展:已有 PR #6863 修复此问题,等待合并。

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about AstrBot Share Dosu with your team

dosubot[bot] avatar Mar 24 '26 07:03 dosubot[bot]

@Branwen07 你看上面的答复可以解决你的问题吗

Soulter avatar Mar 24 '26 08:03 Soulter

@Branwen07 你看上面的答复可以解决你的问题吗

您好,手动加入/v1也不能解决问题,会提示测试成功但是依旧旁边会显示感叹号并提示Error code: 400-{'error: {message':'Model "Qwen/Qwen3-Embedding-0.6B" does not support matryoshka representation, changing output dimensions willead to poor results., 'type': 'BadRequestError, 'param': None, 'code': 400}),我的是硅基流动的Qwen3emb模型

xinxiuzhu avatar Mar 24 '26 14:03 xinxiuzhu

Image 我没有碰到这个问题唉? Image

h4rm00n avatar Mar 25 '26 02:03 h4rm00n

Image 我没有碰到这个问题唉? Image

请问您的版本号是多少?我是在4.22.0测试的

xinxiuzhu avatar Mar 25 '26 04:03 xinxiuzhu

Image 我没有碰到这个问题唉? Image

请问您的版本号是多少?我是在4.22.0测试的

我的也是4.22.0,但这个不是新配置的,是从老的版本继承下来的。

h4rm00n avatar Mar 25 '26 07:03 h4rm00n

@Branwen07 你看上面的答复可以解决你的问题吗

已解决

Branwen07 avatar Mar 28 '26 06:03 Branwen07

我也遇到了类似情况,加载火山Embedding失败,然后了解到前文提到的

“这个问题的根本原因是 https://github.com/AstrBotDevs/AstrBot/pull/6669 移除了 OpenAI Embedding API Base URL 的自动 /v1 补全逻辑。当 embedding_api_base 配置缺少 /v1 路径时,请求会发送到错误的端点,导致 API 返回错误响应,进而触发 'str' object has no attribute 'data' 错误。”

的情况后,让AstrBot自己修。它反馈道: 问题定位: 核心代码在 /AstrBot/astrbot/core/provider/sources/openai_embedding_source.py 第28-36行:

Python

api_base = ( provider_config.get("embedding_api_base", "https://api.openai.com/v1") .strip() .removesuffix("/") .removesuffix("/embeddings") ) if api_base and not api_base.endswith("/v1") and not api_base.endswith("/v4"): api_base = api_base + "/v1" # <-- 问题在这 你的火山引擎 URL https://ark.cn-beijing.volces.com/api/coding/v3 的处理流程:

.removesuffix("/") → .../v3

.removesuffix("/embeddings") → .../v3 (无变化)

判断 not endswith("/v1") → True

判断 not endswith("/v4") → True

→ 强制追加 /v1 → 结果变成 https://ark.cn-beijing.volces.com/api/coding/v3/v1 ❌

最终请求发到 .../v3/v1/embeddings,404 返回非标准响应,触发 'str' object has no attribute 'data'。

修复方案 只需在一行加一个条件,第32行改为:

Python

if api_base and not api_base.endswith("/v1") and not api_base.endswith("/v3") and not api_base.endswith("/v4"): 这样火山引擎的 /v3 结尾 URL 就不会被错误追加 /v1。

希望可以给大家提供帮助。

Hayashihigashi avatar May 06 '26 13:05 Hayashihigashi

版本:v4.25.5 Image

vllm 部署

nohup vllm serve /data/models/bge-m3 \
    --port 8001 \
    --gpu-memory-utilization 0.06 \
    --served-model-name emb > vllm.emb.log 2>&1 &

vllm 内报错

(APIServer pid=4078970) ValueError: Model "emb" does not support matryoshka representation, changing output dimensions will lead to poor results.
^C

momomobinx avatar Jun 12 '26 01:06 momomobinx