Home / Class/ SimpleRequestChain Class — langchain Architecture

SimpleRequestChain Class — langchain Architecture

Architecture documentation for the SimpleRequestChain class in openapi.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  7d9cd052_b35e_d7e6_3e3f_6be2efe55548["SimpleRequestChain"]
  f3cef70e_11b0_61c9_7ec0_7308f4b45056["Chain"]
  7d9cd052_b35e_d7e6_3e3f_6be2efe55548 -->|extends| f3cef70e_11b0_61c9_7ec0_7308f4b45056
  a34d3b0d_246d_bf4f_cf5f_c38a4937926e["openapi.py"]
  7d9cd052_b35e_d7e6_3e3f_6be2efe55548 -->|defined in| a34d3b0d_246d_bf4f_cf5f_c38a4937926e
  c75a993b_3d82_0d79_d660_cfa8f4787812["input_keys()"]
  7d9cd052_b35e_d7e6_3e3f_6be2efe55548 -->|method| c75a993b_3d82_0d79_d660_cfa8f4787812
  5cc45a33_e7fc_27d8_3a44_958d57fd435c["output_keys()"]
  7d9cd052_b35e_d7e6_3e3f_6be2efe55548 -->|method| 5cc45a33_e7fc_27d8_3a44_958d57fd435c
  3402face_2006_2c1f_b057_c685f2190047["_call()"]
  7d9cd052_b35e_d7e6_3e3f_6be2efe55548 -->|method| 3402face_2006_2c1f_b057_c685f2190047

Relationship Graph

Source Code

libs/langchain/langchain_classic/chains/openai_functions/openapi.py lines 201–249

class SimpleRequestChain(Chain):
    """Chain for making a simple request to an API endpoint."""

    request_method: Callable
    """Method to use for making the request."""
    output_key: str = "response"
    """Key to use for the output of the request."""
    input_key: str = "function"
    """Key to use for the input of the request."""

    @property
    @override
    def input_keys(self) -> list[str]:
        return [self.input_key]

    @property
    @override
    def output_keys(self) -> list[str]:
        return [self.output_key]

    def _call(
        self,
        inputs: dict[str, Any],
        run_manager: CallbackManagerForChainRun | None = None,
    ) -> dict[str, Any]:
        """Run the logic of this chain and return the output."""
        _run_manager = run_manager or CallbackManagerForChainRun.get_noop_manager()
        name = inputs[self.input_key].pop("name")
        args = inputs[self.input_key].pop("arguments")
        _pretty_name = get_colored_text(name, "green")
        _pretty_args = get_colored_text(json.dumps(args, indent=2), "green")
        _text = f"Calling endpoint {_pretty_name} with arguments:\n" + _pretty_args
        _run_manager.on_text(_text)
        api_response: Response = self.request_method(name, args)
        if api_response.status_code != requests.codes.ok:
            response = (
                f"{api_response.status_code}: {api_response.reason}"
                f"\nFor {name} "
                f"Called with args: {args.get('params', '')}"
            )
        else:
            try:
                response = api_response.json()
            except JSONDecodeError:
                response = api_response.text
            except Exception:
                _logger.exception("Unexpected error parsing response as JSON")
                response = api_response.text
        return {self.output_key: response}

Extends

Frequently Asked Questions

What is the SimpleRequestChain class?
SimpleRequestChain is a class in the langchain codebase, defined in libs/langchain/langchain_classic/chains/openai_functions/openapi.py.
Where is SimpleRequestChain defined?
SimpleRequestChain is defined in libs/langchain/langchain_classic/chains/openai_functions/openapi.py at line 201.
What does SimpleRequestChain extend?
SimpleRequestChain extends Chain.

Analyze Your Own Codebase

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

Try Supermodel Free