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:
Igor Ilinskii
2026-05-11 05:04:40 +03:00
committed by GitHub
parent ed01ac9994
commit 889aba6a32

View File

@@ -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: