Skip to content

Commit

Permalink
x
Browse files Browse the repository at this point in the history
  • Loading branch information
eyurtsev committed Sep 3, 2024
1 parent ae5a574 commit 509ed89
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions libs/core/tests/unit_tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import inspect
import json
from langchain_core.tools import tool
from typing import Annotated, get_type_hints
import inspect


import sys
import textwrap
import threading
Expand Down Expand Up @@ -1737,6 +1742,8 @@ def test__is_message_content_block(obj: Any, expected: bool) -> None:
assert _is_message_content_block(obj) is expected




@pytest.mark.parametrize(
("obj", "expected"),
[
Expand Down Expand Up @@ -1871,6 +1878,22 @@ class ModelD(ModelC, Generic[D]):
assert actual == expected


def test_tool_annotations_preserved() -> None:
"""Test that annotations are preserved when creating a tool."""
@tool
def my_tool(val: int, other_val: Annotated[dict, "my annotation"]) -> str:
"""Tool docstring."""
return other_val

schema = my_tool.get_input_schema()

expected_type_hints = {
name: hint
for name, hint in my_tool.func.__annotations__.items()
if name in inspect.signature(my_tool.func).parameters
}
assert schema.__annotations__ == expected_type_hints

@pytest.mark.skipif(PYDANTIC_MAJOR_VERSION != 2, reason="Testing pydantic v2.")
def test_tool_args_schema_pydantic_v2_with_metadata() -> None:
from pydantic import BaseModel as BaseModelV2
Expand Down

0 comments on commit 509ed89

Please sign in to comment.