Skip to content

The agent engineering platform.

chore(langchain-classic): add deprecations (#36826)

ccurme1749eb860113
diff --git a/libs/langchain/langchain_classic/chains/openai_functions/openapi.py b/libs/langchain/langchain_classic/chains/openai_functions/openapi.py
index c29c111e38..f04fbd4975 100644
--- a/libs/langchain/langchain_classic/chains/openai_functions/openapi.py
+++ b/libs/langchain/langchain_classic/chains/openai_functions/openapi.py
@@ -83,6 +83,14 @@ def _openapi_params_to_json_schema(params: list[Parameter], spec: OpenAPISpec) -
return {"type": "object", "properties": properties, "required": required}
+@deprecated(
+ since="1.0.4",
+ message=(
+ "This function is deprecated and will be removed in a future version. "
+ "Use LLM tool calling features directly with an HTTP client instead."
+ ),
+ removal="2.0",
+)
def openapi_spec_to_openai_fn(
spec: OpenAPISpec,
) -> tuple[list[dict[str, Any]], Callable]:
@@ -198,6 +206,14 @@ def openapi_spec_to_openai_fn(
return functions, default_call_api
+@deprecated(
+ since="1.0.4",
+ message=(
+ "This class is deprecated and will be removed in a future version. "
+ "Use LLM tool calling features directly with an HTTP client instead."
+ ),
+ removal="2.0",
+)
class SimpleRequestChain(Chain):
"""Chain for making a simple request to an API endpoint."""
@@ -252,11 +268,10 @@ class SimpleRequestChain(Chain):
@deprecated(
since="0.2.13",
message=(
- "This function is deprecated and will be removed in langchain 1.0. "
- "See API reference for replacement: "
- "https://api.python.langchain.com/en/latest/chains/langchain.chains.openai_functions.openapi.get_openapi_chain.html"
+ "This function is deprecated and will be removed in a future version. "
+ "Use LLM tool calling features directly with an HTTP client instead."
),
- removal="1.0",
+ removal="2.0",
)
def get_openapi_chain(
spec: OpenAPISpec | str,
@@ -271,82 +286,9 @@ def get_openapi_chain(
) -> SequentialChain:
r"""Create a chain for querying an API from a OpenAPI spec.
- Note: this class is deprecated. See below for a replacement implementation.
- The benefits of this implementation are:
-
- - Uses LLM tool calling features to encourage properly-formatted API requests;
- - Includes async support.
-
- ```python
- from typing import Any
-
- from langchain_classic.chains.openai_functions.openapi import openapi_spec_to_openai_fn
- from langchain_community.utilities.openapi import OpenAPISpec
- from langchain_core.prompts import ChatPromptTemplate
- from langchain_openai import ChatOpenAI
-
- # Define API spec. Can be JSON or YAML
- api_spec = \"\"\"
- {
- "openapi": "3.1.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"
- }
- ]
- }
- }
- }
- }
- \"\"\"
-
- parsed_spec = OpenAPISpec.from_text(api_spec)
- openai_fns, call_api_fn = openapi_spec_to_openai_fn(parsed_spec)
- tools = [
- {"type": "function", "function": fn}
- for fn in openai_fns
- ]
-
- prompt = ChatPromptTemplate.from_template(
- "Use the provided APIs to respond to this user query:\\n\\n{query}"
- )
- model = ChatOpenAI(model="gpt-4o-mini", temperature=0).bind_tools(tools)
-
- def _execute_tool(message) -> Any:
- if tool_calls := message.tool_calls:
- tool_call = message.tool_calls[0]
- response = call_api_fn(name=tool_call["name"], fn_args=tool_call["args"])
- response.raise_for_status()
- return response.json()
- else:
- return message.content
-
- chain = prompt | model | _execute_tool
- ```
-
- ```python
- response = chain.invoke({"query": "Get me top two posts."})
- ```
+ !!! warning "Deprecated"
+ This function and all related utilities in this module are deprecated.
+ Use LLM tool calling features directly with an HTTP client instead.
Args:
spec: OpenAPISpec or url/file/text string corresponding to one.
@@ -360,7 +302,7 @@ def get_openapi_chain(
llm_chain_kwargs: LLM chain additional keyword arguments.
**kwargs: Additional keyword arguments to pass to the chain.
- """ # noqa: E501
+ """
try:
from langchain_community.utilities.openapi import OpenAPISpec
except ImportError as e: