core[patch]: export tool output parsers from langchain_core.output_parsers (#23305)

These currently read off AIMessage.tool_calls, and only fall back to
OpenAI parsing if tool calls aren't populated.

Importing these from `openai_tools` (e.g., in our [tool calling
docs](https://python.langchain.com/v0.2/docs/how_to/tool_calling/#tool-calls))
can lead to confusion.

After landing, would need to release core and update docs.
This commit is contained in:
ccurme 2024-06-25 14:40:42 -04:00 committed by GitHub
parent 7e9e69c758
commit 730c551819
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View File

@ -24,6 +24,11 @@ from langchain_core.output_parsers.list import (
MarkdownListOutputParser, MarkdownListOutputParser,
NumberedListOutputParser, NumberedListOutputParser,
) )
from langchain_core.output_parsers.openai_tools import (
JsonOutputKeyToolsParser,
JsonOutputToolsParser,
PydanticToolsParser,
)
from langchain_core.output_parsers.pydantic import PydanticOutputParser from langchain_core.output_parsers.pydantic import PydanticOutputParser
from langchain_core.output_parsers.string import StrOutputParser from langchain_core.output_parsers.string import StrOutputParser
from langchain_core.output_parsers.transform import ( from langchain_core.output_parsers.transform import (
@ -47,4 +52,7 @@ __all__ = [
"XMLOutputParser", "XMLOutputParser",
"JsonOutputParser", "JsonOutputParser",
"PydanticOutputParser", "PydanticOutputParser",
"JsonOutputToolsParser",
"JsonOutputKeyToolsParser",
"PydanticToolsParser",
] ]

View File

@ -5,7 +5,7 @@ from typing import Any, Dict, List, Optional, Type
from langchain_core.exceptions import OutputParserException from langchain_core.exceptions import OutputParserException
from langchain_core.messages import AIMessage, InvalidToolCall from langchain_core.messages import AIMessage, InvalidToolCall
from langchain_core.output_parsers import BaseCumulativeTransformOutputParser from langchain_core.output_parsers.transform import BaseCumulativeTransformOutputParser
from langchain_core.outputs import ChatGeneration, Generation from langchain_core.outputs import ChatGeneration, Generation
from langchain_core.pydantic_v1 import BaseModel, ValidationError from langchain_core.pydantic_v1 import BaseModel, ValidationError
from langchain_core.utils.json import parse_partial_json from langchain_core.utils.json import parse_partial_json

View File

@ -15,6 +15,9 @@ EXPECTED_ALL = [
"XMLOutputParser", "XMLOutputParser",
"JsonOutputParser", "JsonOutputParser",
"PydanticOutputParser", "PydanticOutputParser",
"JsonOutputToolsParser",
"JsonOutputKeyToolsParser",
"PydanticToolsParser",
] ]