mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-20 11:31:58 +00:00
langchain_google_vertexai:Enable the use of langchain's built-in tools in Gemini's function calling (#16341)
- **Issue:** This is a PR about #16340 <!-- Thank you for contributing to LangChain! Please title your PR "<package>: <description>", where <package> is whichever of langchain, community, core, experimental, etc. is being modified. Replace this entire comment with: - **Description:** a description of the change, - **Issue:** the issue # it fixes if applicable, - **Dependencies:** any dependencies required for this change, - **Twitter handle:** we announce bigger features on Twitter. If your PR gets announced, and you'd like a mention, we'll gladly shout you out! Please make sure your PR is passing linting and testing before submitting. Run `make format`, `make lint` and `make test` from the root of the package you've modified to check this locally. See contribution guidelines for more information on how to write/run tests, lint, etc: https://python.langchain.com/docs/contributing/ If you're adding a new integration, please include: 1. a test for the integration, preferably unit tests that do not rely on network access, 2. an example notebook showing its use. It lives in `docs/docs/integrations` directory. If no one reviews your PR within a few days, please @-mention one of @baskaryan, @eyurtsev, @hwchase17. --> Co-authored-by: yuhei.tsunoda <yuhei.tsunoda@brainpad.co.jp>
This commit is contained in:
parent
1445ac95e8
commit
54f90fc6bc
@ -5,7 +5,7 @@ from langchain_core.exceptions import OutputParserException
|
|||||||
from langchain_core.output_parsers import BaseOutputParser
|
from langchain_core.output_parsers import BaseOutputParser
|
||||||
from langchain_core.outputs import ChatGeneration, Generation
|
from langchain_core.outputs import ChatGeneration, Generation
|
||||||
from langchain_core.pydantic_v1 import BaseModel
|
from langchain_core.pydantic_v1 import BaseModel
|
||||||
from langchain_core.tools import Tool
|
from langchain_core.tools import BaseTool
|
||||||
from langchain_core.utils.function_calling import FunctionDescription
|
from langchain_core.utils.function_calling import FunctionDescription
|
||||||
from langchain_core.utils.json_schema import dereference_refs
|
from langchain_core.utils.json_schema import dereference_refs
|
||||||
from vertexai.preview.generative_models import ( # type: ignore
|
from vertexai.preview.generative_models import ( # type: ignore
|
||||||
@ -39,7 +39,7 @@ def _format_pydantic_to_vertex_function(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _format_tool_to_vertex_function(tool: Tool) -> FunctionDescription:
|
def _format_tool_to_vertex_function(tool: BaseTool) -> FunctionDescription:
|
||||||
"Format tool into the Vertex function API."
|
"Format tool into the Vertex function API."
|
||||||
if tool.args_schema:
|
if tool.args_schema:
|
||||||
schema = dereference_refs(tool.args_schema.schema())
|
schema = dereference_refs(tool.args_schema.schema())
|
||||||
@ -75,12 +75,12 @@ def _format_tool_to_vertex_function(tool: Tool) -> FunctionDescription:
|
|||||||
|
|
||||||
|
|
||||||
def _format_tools_to_vertex_tool(
|
def _format_tools_to_vertex_tool(
|
||||||
tools: List[Union[Tool, Type[BaseModel]]],
|
tools: List[Union[BaseTool, Type[BaseModel]]],
|
||||||
) -> List[VertexTool]:
|
) -> List[VertexTool]:
|
||||||
"Format tool into the Vertex Tool instance."
|
"Format tool into the Vertex Tool instance."
|
||||||
function_declarations = []
|
function_declarations = []
|
||||||
for tool in tools:
|
for tool in tools:
|
||||||
if isinstance(tool, Tool):
|
if isinstance(tool, BaseTool):
|
||||||
func = _format_tool_to_vertex_function(tool)
|
func = _format_tool_to_vertex_function(tool)
|
||||||
else:
|
else:
|
||||||
func = _format_pydantic_to_vertex_function(tool)
|
func = _format_pydantic_to_vertex_function(tool)
|
||||||
|
Loading…
Reference in New Issue
Block a user