MMathisLab Cursor commited on
Commit ·
ee80f6e
1
Parent(s): f9d77a3
Improve HF ranking compatibility by enabling chat endpoint fallback.
Browse filesAllow scoring requests to try router chat completions after generate/completions so ranking can succeed on providers exposing chat-only interfaces.
Co-authored-by: Cursor <cursoragent@cursor.com>
- llm_service.py +9 -5
llm_service.py
CHANGED
|
@@ -18,9 +18,10 @@ logger = logging.getLogger(__name__)
|
|
| 18 |
# Router statuses that should trigger trying the next endpoint format.
|
| 19 |
_ROUTER_FALLBACK_STATUSES = (400, 404, 405, 415, 422)
|
| 20 |
_DEFAULT_FALLBACK_MODELS = (
|
| 21 |
-
"Qwen/Qwen2.5-32B-Instruct",
|
| 22 |
-
"meta-llama/Llama-3.1-70B-Instruct",
|
| 23 |
"Qwen/Qwen2.5-7B-Instruct",
|
|
|
|
|
|
|
|
|
|
| 24 |
)
|
| 25 |
_BIOMEDICAL_SYNONYMS = {
|
| 26 |
"kras": ["k-ras", "kras g12c", "kras g12d", "krasi"],
|
|
@@ -582,7 +583,7 @@ REASONING: [brief, natural explanation of why this score was assigned]"""
|
|
| 582 |
"""Score using Hugging Face Inference API (legacy method)"""
|
| 583 |
try:
|
| 584 |
response, _ = self._call_hf_router_api(
|
| 585 |
-
prompt, max_tokens=10, temperature=0.1, top_p=1.0, timeout=30, allow_chat_fallback=
|
| 586 |
)
|
| 587 |
response.raise_for_status()
|
| 588 |
generated_text = self._extract_text_from_hf_response(response.json())
|
|
@@ -599,7 +600,7 @@ REASONING: [brief, natural explanation of why this score was assigned]"""
|
|
| 599 |
return 0.5, "Hugging Face token missing. Add HUGGINGFACE_API_TOKEN in Space Secrets."
|
| 600 |
|
| 601 |
response, used_model = self._call_hf_router_api(
|
| 602 |
-
prompt, max_tokens=200, timeout=60, allow_chat_fallback=
|
| 603 |
)
|
| 604 |
|
| 605 |
if not response.ok:
|
|
@@ -615,7 +616,10 @@ REASONING: [brief, natural explanation of why this score was assigned]"""
|
|
| 615 |
if response.status_code == 429:
|
| 616 |
return 0.5, "Hugging Face rate limit reached (429). Please retry shortly."
|
| 617 |
if response.status_code in (400, 404, 422):
|
| 618 |
-
return 0.5,
|
|
|
|
|
|
|
|
|
|
| 619 |
|
| 620 |
return 0.5, f"Hugging Face API error {response.status_code}: {error_preview[:140]}"
|
| 621 |
|
|
|
|
| 18 |
# Router statuses that should trigger trying the next endpoint format.
|
| 19 |
_ROUTER_FALLBACK_STATUSES = (400, 404, 405, 415, 422)
|
| 20 |
_DEFAULT_FALLBACK_MODELS = (
|
|
|
|
|
|
|
| 21 |
"Qwen/Qwen2.5-7B-Instruct",
|
| 22 |
+
"mistralai/Mistral-7B-Instruct-v0.3",
|
| 23 |
+
"google/gemma-2-9b-it",
|
| 24 |
+
"meta-llama/Llama-3.1-8B-Instruct",
|
| 25 |
)
|
| 26 |
_BIOMEDICAL_SYNONYMS = {
|
| 27 |
"kras": ["k-ras", "kras g12c", "kras g12d", "krasi"],
|
|
|
|
| 583 |
"""Score using Hugging Face Inference API (legacy method)"""
|
| 584 |
try:
|
| 585 |
response, _ = self._call_hf_router_api(
|
| 586 |
+
prompt, max_tokens=10, temperature=0.1, top_p=1.0, timeout=30, allow_chat_fallback=True
|
| 587 |
)
|
| 588 |
response.raise_for_status()
|
| 589 |
generated_text = self._extract_text_from_hf_response(response.json())
|
|
|
|
| 600 |
return 0.5, "Hugging Face token missing. Add HUGGINGFACE_API_TOKEN in Space Secrets."
|
| 601 |
|
| 602 |
response, used_model = self._call_hf_router_api(
|
| 603 |
+
prompt, max_tokens=200, timeout=60, allow_chat_fallback=True
|
| 604 |
)
|
| 605 |
|
| 606 |
if not response.ok:
|
|
|
|
| 616 |
if response.status_code == 429:
|
| 617 |
return 0.5, "Hugging Face rate limit reached (429). Please retry shortly."
|
| 618 |
if response.status_code in (400, 404, 422):
|
| 619 |
+
return 0.5, (
|
| 620 |
+
f"Model/endpoint mismatch ({response.status_code}). "
|
| 621 |
+
"Set DEEPSEEK_MODEL or HF_FALLBACK_MODELS to router-supported models."
|
| 622 |
+
)
|
| 623 |
|
| 624 |
return 0.5, f"Hugging Face API error {response.status_code}: {error_preview[:140]}"
|
| 625 |
|