Home / File/ test_openapi.py — langchain Source File

test_openapi.py — langchain Source File

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

Entity Profile

Dependency Diagram

graph LR
  2594edb2_53ad_8129_0bfd_2bdfec20f696["test_openapi.py"]
  7025b240_fdc3_cf68_b72f_f41dac94566b["json"]
  2594edb2_53ad_8129_0bfd_2bdfec20f696 --> 7025b240_fdc3_cf68_b72f_f41dac94566b
  120e2591_3e15_b895_72b6_cb26195e40a6["pytest"]
  2594edb2_53ad_8129_0bfd_2bdfec20f696 --> 120e2591_3e15_b895_72b6_cb26195e40a6
  9b4ec80f_d8de_a6e0_4f16_67ba56685088["langchain_classic.chains"]
  2594edb2_53ad_8129_0bfd_2bdfec20f696 --> 9b4ec80f_d8de_a6e0_4f16_67ba56685088
  c5cc8b71_d222_257f_f5bf_1974ae2a0043["langchain_classic.chains.openai_functions.openapi"]
  2594edb2_53ad_8129_0bfd_2bdfec20f696 --> c5cc8b71_d222_257f_f5bf_1974ae2a0043
  0b28cff6_d823_1571_d2bb_ec61508cc89c["langchain_openai"]
  2594edb2_53ad_8129_0bfd_2bdfec20f696 --> 0b28cff6_d823_1571_d2bb_ec61508cc89c
  style 2594edb2_53ad_8129_0bfd_2bdfec20f696 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import json

import pytest

from langchain_classic.chains import OpenAIModerationChain
from langchain_classic.chains.openai_functions.openapi import get_openapi_chain

api_spec = {
    "openapi": "3.0.0",
    "info": {"title": "JSONPlaceholder API", "version": "1.0.0"},
    "servers": [{"url": "https://jsonplaceholder.typicode.com"}],
    "paths": {
        "/posts": {
            "get": {
                "summary": "Get posts",
                "parameters": [
                    {
                        "name": "_limit",
                        "in": "query",
                        "required": False,
                        "schema": {"type": "integer", "example": 2},
                        "description": "Limit the number of results",
                    },
                ],
            },
        },
    },
}


@pytest.mark.requires("openapi_pydantic")
@pytest.mark.requires("langchain_openai")
def test_openai_openapi_chain() -> None:
    from langchain_openai import ChatOpenAI

    llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
    chain = get_openapi_chain(json.dumps(api_spec), llm)
    output = chain.invoke({"query": "Fetch the top two posts."})
    assert len(output["response"]) == 2


@pytest.mark.requires("openai")
def test_openai_moderation_chain_instantiation() -> None:
    """Test OpenAIModerationChain."""
    api_key = "foo"

    moderation = OpenAIModerationChain(openai_api_key=api_key)

    assert isinstance(moderation, OpenAIModerationChain)

Subdomains

Dependencies

  • json
  • langchain_classic.chains
  • langchain_classic.chains.openai_functions.openapi
  • langchain_openai
  • pytest

Frequently Asked Questions

What does test_openapi.py do?
test_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 test_openapi.py?
test_openapi.py defines 2 function(s): test_openai_moderation_chain_instantiation, test_openai_openapi_chain.
What does test_openapi.py depend on?
test_openapi.py imports 5 module(s): json, langchain_classic.chains, langchain_classic.chains.openai_functions.openapi, langchain_openai, pytest.
Where is test_openapi.py in the architecture?
test_openapi.py is located at libs/langchain/tests/integration_tests/chains/openai_functions/test_openapi.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain/tests/integration_tests/chains/openai_functions).

Analyze Your Own Codebase

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

Try Supermodel Free