fix: resolve linting issues
This commit is contained in:
parent
a81da6788d
commit
0c33a24d8f
3 changed files with 13 additions and 7 deletions
|
|
@ -36,7 +36,7 @@ class FuncSchema:
|
|||
strict_json_schema: bool = True
|
||||
"""Whether the JSON schema is in strict mode. We **strongly** recommend setting this to True,
|
||||
as it increases the likelihood of correct JSON input."""
|
||||
|
||||
|
||||
def to_call_args(self, data: BaseModel) -> tuple[list[Any], dict[str, Any]]:
|
||||
"""
|
||||
Converts validated data from the Pydantic model into (args, kwargs), suitable for calling
|
||||
|
|
|
|||
|
|
@ -189,7 +189,8 @@ def function_tool(
|
|||
failure_error_function: If provided, use this function to generate an error message when
|
||||
the tool call fails. The error message is sent to the LLM. If you pass None, then no
|
||||
error message will be sent and instead an Exception will be raised.
|
||||
strict_mode: If False, parameters with default values become optional in the function schema.
|
||||
strict_mode: If False, parameters with default values become optional in the
|
||||
function schema.
|
||||
"""
|
||||
|
||||
def _create_function_tool(the_func: ToolFunction[...]) -> FunctionTool:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import asyncio
|
||||
import json
|
||||
from typing import Any
|
||||
from typing import Any, Optional
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ async def test_no_error_on_invalid_json_async():
|
|||
|
||||
|
||||
@function_tool(strict_mode=False)
|
||||
def optional_param_function(a: int, b: int | None = None) -> str:
|
||||
def optional_param_function(a: int, b: Optional[int] = None) -> str:
|
||||
if b is None:
|
||||
return f"{a}_no_b"
|
||||
return f"{a}_{b}"
|
||||
|
|
@ -165,17 +165,22 @@ async def test_optional_param_function():
|
|||
|
||||
|
||||
@function_tool(strict_mode=False)
|
||||
def multiple_optional_params_function(x: int = 42, y: str = "hello", z: int | None = None) -> str:
|
||||
def multiple_optional_params_function(
|
||||
x: int = 42,
|
||||
y: str = "hello",
|
||||
z: Optional[int] = None,
|
||||
) -> str:
|
||||
if z is None:
|
||||
return f"{x}_{y}_no_z"
|
||||
return f"{x}_{y}_{z}"
|
||||
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_multiple_optional_params_function():
|
||||
tool = multiple_optional_params_function
|
||||
|
||||
input_data = {}
|
||||
input_data: dict[str,Any] = {}
|
||||
output = await tool.on_invoke_tool(ctx_wrapper(), json.dumps(input_data))
|
||||
assert output == "42_hello_no_z"
|
||||
|
||||
|
|
@ -185,4 +190,4 @@ async def test_multiple_optional_params_function():
|
|||
|
||||
input_data = {"x": 10, "y": "world", "z": 99}
|
||||
output = await tool.on_invoke_tool(ctx_wrapper(), json.dumps(input_data))
|
||||
assert output == "10_world_99"
|
||||
assert output == "10_world_99"
|
||||
|
|
|
|||
Loading…
Reference in a new issue