Fix: api-key issue for xinference. (#6490)

### What problem does this PR solve?

#2792

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
Kevin Hu 2025-03-25 15:01:13 +08:00 committed by GitHub
parent 384b6549a6
commit 60c3a253ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -208,7 +208,7 @@ class YoudaoRerank(DefaultRerank):
class XInferenceRerank(Base): class XInferenceRerank(Base):
def __init__(self, key="xxxxxxx", model_name="", base_url=""): def __init__(self, key="x", model_name="", base_url=""):
if base_url.find("/v1") == -1: if base_url.find("/v1") == -1:
base_url = urljoin(base_url, "/v1/rerank") base_url = urljoin(base_url, "/v1/rerank")
if base_url.find("/rerank") == -1: if base_url.find("/rerank") == -1:
@ -217,9 +217,10 @@ class XInferenceRerank(Base):
self.base_url = base_url self.base_url = base_url
self.headers = { self.headers = {
"Content-Type": "application/json", "Content-Type": "application/json",
"accept": "application/json", "accept": "application/json"
"Authorization": f"Bearer {key}"
} }
if key and key != "x":
self.headers["Authorization"] = f"Bearer {key}"
def similarity(self, query: str, texts: list): def similarity(self, query: str, texts: list):
if len(texts) == 0: if len(texts) == 0: