[Python] How to type a dict argument in tool function of LangChain?

Discussão em 'Python' iniciado por Stack, Dezembro 8, 2024.

  1. Stack

    Stack Membro Participativo

    I'm using Gemini-1.5-flash model from langchain_google_genai.

    When I try to bind this tool to the ChatGoogleGenerativeAI instance,

    from langchain_core.tools import tool


    @tool
    def test(a: int, b: dict) -> str:
    """
    test
    """
    return f"a: {a}, b: {b}"


    the error occurs like below

    400 * GenerateContentRequest.tools[0].function_declarations[8].parameters.properties.properties: should be non-empty for OBJECT type

    WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
    E0000 00:00:1733636038.240366 20980 init.cc:229] grpc_wait_for_shutdown_with_timeout() timed out.


    I searched around for hours and no article found about typing dict argument for langchain tool function.

    I need help


    I tried...

    • removed b: dict from signature and the error didn't occurred.
    • changed typing b: dict to b: dict[str, Any] and the same error occurred.

    Continue reading...

Compartilhe esta Página