mirror of https://github.com/hwchase17/langchain
Implement better reprs for Runnables (#11175)
``` ChatPromptTemplate(messages=[SystemMessagePromptTemplate(prompt=PromptTemplate(input_variables=[], template='You are a nice assistant.')), HumanMessagePromptTemplate(prompt=PromptTemplate(input_variables=['question'], template='{question}'))]) | RunnableLambda(lambda x: x) | { chat: FakeListChatModel(responses=["i'm a chatbot"]), llm: FakeListLLM(responses=["i'm a textbot"]) } ``` <!-- Thank you for contributing to LangChain! Replace this entire comment with: - **Description:** a description of the change, - **Issue:** the issue # it fixes (if applicable), - **Dependencies:** any dependencies required for this change, - **Tag maintainer:** for a quicker response, tag the relevant maintainer (see below), - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out! Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` to check this locally. See contribution guidelines for more information on how to write/run tests, lint, etc: https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md If you're adding a new integration, please include: 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. It lives in `docs/extras` directory. If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17. -->pull/11218/head
commit
61b5942adf
File diff suppressed because one or more lines are too long
@ -0,0 +1,39 @@
|
||||
import sys
|
||||
from typing import Callable
|
||||
|
||||
import pytest
|
||||
|
||||
from langchain.schema.runnable.utils import (
|
||||
get_lambda_source,
|
||||
indent_lines_after_first,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.skipif(
|
||||
sys.version_info < (3, 9), reason="Requires python version >= 3.9 to run."
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"func, expected_source",
|
||||
[
|
||||
(lambda x: x * 2, "lambda x: x * 2"),
|
||||
(lambda a, b: a + b, "lambda a, b: a + b"),
|
||||
(lambda x: x if x > 0 else 0, "lambda x: x if x > 0 else 0"),
|
||||
],
|
||||
)
|
||||
def test_get_lambda_source(func: Callable, expected_source: str) -> None:
|
||||
"""Test get_lambda_source function"""
|
||||
source = get_lambda_source(func)
|
||||
assert source == expected_source
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"text,prefix,expected_output",
|
||||
[
|
||||
("line 1\nline 2\nline 3", "1", "line 1\n line 2\n line 3"),
|
||||
("line 1\nline 2\nline 3", "ax", "line 1\n line 2\n line 3"),
|
||||
],
|
||||
)
|
||||
def test_indent_lines_after_first(text: str, prefix: str, expected_output: str) -> None:
|
||||
"""Test indent_lines_after_first function"""
|
||||
indented_text = indent_lines_after_first(text, prefix)
|
||||
assert indented_text == expected_output
|
Loading…
Reference in New Issue