Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions libs/community/langchain_community/llms/mlx_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

import logging
from typing import Any, Callable, Iterator, List, Mapping, Optional

Check failure on line 4 in libs/community/langchain_community/llms/mlx_pipeline.py

View workflow job for this annotation

GitHub Actions / cd libs/community / Python 3.11

Ruff (F401)

langchain_community/llms/mlx_pipeline.py:4:25: F401 `typing.Callable` imported but unused

from langchain_core.callbacks import CallbackManagerForLLMRun
from langchain_core.language_models.llms import LLM
Expand Down Expand Up @@ -156,7 +156,6 @@
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
)
Expand All @@ -178,7 +177,6 @@
prompt=prompt,
max_tokens=max_tokens,
verbose=verbose,
formatter=formatter,
sampler=sampler,
logits_processors=logits_processors,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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"



Loading