Home / File/ function_calling.py — langchain Source File

function_calling.py — langchain Source File

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

File python CoreAbstractions RunnableInterface 16 imports 17 functions 2 classes

Entity Profile

Dependency Diagram

graph LR
  344b2838_87a8_d5dc_b550_fdb443ff6c4e["function_calling.py"]
  efd68536_3a44_76e4_ec2a_0ec171774703["collections"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> efd68536_3a44_76e4_ec2a_0ec171774703
  614e7b9f_ed51_0780_749c_ff40b74963fc["inspect"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> 614e7b9f_ed51_0780_749c_ff40b74963fc
  2a7f66a7_8738_3d47_375b_70fcaa6ac169["logging"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> 2a7f66a7_8738_3d47_375b_70fcaa6ac169
  05bcd40b_a309_8a05_c2c6_59e32e113cf5["types"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> 05bcd40b_a309_8a05_c2c6_59e32e113cf5
  8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3
  23a1b3c0_d78f_7f2f_8eca_25b1ca6a84a6["uuid.py"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> 23a1b3c0_d78f_7f2f_8eca_25b1ca6a84a6
  91721f45_4909_e489_8c1f_084f8bd87145["typing_extensions"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> 91721f45_4909_e489_8c1f_084f8bd87145
  930c470c_e6f2_ae5f_1129_48cfd16873f9["pydantic.py"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> 930c470c_e6f2_ae5f_1129_48cfd16873f9
  63ae09a2_4a67_3eaf_7888_b0fd11776a0e["pydantic.v1"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> 63ae09a2_4a67_3eaf_7888_b0fd11776a0e
  3fb4a817_a89e_f069_6543_9c06e36d4338["langchain_core"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> 3fb4a817_a89e_f069_6543_9c06e36d4338
  b19a8b7e_fbee_95b1_65b8_509a1ed3cad7["langchain_core._api"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> b19a8b7e_fbee_95b1_65b8_509a1ed3cad7
  d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> d758344f_537f_649e_f467_b9d7442e86df
  bd8d173a_d62b_a088_32e2_8c51fb93e490["langchain_core.utils.json_schema"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> bd8d173a_d62b_a088_32e2_8c51fb93e490
  1014fe78_cb2c_fde4_a624_ae899aa7ca8e["langchain_core.utils.pydantic"]
  344b2838_87a8_d5dc_b550_fdb443ff6c4e --> 1014fe78_cb2c_fde4_a624_ae899aa7ca8e
  style 344b2838_87a8_d5dc_b550_fdb443ff6c4e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Methods for creating function specs in the style of OpenAI Functions."""

from __future__ import annotations

import collections
import inspect
import logging
import types
import typing
import uuid
from typing import (
    TYPE_CHECKING,
    Annotated,
    Any,
    Literal,
    Union,
    cast,
    get_args,
    get_origin,
    get_type_hints,
)

import typing_extensions
from pydantic import BaseModel
from pydantic.v1 import BaseModel as BaseModelV1
from pydantic.v1 import Field as Field_v1
from pydantic.v1 import create_model as create_model_v1
from typing_extensions import TypedDict, is_typeddict

import langchain_core
from langchain_core._api import beta
from langchain_core.messages import AIMessage, BaseMessage, HumanMessage, ToolMessage
from langchain_core.utils.json_schema import dereference_refs
from langchain_core.utils.pydantic import is_basemodel_subclass

if TYPE_CHECKING:
    from collections.abc import Callable, Mapping

    from langchain_core.tools import BaseTool

logger = logging.getLogger(__name__)

PYTHON_TO_JSON_TYPES = {
    "str": "string",
    "int": "integer",
    "float": "number",
    "bool": "boolean",
}

_ORIGIN_MAP: dict[type, Any] = {
    dict: dict,
    list: list,
    tuple: tuple,
    set: set,
    collections.abc.Iterable: typing.Iterable,
    collections.abc.Mapping: typing.Mapping,
    collections.abc.Sequence: typing.Sequence,
    collections.abc.MutableMapping: typing.MutableMapping,
}
# Add UnionType mapping for Python 3.10+
// ... (753 more lines)

Subdomains

Dependencies

  • collections
  • collections.abc
  • inspect
  • langchain_core
  • langchain_core._api
  • langchain_core.messages
  • langchain_core.tools
  • langchain_core.utils.json_schema
  • langchain_core.utils.pydantic
  • logging
  • pydantic.py
  • pydantic.v1
  • types
  • typing
  • typing_extensions
  • uuid.py

Frequently Asked Questions

What does function_calling.py do?
function_calling.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 function_calling.py?
function_calling.py defines 17 function(s): _ORIGIN_MAP, _convert_any_typed_dicts_to_pydantic, _convert_json_schema_to_openai_function, _convert_pydantic_to_openai_function, _convert_python_function_to_openai_function, _convert_typed_dict_to_openai_function, _format_tool_to_openai_function, _get_python_function_name, _parse_google_docstring, _py_38_safe_origin, and 7 more.
What does function_calling.py depend on?
function_calling.py imports 16 module(s): collections, collections.abc, inspect, langchain_core, langchain_core._api, langchain_core.messages, langchain_core.tools, langchain_core.utils.json_schema, and 8 more.
Where is function_calling.py in the architecture?
function_calling.py is located at libs/core/langchain_core/utils/function_calling.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/core/langchain_core/utils).

Analyze Your Own Codebase

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

Try Supermodel Free