Kevin Hu
commited on
Commit
·
9cbbedc
1
Parent(s):
5ec7450
fix SILICONFLOW rerank error (#2980)
Browse files### What problem does this PR solve?
#2977
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- api/apps/chunk_app.py +21 -2
- rag/llm/rerank_model.py +3 -0
api/apps/chunk_app.py
CHANGED
|
@@ -320,9 +320,28 @@ def knowledge_graph():
|
|
| 320 |
for id in sres.ids[:2]:
|
| 321 |
ty = sres.field[id]["knowledge_graph_kwd"]
|
| 322 |
try:
|
| 323 |
-
|
| 324 |
except Exception as e:
|
| 325 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 326 |
|
| 327 |
return get_json_result(data=obj)
|
| 328 |
|
|
|
|
| 320 |
for id in sres.ids[:2]:
|
| 321 |
ty = sres.field[id]["knowledge_graph_kwd"]
|
| 322 |
try:
|
| 323 |
+
content_json = json.loads(sres.field[id]["content_with_weight"])
|
| 324 |
except Exception as e:
|
| 325 |
+
continue
|
| 326 |
+
|
| 327 |
+
if ty == 'mind_map':
|
| 328 |
+
node_dict = {}
|
| 329 |
+
|
| 330 |
+
def repeat_deal(content_json, node_dict):
|
| 331 |
+
if 'id' in content_json:
|
| 332 |
+
if content_json['id'] in node_dict:
|
| 333 |
+
node_name = content_json['id']
|
| 334 |
+
content_json['id'] += f"({node_dict[content_json['id']]})"
|
| 335 |
+
node_dict[node_name] += 1
|
| 336 |
+
else:
|
| 337 |
+
node_dict[content_json['id']] = 1
|
| 338 |
+
if 'children' in content_json and content_json['children']:
|
| 339 |
+
for item in content_json['children']:
|
| 340 |
+
repeat_deal(item, node_dict)
|
| 341 |
+
|
| 342 |
+
repeat_deal(content_json, node_dict)
|
| 343 |
+
|
| 344 |
+
obj[ty] = content_json
|
| 345 |
|
| 346 |
return get_json_result(data=obj)
|
| 347 |
|
rag/llm/rerank_model.py
CHANGED
|
@@ -344,6 +344,9 @@ class SILICONFLOWRerank(Base):
|
|
| 344 |
self.base_url, json=payload, headers=self.headers
|
| 345 |
).json()
|
| 346 |
rank = np.zeros(len(texts), dtype=float)
|
|
|
|
|
|
|
|
|
|
| 347 |
for d in response["results"]:
|
| 348 |
rank[d["index"]] = d["relevance_score"]
|
| 349 |
return (
|
|
|
|
| 344 |
self.base_url, json=payload, headers=self.headers
|
| 345 |
).json()
|
| 346 |
rank = np.zeros(len(texts), dtype=float)
|
| 347 |
+
if "results" not in response:
|
| 348 |
+
return rank, 0
|
| 349 |
+
|
| 350 |
for d in response["results"]:
|
| 351 |
rank[d["index"]] = d["relevance_score"]
|
| 352 |
return (
|