Home / Function/ _get_input_output() — langchain Function Reference

_get_input_output() — langchain Function Reference

Architecture documentation for the _get_input_output() function in chat_memory.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  14089ed0_ac37_0fa3_6d93_2e792001c895["_get_input_output()"]
  48fb025a_9570_1ddd_d527_ec72c1ae6a6f["BaseChatMemory"]
  14089ed0_ac37_0fa3_6d93_2e792001c895 -->|defined in| 48fb025a_9570_1ddd_d527_ec72c1ae6a6f
  bc73f18b_fe97_9059_903b_9103d9fc0492["save_context()"]
  bc73f18b_fe97_9059_903b_9103d9fc0492 -->|calls| 14089ed0_ac37_0fa3_6d93_2e792001c895
  ef8b300b_59ad_92fa_9e4b_3572f54c5811["asave_context()"]
  ef8b300b_59ad_92fa_9e4b_3572f54c5811 -->|calls| 14089ed0_ac37_0fa3_6d93_2e792001c895
  style 14089ed0_ac37_0fa3_6d93_2e792001c895 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/memory/chat_memory.py lines 43–72

    def _get_input_output(
        self,
        inputs: dict[str, Any],
        outputs: dict[str, str],
    ) -> tuple[str, str]:
        if self.input_key is None:
            prompt_input_key = get_prompt_input_key(inputs, self.memory_variables)
        else:
            prompt_input_key = self.input_key
        if self.output_key is None:
            if len(outputs) == 1:
                output_key = next(iter(outputs.keys()))
            elif "output" in outputs:
                output_key = "output"
                warnings.warn(
                    f"'{self.__class__.__name__}' got multiple output keys:"
                    f" {outputs.keys()}. The default 'output' key is being used."
                    f" If this is not desired, please manually set 'output_key'.",
                    stacklevel=3,
                )
            else:
                msg = (
                    f"Got multiple output keys: {outputs.keys()}, cannot "
                    f"determine which to store in memory. Please set the "
                    f"'output_key' explicitly."
                )
                raise ValueError(msg)
        else:
            output_key = self.output_key
        return inputs[prompt_input_key], outputs[output_key]

Domain

Subdomains

Frequently Asked Questions

What does _get_input_output() do?
_get_input_output() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/memory/chat_memory.py.
Where is _get_input_output() defined?
_get_input_output() is defined in libs/langchain/langchain_classic/memory/chat_memory.py at line 43.
What calls _get_input_output()?
_get_input_output() is called by 2 function(s): asave_context, save_context.

Analyze Your Own Codebase

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

Try Supermodel Free