mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 23:41:12 +08:00
fix base_url handling in HuggingfaceRerank (#14555)
### What problem does this PR solve? HuggingfaceRerank.post() unconditionally prepends `http://` to base_url, which already contains a protocol. This creates invalid URLs like http://http://127.0.0.1:8080/rerank, breaking all requests. The fix normalizes URL handling to match the rest of the codebase, removing redunant `http://`. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Related Issues - #7318 - #7796 --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
@@ -407,16 +407,21 @@ class HuggingfaceRerank(Base):
|
||||
_FACTORY_NAME = "HuggingFace"
|
||||
|
||||
@staticmethod
|
||||
def post(query: str, texts: list, url="127.0.0.1"):
|
||||
def post(query: str, texts: list, url: str = "http://127.0.0.1"):
|
||||
exc = None
|
||||
scores = [0 for _ in range(len(texts))]
|
||||
batch_size = 8
|
||||
for i in range(0, len(texts), batch_size):
|
||||
try:
|
||||
res = requests.post(
|
||||
f"http://{url}/rerank", headers={"Content-Type": "application/json"}, json={"query": query, "texts": texts[i : i + batch_size], "raw_scores": False, "truncate": True}
|
||||
)
|
||||
endpoint = (url or "").rstrip("/")
|
||||
|
||||
if not endpoint.endswith("/rerank"):
|
||||
endpoint = f"{endpoint}/rerank"
|
||||
res = requests.post(
|
||||
endpoint,
|
||||
headers = {"Content-Type": "application/json"},
|
||||
json = {"query": query, "texts": texts[i: i + batch_size], "raw_scores": False, "truncate": True},
|
||||
)
|
||||
for o in res.json():
|
||||
scores[o["index"] + i] = o["score"]
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user