The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
community[minor]: Add support for translation in HuggingFacePipeline (#19190)
Nikhil Kumar635b3372bdd3
diff --git a/libs/community/langchain_community/llms/huggingface_pipeline.py b/libs/community/langchain_community/llms/huggingface_pipeline.pyindex f95a994d68..e989cd16da 100644--- a/libs/community/langchain_community/llms/huggingface_pipeline.py+++ b/libs/community/langchain_community/llms/huggingface_pipeline.py@@ -11,7 +11,12 @@ from langchain_core.pydantic_v1 import ExtraDEFAULT_MODEL_ID = "gpt2"DEFAULT_TASK = "text-generation"-VALID_TASKS = ("text2text-generation", "text-generation", "summarization")+VALID_TASKS = (+ "text2text-generation",+ "text-generation",+ "summarization",+ "translation",+)DEFAULT_BATCH_SIZE = 4logger = logging.getLogger(__name__)@@ -121,7 +126,7 @@ class HuggingFacePipeline(BaseLLM):model = AutoModelForCausalLM.from_pretrained(model_id, **_model_kwargs)- elif task in ("text2text-generation", "summarization"):+ elif task in ("text2text-generation", "summarization", "translation"):if backend == "openvino":try:from optimum.intel.openvino import OVModelForSeq2SeqLM@@ -260,8 +265,6 @@ class HuggingFacePipeline(BaseLLM):# Process batch of promptsresponses = self.pipeline(batch_prompts,- stop_sequence=stop,- return_full_text=False,**pipeline_kwargs,)@@ -277,6 +280,8 @@ class HuggingFacePipeline(BaseLLM):text = response["generated_text"]elif self.pipeline.task == "summarization":text = response["summary_text"]+ elif self.pipeline.task in "translation":+ text = response["translation_text"]else:raise ValueError(f"Got invalid task {self.pipeline.task}, "