Commit bbe28c0
committed
fix(chat_model): raise clear ModelException when BaiduYiyan key is not a JSON object (infiniflow#17389)
The BaiduYiyan / Qianfan provider in rag/llm/chat_model.py:1189 does an
unguarded `json.loads(key)` followed by `.get("yiyan_ak")` and
`.get("yiyan_sk")`. The provider REQUIRES a JSON key (per
conf/models/baidu.json) but a user pasting a plain Baidu API key like
"bce-v3/ALTAK-.../..." (the most common mistake: copying from the Qianfan
console into a BaiduYiyan field) would crash with
`json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)`
from inside rag/llm internals, with no indication of what the user did
wrong.
This is the BaiduYiyan equivalent of:
- infiniflow#17204 / PR infiniflow#17215 (Azure-OpenAI)
- infiniflow#17373 / PR infiniflow#17377 (AWS Bedrock)
Add a parallel helper to rag.llm.key_utils that mirrors the Bedrock fix
shape:
```
def _resolve_qianfan_credentials(key):
# Accepts dict or JSON-string-encoded dict. Returns the dict.
# On non-JSON input (e.g. plain "bce-v3/..."):
# raises ModelException with the required schema in the message
# (yiyan_ak + yiyan_sk, conf/models/baidu.json reference).
# On JSON top-level non-dict (list, string, number):
# raises ModelException rather than letting the caller hit
# AttributeError on .get("yiyan_ak").
```
Wire BaiduYiyanChat.__init__ (chat_model.py:1189) through the helper
instead of the bare `json.loads(key)`. The downstream
`key.get("yiyan_ak", "")` / `.get("yiyan_sk", "")` calls are
unchanged.
No public API change. No data-model change. No migration.
Fixes infiniflow#17389.1 parent c87aa3b commit bbe28c0
2 files changed
Lines changed: 69 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
| |||
1335 | 1339 | | |
1336 | 1340 | | |
1337 | 1341 | | |
1338 | | - | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
1339 | 1348 | | |
1340 | 1349 | | |
1341 | 1350 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
| |||
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
0 commit comments