Home / File/ openapi.py — langchain Source File

openapi.py — langchain Source File

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

File python CoreAbstractions RunnableInterface 20 imports 5 functions 1 classes

Entity Profile

Dependency Diagram

graph LR
  f2307213_6a7e_e815_bd7b_cb5137206faa["openapi.py"]
  7025b240_fdc3_cf68_b72f_f41dac94566b["json"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> 7025b240_fdc3_cf68_b72f_f41dac94566b
  2a7f66a7_8738_3d47_375b_70fcaa6ac169["logging"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> 2a7f66a7_8738_3d47_375b_70fcaa6ac169
  67ec3255_645e_8b6e_1eff_1eb3c648ed95["re"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> 67ec3255_645e_8b6e_1eff_1eb3c648ed95
  efd68536_3a44_76e4_ec2a_0ec171774703["collections"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> efd68536_3a44_76e4_ec2a_0ec171774703
  cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  792c09b7_7372_31d2_e29c_dc98949aa3c2["requests"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> 792c09b7_7372_31d2_e29c_dc98949aa3c2
  b19a8b7e_fbee_95b1_65b8_509a1ed3cad7["langchain_core._api"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> b19a8b7e_fbee_95b1_65b8_509a1ed3cad7
  f3bc7443_c889_119d_0744_aacc3620d8d2["langchain_core.callbacks"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> f3bc7443_c889_119d_0744_aacc3620d8d2
  ba43b74d_3099_7e1c_aac3_cf594720469e["langchain_core.language_models"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> ba43b74d_3099_7e1c_aac3_cf594720469e
  89a4ade4_215f_cae5_8190_9505303396df["langchain_core.output_parsers.openai_functions"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> 89a4ade4_215f_cae5_8190_9505303396df
  e6b4f61e_7b98_6666_3641_26b069517d4a["langchain_core.prompts"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> e6b4f61e_7b98_6666_3641_26b069517d4a
  75b56223_6cf5_b347_8586_de20156157a1["langchain_core.utils.input"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> 75b56223_6cf5_b347_8586_de20156157a1
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  f2307213_6a7e_e815_bd7b_cb5137206faa --> 91721f45_4909_e489_8c1f_084f8bd87145
  style f2307213_6a7e_e815_bd7b_cb5137206faa fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

from __future__ import annotations

import json
import logging
import re
from collections import defaultdict
from collections.abc import Callable
from typing import TYPE_CHECKING, Any

import requests
from langchain_core._api import deprecated
from langchain_core.callbacks import CallbackManagerForChainRun
from langchain_core.language_models import BaseLanguageModel
from langchain_core.output_parsers.openai_functions import JsonOutputFunctionsParser
from langchain_core.prompts import BasePromptTemplate, ChatPromptTemplate
from langchain_core.utils.input import get_colored_text
from requests import JSONDecodeError, Response
from typing_extensions import override

from langchain_classic.chains.base import Chain
from langchain_classic.chains.llm import LLMChain
from langchain_classic.chains.sequential import SequentialChain

if TYPE_CHECKING:
    from langchain_community.utilities.openapi import OpenAPISpec
    from openapi_pydantic import Parameter

_logger = logging.getLogger(__name__)


def _format_url(url: str, path_params: dict) -> str:
    expected_path_param = re.findall(r"{(.*?)}", url)
    new_params = {}
    for param in expected_path_param:
        clean_param = param.lstrip(".;").rstrip("*")
        val = path_params[clean_param]
        if isinstance(val, list):
            if param[0] == ".":
                sep = "." if param[-1] == "*" else ","
                new_val = "." + sep.join(val)
            elif param[0] == ";":
                sep = f"{clean_param}=" if param[-1] == "*" else ","
                new_val = f"{clean_param}=" + sep.join(val)
            else:
                new_val = ",".join(val)
        elif isinstance(val, dict):
            kv_sep = "=" if param[-1] == "*" else ","
            kv_strs = [kv_sep.join((k, v)) for k, v in val.items()]
            if param[0] == ".":
                sep = "."
                new_val = "."
            elif param[0] == ";":
                sep = ";"
                new_val = ";"
            else:
                sep = ","
                new_val = ""
            new_val += sep.join(kv_strs)
        elif param[0] == ".":
            new_val = f".{val}"
// ... (368 more lines)

Subdomains

Dependencies

  • collections
  • collections.abc
  • json
  • langchain_classic.chains.base
  • langchain_classic.chains.llm
  • langchain_classic.chains.sequential
  • langchain_community.tools
  • langchain_community.utilities.openapi
  • langchain_core._api
  • langchain_core.callbacks
  • langchain_core.language_models
  • langchain_core.output_parsers.openai_functions
  • langchain_core.prompts
  • langchain_core.utils.input
  • logging
  • openapi_pydantic
  • re
  • requests
  • typing
  • typing_extensions

Frequently Asked Questions

What does openapi.py do?
openapi.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in openapi.py?
openapi.py defines 5 function(s): _format_url, _openapi_params_to_json_schema, get_openapi_chain, langchain_community, openapi_spec_to_openai_fn.
What does openapi.py depend on?
openapi.py imports 20 module(s): collections, collections.abc, json, langchain_classic.chains.base, langchain_classic.chains.llm, langchain_classic.chains.sequential, langchain_community.tools, langchain_community.utilities.openapi, and 12 more.
Where is openapi.py in the architecture?
openapi.py is located at libs/langchain/langchain_classic/chains/openai_functions/openapi.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/langchain_classic/chains/openai_functions).

Analyze Your Own Codebase

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

Try Supermodel Free