Home / File/ test_chat.py — langchain Source File

test_chat.py — langchain Source File

Architecture documentation for test_chat.py, a python file in the langchain codebase. 2 imports, 0 dependents.

File python CoreAbstractions MessageSchema 2 imports 3 functions

Entity Profile

Dependency Diagram

graph LR
  12adc08b_0468_682f_c083_0c0c45df05c3["test_chat.py"]
  80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b["langchain_core.agents"]
  12adc08b_0468_682f_c083_0c0c45df05c3 --> 80d582c5_7cc3_ac96_2742_3dbe1cbd4e2b
  877cb291_dfed_f8ac_1313_a40a0e86b931["langchain_classic.agents.chat.output_parser"]
  12adc08b_0468_682f_c083_0c0c45df05c3 --> 877cb291_dfed_f8ac_1313_a40a0e86b931
  style 12adc08b_0468_682f_c083_0c0c45df05c3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Unittests for langchain.agents.chat package."""

from langchain_core.agents import AgentAction

from langchain_classic.agents.chat.output_parser import ChatOutputParser

output_parser = ChatOutputParser()


def get_action_and_input(text: str) -> tuple[str, str]:
    output = output_parser.parse(text)
    if isinstance(output, AgentAction):
        return output.tool, str(output.tool_input)
    return "Final Answer", output.return_values["output"]


def test_parse_with_language() -> None:
    llm_output = """I can use the `foo` tool to achieve the goal.

    Action:
    ```json
    {
      "action": "foo",
      "action_input": "bar"
    }
    ```
    """
    action, action_input = get_action_and_input(llm_output)
    assert action == "foo"
    assert action_input == "bar"


def test_parse_without_language() -> None:
    llm_output = """I can use the `foo` tool to achieve the goal.

    Action:
    ```
    {
      "action": "foo",
      "action_input": "bar"
    }
    ```
    """
    action, action_input = get_action_and_input(llm_output)
    assert action == "foo"
    assert action_input == "bar"

Subdomains

Dependencies

  • langchain_classic.agents.chat.output_parser
  • langchain_core.agents

Frequently Asked Questions

What does test_chat.py do?
test_chat.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_chat.py?
test_chat.py defines 3 function(s): get_action_and_input, test_parse_with_language, test_parse_without_language.
What does test_chat.py depend on?
test_chat.py imports 2 module(s): langchain_classic.agents.chat.output_parser, langchain_core.agents.
Where is test_chat.py in the architecture?
test_chat.py is located at libs/langchain/tests/unit_tests/agents/test_chat.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/langchain/tests/unit_tests/agents).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free