Skip to content

.register_tool() should accept Tools #171

@gadenbuie

Description

@gadenbuie
import chatlas

def get_weather_forecast(
    lat: float, lon: float, location_name: str
) -> dict[str, str]:
    """Get the weather forecast for a location."""
    # Mocked weather data for demonstration purposes
    return {"temperature_2m": 18, "condition": "Partly Cloudy"}
    
weather_tool = chatlas.Tool.from_func(get_weather_forecast)

chat = chatlas.ChatOpenAI()
chat.register_tool(weather_tool)
#> Argument of type "Tool" cannot be assigned to parameter "func" of type "((...) -> Any) | ((...) -> Awaitable[Any])" in function "register_tool"
#>   Type "Tool" is not assignable to type "((...) -> Any) | ((...) -> Awaitable[Any])"
#>     Type "Tool" is not assignable to type "(...) -> Any"
#>     Type "Tool" is not assignable to type "(...) -> Awaitable[Any]"PyrightreportArgumentType

You can get around this with a chat.set_tools() dance, which is not ideal.

chat.set_tools([*chat.get_tools(), weather_tool])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions