langchain/libs/core/langchain_core/utils
ccurme 4bb391fd4e
core[patch]: remove deprecated functions from tool binding hotpath (#29015)
(Inspired by https://github.com/langchain-ai/langchain/issues/26918)

We rely on some deprecated public functions in the hot path for tool
binding (`convert_pydantic_to_openai_function`,
`convert_python_function_to_openai_function`, and
`format_tool_to_openai_function`). My understanding is that what is
deprecated is not the functionality they implement, but use of them in
the public API -- we expect to continue to rely on them.

Here we update these functions to be private and not deprecated. We keep
the public, deprecated functions as simple wrappers that can be safely
deleted.

The `@deprecated` wrapper adds considerable latency due to its use of
the `inspect` module. This update speeds up `bind_tools` by a factor of
~100x:

Before:

![Screenshot 2025-01-03 at 11 22
55 AM](https://github.com/user-attachments/assets/94b1c433-ce12-406f-b64c-ca7103badfe0)

After:

![Screenshot 2025-01-03 at 11 23
41 AM](https://github.com/user-attachments/assets/02d0deab-82e4-45ca-8cc7-a20b91a5b5db)

---------

Co-authored-by: Erick Friis <erick@langchain.dev>
2025-01-03 19:29:01 +00:00
..
__init__.py core,integrations[minor]: Dont error on fields in model_kwargs (#27110) 2024-10-04 11:30:27 -07:00
_merge.py core: Add ruff rules for error messages (EM) (#26965) 2024-10-07 22:12:28 +00:00
aiter.py core: Add ruff rules for error messages (EM) (#26965) 2024-10-07 22:12:28 +00:00
env.py core: Add ruff rules for error messages (EM) (#26965) 2024-10-07 22:12:28 +00:00
formatting.py core: Add ruff rules for error messages (EM) (#26965) 2024-10-07 22:12:28 +00:00
function_calling.py core[patch]: remove deprecated functions from tool binding hotpath (#29015) 2025-01-03 19:29:01 +00:00
html.py core: Put Python version as a project requirement so it is considered by ruff (#26608) 2024-09-18 14:37:57 +00:00
image.py core[patch]: update image util err msg (#27803) 2024-10-31 10:56:43 -07:00
input.py core: Put Python version as a project requirement so it is considered by ruff (#26608) 2024-09-18 14:37:57 +00:00
interactive_env.py core[patch]: simple prompt pretty printing (#15968) 2024-01-12 21:08:51 -05:00
iter.py core: Put Python version as a project requirement so it is considered by ruff (#26608) 2024-09-18 14:37:57 +00:00
json_schema.py core: Add ruff rules for error messages (EM) (#26965) 2024-10-07 22:12:28 +00:00
json.py core: Add ruff rules for error messages (EM) (#26965) 2024-10-07 22:12:28 +00:00
loading.py core[patch]: Add B(bugbear) ruff rules (#25520) 2024-08-28 07:09:29 +00:00
mustache.py core: Add ruff rules for error messages (EM) (#26965) 2024-10-07 22:12:28 +00:00
pydantic.py core[patch]: remove redundant imports (#28861) 2024-12-23 10:31:23 -05:00
strings.py core: Put Python version as a project requirement so it is considered by ruff (#26608) 2024-09-18 14:37:57 +00:00
usage.py core[patch]: utils for adding/subtracting usage metadata (#27203) 2024-10-08 13:15:33 -07:00
utils.py core: Add various ruff rules (#26836) 2024-10-07 22:30:27 +00:00