[Python] Failed to use model_dump to serialize <class...

Discussão em 'Python' iniciado por Stack, Janeiro 29, 2025.

  1. Stack

    Stack Membro Participativo

    Failed to use model_dump to serialize <class 'langchain_community.tools.tavily_search.tool.TavilySearchResults'> to JSON: PydanticSerializationError(Unable to serialize unknown type: <class 'pydantic._internal._model_construction.ModelMetaclass'>)

    I am working on integrating LangChain tools, specifically using ArxivQueryRun from the langchain_community.tools package. However, I am encountering the following errors when I try to bind tools to my LLM:

    BadRequestError: Error code: 400 - {'error': {'message': "'tools.0.type' : property 'type' is missing", 'type': 'invalid_request_error'}}

    Here is the relevant code snippet:

    from langchain_community.utilities import ArxivAPIWrapper
    from langchain_community.tools import ArxivQueryRun

    # Initialize the Arxiv wrapper and tool
    arxiv_wrapper = ArxivAPIWrapper(top_k_results=1, doc_content_chars_max=300)
    arxiv_tool = ArxivQueryRun(api_wrapper=arxiv_wrapper)

    tools = [tavily_search] # Replace `tavily_search` with `arxiv_tool`
    llm_with_tools = llm.bind(tools=tools)


    Here is my graph code:

    arcus_builder = StateGraph(ARCUSState)
    arcus_builder.add_node("generate_co_info", generate_co_info)
    arcus_builder.add_node("search_web", search_web)
    arcus_builder.add_node("search_wiki", search_wiki)
    arcus_builder.add_node("save_result", save_result)
    arcus_builder.add_node("write_research", write_research)
    arcus_builder.add_node("use_case_generator", use_case_generator)
    arcus_builder.add_node("resource_collector", resource_collector)
    tool_node = ToolNode(tools=tools)
    arcus_builder.add_node("tools", tool_node)
    arcus_builder.add_node("write_report", write_report)

    arcus_builder.add_edge(START, "generate_co_info")
    arcus_builder.add_edge("generate_co_info", "search_web")
    arcus_builder.add_edge("generate_co_info", "search_wiki")
    arcus_builder.add_edge("search_web", "save_result")
    arcus_builder.add_edge("search_wiki", "save_result")
    arcus_builder.add_edge("save_result", "write_research")
    arcus_builder.add_edge("write_research", "use_case_generator")
    arcus_builder.add_edge("use_case_generator", "resource_collector")
    arcus_builder.add_conditional_edges(
    "resource_collector",
    tools_condition_custom,
    {
    "tools": "tools",
    "write_report": "write_report",
    }
    )
    arcus_builder.add_edge("tools", "resource_collector")
    arcus_builder.add_edge("write_report", END)


    memory = MemorySaver()
    arcus_graph = arcus_builder.compile(checkpointer=memory)

    display(Image(arcus_graph.get_graph(xray=1).draw_mermaid_png()))


    Here is how I am calling:

    company_name = "Tesla"
    messages = [HumanMessage(f" Company Name: {company_name}")]
    thread = {"configurable": {"thread_id": "1"}}
    research = arcus_graph.invoke({"messages": messages}, thread)


    Without tools its running fine, I am expecting tools to work.

    Continue reading...

Compartilhe esta Página