Skip to content

The agent engineering platform.

community[patch]: huggingface hub character removal bug fix (#16233)

mikeFore49d32af72ce54
diff --git a/libs/community/langchain_community/llms/huggingface_hub.py b/libs/community/langchain_community/llms/huggingface_hub.py
index 32facc244b..10eb8eb7a0 100644
--- a/libs/community/langchain_community/llms/huggingface_hub.py
+++ b/libs/community/langchain_community/llms/huggingface_hub.py
@@ -112,8 +112,10 @@ class HuggingFaceHub(LLM):
if "error" in response:
raise ValueError(f"Error raised by inference API: {response['error']}")
if self.client.task == "text-generation":
- # Text generation return includes the starter text.
- text = response[0]["generated_text"][len(prompt) :]
+ # Text generation sometimes return includes the starter text.
+ text = response[0]["generated_text"]
+ if text.startswith(prompt):
+ text = response[0]["generated_text"][len(prompt) :]
elif self.client.task == "text2text-generation":
text = response[0]["generated_text"]
elif self.client.task == "summarization":