Spaces:
Runtime error
Runtime error
Respect strict Hugging Face API mode
Browse files
app/generation/providers/huggingface_provider.py
CHANGED
|
@@ -39,11 +39,6 @@ class HuggingFaceLLMProvider(BaseLLMProvider):
|
|
| 39 |
if api_mode == "chat":
|
| 40 |
answer = self.call_chat_completion_api(prompt)
|
| 41 |
|
| 42 |
-
if answer:
|
| 43 |
-
return clean_hosted_output(answer)
|
| 44 |
-
|
| 45 |
-
answer = self.call_hf_inference_model_api(prompt)
|
| 46 |
-
|
| 47 |
if answer:
|
| 48 |
return clean_hosted_output(answer)
|
| 49 |
|
|
@@ -52,11 +47,6 @@ class HuggingFaceLLMProvider(BaseLLMProvider):
|
|
| 52 |
if api_mode == "inference":
|
| 53 |
answer = self.call_hf_inference_model_api(prompt)
|
| 54 |
|
| 55 |
-
if answer:
|
| 56 |
-
return clean_hosted_output(answer)
|
| 57 |
-
|
| 58 |
-
answer = self.call_chat_completion_api(prompt)
|
| 59 |
-
|
| 60 |
if answer:
|
| 61 |
return clean_hosted_output(answer)
|
| 62 |
|
|
|
|
| 39 |
if api_mode == "chat":
|
| 40 |
answer = self.call_chat_completion_api(prompt)
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
if answer:
|
| 43 |
return clean_hosted_output(answer)
|
| 44 |
|
|
|
|
| 47 |
if api_mode == "inference":
|
| 48 |
answer = self.call_hf_inference_model_api(prompt)
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
if answer:
|
| 51 |
return clean_hosted_output(answer)
|
| 52 |
|
scripts/patch_hf_strict_mode.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pathlib import Path
|
| 2 |
+
|
| 3 |
+
path = Path("app/generation/providers/huggingface_provider.py")
|
| 4 |
+
text = path.read_text(encoding="utf-8")
|
| 5 |
+
|
| 6 |
+
old = ''' if api_mode == "chat":
|
| 7 |
+
answer = self.call_chat_completion_api(prompt)
|
| 8 |
+
|
| 9 |
+
if answer:
|
| 10 |
+
return clean_hosted_output(answer)
|
| 11 |
+
|
| 12 |
+
answer = self.call_hf_inference_model_api(prompt)
|
| 13 |
+
|
| 14 |
+
if answer:
|
| 15 |
+
return clean_hosted_output(answer)
|
| 16 |
+
|
| 17 |
+
return ""
|
| 18 |
+
|
| 19 |
+
if api_mode == "inference":
|
| 20 |
+
answer = self.call_hf_inference_model_api(prompt)
|
| 21 |
+
|
| 22 |
+
if answer:
|
| 23 |
+
return clean_hosted_output(answer)
|
| 24 |
+
|
| 25 |
+
answer = self.call_chat_completion_api(prompt)
|
| 26 |
+
|
| 27 |
+
if answer:
|
| 28 |
+
return clean_hosted_output(answer)
|
| 29 |
+
|
| 30 |
+
return ""
|
| 31 |
+
'''
|
| 32 |
+
|
| 33 |
+
new = ''' if api_mode == "chat":
|
| 34 |
+
answer = self.call_chat_completion_api(prompt)
|
| 35 |
+
|
| 36 |
+
if answer:
|
| 37 |
+
return clean_hosted_output(answer)
|
| 38 |
+
|
| 39 |
+
return ""
|
| 40 |
+
|
| 41 |
+
if api_mode == "inference":
|
| 42 |
+
answer = self.call_hf_inference_model_api(prompt)
|
| 43 |
+
|
| 44 |
+
if answer:
|
| 45 |
+
return clean_hosted_output(answer)
|
| 46 |
+
|
| 47 |
+
return ""
|
| 48 |
+
'''
|
| 49 |
+
|
| 50 |
+
if old not in text:
|
| 51 |
+
print("Could not find old fallback block. No change made.")
|
| 52 |
+
else:
|
| 53 |
+
text = text.replace(old, new)
|
| 54 |
+
path.write_text(text, encoding="utf-8")
|
| 55 |
+
print("Strict HF_API_MODE patch applied successfully.")
|