diff --git a/libs/community/langchain_community/llms/mlx_pipeline.py b/libs/community/langchain_community/llms/mlx_pipeline.py index 8bc25f34a..952a3f7fc 100644 --- a/libs/community/langchain_community/llms/mlx_pipeline.py +++ b/libs/community/langchain_community/llms/mlx_pipeline.py @@ -156,7 +156,6 @@ def _call( temp: float = pipeline_kwargs.get("temp", 0.0) max_tokens: int = pipeline_kwargs.get("max_tokens", 100) verbose: bool = pipeline_kwargs.get("verbose", False) - formatter: Optional[Callable] = pipeline_kwargs.get("formatter", None) repetition_penalty: Optional[float] = pipeline_kwargs.get( "repetition_penalty", None ) @@ -178,7 +177,6 @@ def _call( prompt=prompt, max_tokens=max_tokens, verbose=verbose, - formatter=formatter, sampler=sampler, logits_processors=logits_processors, ) diff --git a/libs/community/tests/unit_tests/llms/test_mlx_pipeline_no_formatter_kwarg.py b/libs/community/tests/unit_tests/llms/test_mlx_pipeline_no_formatter_kwarg.py new file mode 100644 index 000000000..671cca531 --- /dev/null +++ b/libs/community/tests/unit_tests/llms/test_mlx_pipeline_no_formatter_kwarg.py @@ -0,0 +1,31 @@ +from langchain_community.llms.mlx_pipeline import MLXPipeline +from langchain_core.prompts import PromptTemplate + +def test_mlx_pipeline_no_formatter_kwarg(): + """Mimicking example code listed on https://python.langchain.com/docs/integrations/llms/mlx_pipelines/ + + To showcase issue with `formatter` keyword which is being passed to mlx-lm + generate function + """ + pipe = MLXPipeline.from_model_id( + "mlx-community/quantized-gemma-2b-it" + ) + + assert pipe, "Model not loaded" + + template = """Question: {question} + + Answer: Let's think step by step.""" + + prompt = PromptTemplate.from_template(template) + + chain = prompt | pipe + + question = "What is electroencephalography?" + + answer = chain.invoke({"question": question}) + + assert answer, "Answer was not generated" + + +