core[patch]: add InjectedToolArg annotation (#24279)

```python
from typing_extensions import Annotated
from langchain_core.tools import tool, InjectedToolArg
from langchain_anthropic import ChatAnthropic

@tool
def multiply(x: int, y: int, not_for_model: Annotated[dict, InjectedToolArg]) -> str:
    """multiply."""
    return x * y 

ChatAnthropic(model='claude-3-sonnet-20240229',).bind_tools([multiply]).invoke('5 times 3').tool_calls
'''
-> [{'name': 'multiply',
  'args': {'x': 5, 'y': 3},
  'id': 'toolu_01Y1QazYWhu4R8vF4hF4z9no',
  'type': 'tool_call'}]
'''
```

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com>
This commit is contained in:
William FH
2024-07-17 15:28:40 -07:00
committed by GitHub
parent 80f3d48195
commit c5a07e2dd8
5 changed files with 660 additions and 136 deletions

View File

@@ -89,6 +89,10 @@ def convert_to_ollama_tool(tool: Any) -> Dict:
if _is_pydantic_class(tool):
schema = tool.construct().schema()
name = schema["title"]
elif isinstance(tool, BaseTool):
schema = tool.tool_call_schema.schema()
name = tool.get_name()
description = tool.description
elif _is_pydantic_object(tool):
schema = tool.get_input_schema().schema()
name = tool.get_name()