Home / File/ test_openai_functions.py — langchain Source File

test_openai_functions.py — langchain Source File

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

File python LangChainCore ApiManagement 8 imports 5 functions 3 classes

Entity Profile

Dependency Diagram

graph LR
  051794f3_743e_b482_fc72_029694e0fa16["test_openai_functions.py"]
  9d14ea65_8b2e_6721_a947_acc89905651f["json"]
  051794f3_743e_b482_fc72_029694e0fa16 --> 9d14ea65_8b2e_6721_a947_acc89905651f
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  051794f3_743e_b482_fc72_029694e0fa16 --> feec1ec4_6917_867b_d228_b134d0ff8099
  f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"]
  051794f3_743e_b482_fc72_029694e0fa16 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba
  dd5e7909_a646_84f1_497b_cae69735550e["pydantic"]
  051794f3_743e_b482_fc72_029694e0fa16 --> dd5e7909_a646_84f1_497b_cae69735550e
  049d69ec_d53a_d170_b6fa_35c395793702["langchain_core.exceptions"]
  051794f3_743e_b482_fc72_029694e0fa16 --> 049d69ec_d53a_d170_b6fa_35c395793702
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  051794f3_743e_b482_fc72_029694e0fa16 --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  2b2663e7_3c78_e2fb_75f2_99a68ca124a7["langchain_core.output_parsers.openai_functions"]
  051794f3_743e_b482_fc72_029694e0fa16 --> 2b2663e7_3c78_e2fb_75f2_99a68ca124a7
  4382dc25_6fba_324a_49e2_e9742d579385["langchain_core.outputs"]
  051794f3_743e_b482_fc72_029694e0fa16 --> 4382dc25_6fba_324a_49e2_e9742d579385
  style 051794f3_743e_b482_fc72_029694e0fa16 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

import json
from typing import Any

import pytest
from pydantic import BaseModel

from langchain_core.exceptions import OutputParserException
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage
from langchain_core.output_parsers.openai_functions import (
    JsonOutputFunctionsParser,
    PydanticOutputFunctionsParser,
)
from langchain_core.outputs import ChatGeneration


def test_json_output_function_parser() -> None:
    """Test the JSON output function parser is configured with robust defaults."""
    message = AIMessage(
        content="This is a test message",
        additional_kwargs={
            "function_call": {
                "name": "function_name",
                "arguments": '{"arg1": "code\ncode"}',
            }
        },
    )
    chat_generation = ChatGeneration(message=message)

    # Full output
    # Test that the parsers defaults are configured to parse in non-strict mode
    parser = JsonOutputFunctionsParser(args_only=False)
    result = parser.parse_result([chat_generation])
    assert result == {"arguments": {"arg1": "code\ncode"}, "name": "function_name"}

    # Args only
    parser = JsonOutputFunctionsParser(args_only=True)
    result = parser.parse_result([chat_generation])
    assert result == {"arg1": "code\ncode"}

    # Verify that the original message is not modified
    assert message.additional_kwargs == {
        "function_call": {
            "name": "function_name",
            "arguments": '{"arg1": "code\ncode"}',
        }
    }


@pytest.mark.parametrize(
    "config",
    [
        {
            "args_only": False,
            "strict": False,
            "args": '{"arg1": "value1"}',
            "result": {"arguments": {"arg1": "value1"}, "name": "function_name"},
            "exception": None,
        },
        {
            "args_only": True,
// ... (137 more lines)

Domain

Subdomains

Classes

Dependencies

  • json
  • langchain_core.exceptions
  • langchain_core.messages
  • langchain_core.output_parsers.openai_functions
  • langchain_core.outputs
  • pydantic
  • pytest
  • typing

Frequently Asked Questions

What does test_openai_functions.py do?
test_openai_functions.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in test_openai_functions.py?
test_openai_functions.py defines 5 function(s): test_exceptions_raised_while_parsing, test_json_output_function_parser, test_json_output_function_parser_strictness, test_pydantic_output_functions_parser, test_pydantic_output_functions_parser_multiple_schemas.
What does test_openai_functions.py depend on?
test_openai_functions.py imports 8 module(s): json, langchain_core.exceptions, langchain_core.messages, langchain_core.output_parsers.openai_functions, langchain_core.outputs, pydantic, pytest, typing.
Where is test_openai_functions.py in the architecture?
test_openai_functions.py is located at libs/core/tests/unit_tests/output_parsers/test_openai_functions.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/core/tests/unit_tests/output_parsers).

Analyze Your Own Codebase

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

Try Supermodel Free