-
Notifications
You must be signed in to change notification settings - Fork 6.9k
Closed
Labels
bugSomething isn't workingSomething isn't workingtriageIssue needs to be triaged/prioritizedIssue needs to be triaged/prioritized
Description
Bug Description
When creating a FunctionTool and using the Pydantic Field object to specify the "default" value, the default value is not set when calling the function. Somehow the type of the argument is pydantic.fields.FieldInfo
Version
lama-index 0.12.5
Steps to Reproduce
from pydantic import Field
from llama_index.core.tools import FunctionTool
from typing import Optional
def get_weather(
location: Optional[str] = Field(
default="Berlin"
),
) -> str:
"""Usfeful for getting the weather for a given location."""
if location == "Berlin":
return "nice weather in Berlin"
return "bad weather!"
tool = FunctionTool.from_defaults(get_weather)
> tool().content
'bad weather!'
> tool("Berlin").content
'nice weather in Berlin'
Relevant Logs/Tracbacks
This fixes it by the way:
from pydantic import Field
from pydantic.fields import FieldInfo
from llama_index.core.tools import FunctionTool
from typing import Optional
def get_weather(
location: Optional[str] = Field(
default="Berlin"
),
) -> str:
"""Usfeful for getting the weather for a given location."""
if isinstance(location, FieldInfo):
location = location.get_default()
if location == "Berlin":
return "nice weather in Berlin"
return "bad weather!"
tool = FunctionTool.from_defaults(get_weather)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingtriageIssue needs to be triaged/prioritizedIssue needs to be triaged/prioritized